Add action buttons and related functionality; refactor production logic and update entity definitions
This commit is contained in:
@@ -34,6 +34,16 @@ func get_description(item_id: String, items: Array = []) -> String:
|
||||
return description
|
||||
|
||||
|
||||
func format(value: float, digits: int = 0) -> String:
|
||||
if value < 10_000:
|
||||
return "%.*f" % [digits, value]
|
||||
|
||||
var exp = int(floor(log(abs(value)) / log(10.0)))
|
||||
var mantissa = value / pow(10.0, exp)
|
||||
|
||||
return "%.*f" % [digits, mantissa] + "E%+d" % exp
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
OwniverseEntities = _read_from_csv("res://data/owniverse_entitites.txt")
|
||||
OwniverseItems = _read_from_csv("res://data/owniverse_items.txt")
|
||||
|
||||
+38
-7
@@ -27,6 +27,11 @@ const SWIPE_DURATION: float = 0.4
|
||||
$StageRows/PageScroller/HBoxContainer/LifePage/Planets/Civ4
|
||||
]
|
||||
|
||||
@onready var page_actions: Dictionary[int, OwniverseAction] = {
|
||||
2: $StageRows/PageScroller/HBoxContainer/StarPage/Actions,
|
||||
3: $StageRows/PageScroller/HBoxContainer/StructurePage/Actions,
|
||||
}
|
||||
|
||||
@onready var g_item_descriptions: Array = [
|
||||
$StageRows/PageScroller/HBoxContainer/ForcePage/Description,
|
||||
$StageRows/PageScroller/HBoxContainer/ResourcePage/Description,
|
||||
@@ -55,7 +60,7 @@ const SWIPE_DURATION: float = 0.4
|
||||
var g_tween: Tween = null
|
||||
var g_dragged_start: Vector2 = Vector2.ZERO
|
||||
var g_scroll_start: int = 0
|
||||
var g_current_page: int = 0
|
||||
#var g_current_page: int = 0
|
||||
|
||||
var g_last_scroll_updated: int = 0
|
||||
|
||||
@@ -70,11 +75,9 @@ var g_active_items: Dictionary = {}
|
||||
|
||||
var owniverse:Owniverse = Owniverse.new()
|
||||
var owniverse_items: Dictionary[String, OwniverseItem] = {}
|
||||
#var locked_items:Dictionary = {}
|
||||
|
||||
var item_list_to_update: Dictionary = {}
|
||||
|
||||
|
||||
func set_datetime(value: String):
|
||||
date_time.text = value
|
||||
|
||||
@@ -90,6 +93,7 @@ func add_to_update_list(item_id: String, amount: int) -> void:
|
||||
|
||||
func set_owniverse_item_value() -> void:
|
||||
for item_id in owniverse.items_to_update:
|
||||
print("→ ", item_id)
|
||||
var item:OwniverseItem = owniverse_items[item_id]
|
||||
item.description.text = str(roundi(owniverse.items_to_update[item_id]))
|
||||
owniverse.items_to_update = {}
|
||||
@@ -171,10 +175,10 @@ func item_activated(item: OwniverseItem) -> void:
|
||||
_set_item_description(item)
|
||||
|
||||
if item.item_id == "S" or item.item_id == "H":
|
||||
owniverse.produce(item.item_id, 1)
|
||||
owniverse.produce(item.item_id, 1000)
|
||||
|
||||
func _unlock_item(item_id: String):
|
||||
owniverse_items[item_id].visible = true
|
||||
owniverse_items[item_id].set_visible(true)
|
||||
|
||||
|
||||
func _check_counters(delta: float) -> Array:
|
||||
@@ -193,6 +197,8 @@ func _check_counters(delta: float) -> Array:
|
||||
return actions
|
||||
|
||||
|
||||
#region Swipe
|
||||
|
||||
func _do_actions(actions: Array) -> void:
|
||||
for action: String in actions:
|
||||
match action:
|
||||
@@ -200,7 +206,6 @@ func _do_actions(actions: Array) -> void:
|
||||
_swipe_to_nearest_page()
|
||||
|
||||
|
||||
#region Swipe
|
||||
func _swipe_to_nearest_page() -> void:
|
||||
if stage_page_scroller.scroll_horizontal % PAGE_WIDTH == 0: return
|
||||
|
||||
@@ -237,17 +242,43 @@ func _ready() -> void:
|
||||
owniverse.unlock_item.connect(_unlock_item)
|
||||
g_counters.swipe.sec = 0.2
|
||||
|
||||
for pa in page_actions:
|
||||
page_actions[pa].action_pressed.connect(_page_action_pressed)
|
||||
page_actions[pa].page_id = pa
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
# Update date
|
||||
owniverse.cycle(delta)
|
||||
|
||||
var sdt: String = str(snapped(owniverse.add_time_delta(delta), 0.1))
|
||||
set_datetime(sdt)
|
||||
|
||||
#set_owniverse_item_value()
|
||||
|
||||
var actions = _check_counters(delta)
|
||||
_do_actions(actions)
|
||||
|
||||
#page_actions[2].set_visible(true)
|
||||
#page_actions[2].set_action_values([1, 10, 100, 1000, 10_000])
|
||||
#page_actions[3].set_action_values([10000000, 10, 100, 1000, 10_000])
|
||||
##page_actions[1].set_visible(false)
|
||||
|
||||
_set_active_page_actions()
|
||||
|
||||
func _set_active_page_actions() -> void:
|
||||
for pa in page_actions:
|
||||
if !g_active_items.has(pa): continue
|
||||
|
||||
var item_id: String = g_active_items[pa].item_id
|
||||
var amount = owniverse.get_available_to_produce(item_id)
|
||||
|
||||
|
||||
func _page_action_pressed(page_id: int, action_amount: float) -> void:
|
||||
var item_id: String = g_active_items[page_id].item_id
|
||||
|
||||
if action_amount > 0:
|
||||
owniverse.produce(item_id, action_amount)
|
||||
|
||||
|
||||
func _change_speed(delta: int) -> void:
|
||||
var speed: int = owniverse.change_speed(delta)
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
extends HBoxContainer
|
||||
class_name OwniverseAction
|
||||
|
||||
signal action_pressed(page_id, amount: float)
|
||||
|
||||
@onready var action_labels: Array = [
|
||||
$ActionControl0/Label,
|
||||
$ActionControl1/Label,
|
||||
$ActionControl2/Label,
|
||||
$ActionControl3/Label,
|
||||
$ActionControl4/Label,
|
||||
]
|
||||
|
||||
var page_id: int = -1
|
||||
|
||||
var action_values: Dictionary = {
|
||||
0: 0,
|
||||
1: 0,
|
||||
2: 0,
|
||||
3: 0,
|
||||
4: 0,
|
||||
}
|
||||
|
||||
|
||||
|
||||
func set_action_values(values: Array) -> void:
|
||||
for ind in range(0, 5):
|
||||
action_values[ind] = values[ind]
|
||||
action_labels[ind].text = str(values[ind]) if values[ind] > 0 else ""
|
||||
|
||||
|
||||
func _on_action_button_pressed(button_id: int) -> void:
|
||||
action_pressed.emit(page_id, action_values[button_id])
|
||||
@@ -0,0 +1 @@
|
||||
uid://c2ech05mh56y8
|
||||
@@ -0,0 +1,115 @@
|
||||
[gd_scene format=3 uid="uid://dwneq2qq5p8ek"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c2ech05mh56y8" path="res://ui/actions/actions.gd" id="1_cjivn"]
|
||||
[ext_resource type="FontFile" uid="uid://d3k1ddvv0rmhs" path="res://fonts/Roboto_Condensed/RobotoCondensed-Light.ttf" id="1_lgdyb"]
|
||||
[ext_resource type="Texture2D" uid="uid://gsclv7fr1rbr" path="res://ui/actions/action_button.png" id="2_cjivn"]
|
||||
|
||||
[node name="Actions" type="HBoxContainer" unique_id=503388208]
|
||||
custom_minimum_size = Vector2(0, 184)
|
||||
script = ExtResource("1_cjivn")
|
||||
|
||||
[node name="ActionControl0" type="Control" parent="." unique_id=1275614326]
|
||||
custom_minimum_size = Vector2(216, 216)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="ActionControl0" unique_id=1639484784]
|
||||
custom_minimum_size = Vector2(216, 32)
|
||||
layout_mode = 0
|
||||
offset_right = 216.0
|
||||
offset_bottom = 40.0
|
||||
theme_override_fonts/font = ExtResource("1_lgdyb")
|
||||
theme_override_font_sizes/font_size = 32
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="TextureButton" type="TextureButton" parent="ActionControl0" unique_id=1122042557]
|
||||
layout_mode = 0
|
||||
offset_top = 32.0
|
||||
offset_right = 216.0
|
||||
offset_bottom = 216.0
|
||||
texture_normal = ExtResource("2_cjivn")
|
||||
|
||||
[node name="ActionControl1" type="Control" parent="." unique_id=428212496]
|
||||
custom_minimum_size = Vector2(216, 216)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="ActionControl1" unique_id=382714464]
|
||||
custom_minimum_size = Vector2(216, 32)
|
||||
layout_mode = 0
|
||||
offset_right = 216.0
|
||||
offset_bottom = 40.0
|
||||
theme_override_fonts/font = ExtResource("1_lgdyb")
|
||||
theme_override_font_sizes/font_size = 32
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="TextureButton" type="TextureButton" parent="ActionControl1" unique_id=1538851090]
|
||||
layout_mode = 0
|
||||
offset_top = 32.0
|
||||
offset_right = 216.0
|
||||
offset_bottom = 216.0
|
||||
texture_normal = ExtResource("2_cjivn")
|
||||
|
||||
[node name="ActionControl2" type="Control" parent="." unique_id=1758592847]
|
||||
custom_minimum_size = Vector2(216, 216)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="ActionControl2" unique_id=1162569223]
|
||||
custom_minimum_size = Vector2(216, 32)
|
||||
layout_mode = 0
|
||||
offset_right = 216.0
|
||||
offset_bottom = 40.0
|
||||
theme_override_fonts/font = ExtResource("1_lgdyb")
|
||||
theme_override_font_sizes/font_size = 32
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="TextureButton" type="TextureButton" parent="ActionControl2" unique_id=1137903803]
|
||||
layout_mode = 0
|
||||
offset_top = 32.0
|
||||
offset_right = 216.0
|
||||
offset_bottom = 216.0
|
||||
texture_normal = ExtResource("2_cjivn")
|
||||
|
||||
[node name="ActionControl3" type="Control" parent="." unique_id=615206748]
|
||||
custom_minimum_size = Vector2(216, 216)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="ActionControl3" unique_id=580732513]
|
||||
custom_minimum_size = Vector2(216, 32)
|
||||
layout_mode = 0
|
||||
offset_right = 216.0
|
||||
offset_bottom = 40.0
|
||||
theme_override_fonts/font = ExtResource("1_lgdyb")
|
||||
theme_override_font_sizes/font_size = 32
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="TextureButton" type="TextureButton" parent="ActionControl3" unique_id=1783481629]
|
||||
layout_mode = 0
|
||||
offset_top = 32.0
|
||||
offset_right = 216.0
|
||||
offset_bottom = 216.0
|
||||
texture_normal = ExtResource("2_cjivn")
|
||||
|
||||
[node name="ActionControl4" type="Control" parent="." unique_id=473471606]
|
||||
custom_minimum_size = Vector2(216, 216)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="ActionControl4" unique_id=1862337838]
|
||||
custom_minimum_size = Vector2(216, 32)
|
||||
layout_mode = 0
|
||||
offset_right = 216.0
|
||||
offset_bottom = 40.0
|
||||
theme_override_fonts/font = ExtResource("1_lgdyb")
|
||||
theme_override_font_sizes/font_size = 32
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="TextureButton" type="TextureButton" parent="ActionControl4" unique_id=1477690280]
|
||||
layout_mode = 0
|
||||
offset_top = 32.0
|
||||
offset_right = 216.0
|
||||
offset_bottom = 216.0
|
||||
texture_normal = ExtResource("2_cjivn")
|
||||
|
||||
[connection signal="pressed" from="ActionControl0/TextureButton" to="." method="_on_action_button_pressed" binds= [0]]
|
||||
[connection signal="pressed" from="ActionControl1/TextureButton" to="." method="_on_action_button_pressed" binds= [1]]
|
||||
[connection signal="pressed" from="ActionControl2/TextureButton" to="." method="_on_action_button_pressed" binds= [2]]
|
||||
[connection signal="pressed" from="ActionControl3/TextureButton" to="." method="_on_action_button_pressed" binds= [3]]
|
||||
[connection signal="pressed" from="ActionControl4/TextureButton" to="." method="_on_action_button_pressed" binds= [4]]
|
||||
@@ -1,6 +1,6 @@
|
||||
id|is_visible|unlock|cost|bind|mass|space|lifespan|auto|gamma|blast|life_product|voids|output|destroy_level|degradation|planets|count_as|group_as|event_group|space_bonus|civ_bonus|claim
|
||||
S|1|S:0|||||||||||||||||S|||
|
||||
H|1|H:0|||||||||||||||||H|||
|
||||
S|1|S:0|S:0||||||||||||||||S|||
|
||||
H|1|H:0|H:0||||||||||||||||H|||
|
||||
He|1|He:1||||||||||||||||||||
|
||||
Met|1|Met:1||||||||||||||||||||
|
||||
BD|1|BD:1||||||||||||||||||||
|
||||
|
||||
+1
-1
@@ -110,7 +110,7 @@ architectures/armeabi-v7a=false
|
||||
architectures/arm64-v8a=true
|
||||
architectures/x86=false
|
||||
architectures/x86_64=false
|
||||
version/code=128
|
||||
version/code=126
|
||||
version/name=""
|
||||
package/unique_name="com.KIDGameProduction.Owniverse"
|
||||
package/name="Owniverse"
|
||||
|
||||
+3
-1
@@ -15,11 +15,13 @@ compatibility/default_parent_skeleton_in_mesh_instance_3d=true
|
||||
[application]
|
||||
|
||||
config/name="Owniverse"
|
||||
config/version="0.6.12"
|
||||
config/version="0.6.10"
|
||||
run/main_scene="uid://bv384dpmvjv8o"
|
||||
config/features=PackedStringArray("4.6", "Mobile")
|
||||
boot_splash/show_image=false
|
||||
config/icon="uid://do5teb1i7uiuw"
|
||||
config/size/borderless=true
|
||||
config/stretch_mode=0
|
||||
|
||||
[autoload]
|
||||
|
||||
|
||||
+32
-6
@@ -12,6 +12,7 @@ var entities: Dictionary[String, OwniverseEntity] = {}
|
||||
var items_to_update: Dictionary[String, float] = {}
|
||||
|
||||
var cumulative_amount: Dictionary[String, float] = {}
|
||||
var current_amount: Dictionary[String, float] = {}
|
||||
|
||||
var auto_production: Array = []
|
||||
var locked_entities: Array = []
|
||||
@@ -23,12 +24,24 @@ func cycle(delta: float) -> void:
|
||||
|
||||
|
||||
func produce(item_id: String, amount: int) -> void:
|
||||
print("prdcng ", item_id, " ", amount)
|
||||
#if item_id == "S" or item_id == 'H':
|
||||
#entities[item_id].amount += 1
|
||||
entities[item_id].amount += amount
|
||||
var entity: OwniverseEntity = entities[item_id]
|
||||
_process_enitity(entity, amount)
|
||||
|
||||
var entity_transaction = {}
|
||||
|
||||
for elem in entity.cost:
|
||||
if current_amount[elem] < amount * entity.cost[elem]:
|
||||
return
|
||||
if entity.cost[elem] == 0: continue
|
||||
|
||||
entity_transaction[elem] = -amount * entity.cost[elem]
|
||||
|
||||
print("→: ", entity_transaction)
|
||||
for elem in entity_transaction:
|
||||
_process_enitity(elem, amount)
|
||||
_process_enitity(entity, amount)
|
||||
|
||||
|
||||
func automated_production(_delta: float) -> void:
|
||||
@@ -37,14 +50,24 @@ func automated_production(_delta: float) -> void:
|
||||
var amount_to_produce = int(entity.amount * entity.product_per_year_amount * _delta)
|
||||
|
||||
|
||||
func get_available_to_produce(item_id: String) -> float:
|
||||
#print(item_id)
|
||||
return 1_000
|
||||
|
||||
# add to all lists
|
||||
func _process_enitity(entity: OwniverseEntity, amount: int) -> void:
|
||||
_count_cumulative(entity, amount)
|
||||
|
||||
items_to_update[entity.id] = entity.amount
|
||||
if amount == 0: return
|
||||
_count_amount(entity, amount)
|
||||
items_to_update[entity.id] = current_amount[entity.id]
|
||||
|
||||
|
||||
func _count_cumulative(entity: OwniverseEntity, amount: int) -> void:
|
||||
func _count_amount(entity: OwniverseEntity, amount: int) -> void:
|
||||
current_amount[entity.id] += amount
|
||||
if entity.group_as != "":
|
||||
current_amount[entity.group_as] += amount
|
||||
|
||||
if amount <= 0: return
|
||||
|
||||
cumulative_amount[entity.id] += amount
|
||||
if entity.group_as != "":
|
||||
cumulative_amount[entity.group_as] += amount
|
||||
@@ -69,7 +92,10 @@ func init_enitities() -> void:
|
||||
entity.init_entity(Global.OwniverseEntities[entity_id])
|
||||
entities[entity_id] = entity
|
||||
|
||||
current_amount[entity_id] = 0
|
||||
cumulative_amount[entity_id] = 0
|
||||
if entity.group_as != "":
|
||||
current_amount[entity.group_as] = 0
|
||||
cumulative_amount[entity.group_as] = 0
|
||||
|
||||
if entity.unlock != {}:
|
||||
|
||||
+16
-6
@@ -16,6 +16,7 @@
|
||||
[ext_resource type="FontFile" uid="uid://d3k1ddvv0rmhs" path="res://fonts/Roboto_Condensed/RobotoCondensed-Light.ttf" id="14_o7xkw"]
|
||||
[ext_resource type="FontFile" uid="uid://8s0fv3gfj317" path="res://fonts/Roboto_Condensed/RobotoCondensed-BoldItalic.ttf" id="15_bfrib"]
|
||||
[ext_resource type="FontFile" uid="uid://derqj4pbwtae6" path="res://fonts/Roboto_Condensed/RobotoCondensed-Italic.ttf" id="16_mip0j"]
|
||||
[ext_resource type="PackedScene" uid="uid://dwneq2qq5p8ek" path="res://ui/actions/actions.tscn" id="17_ifjjt"]
|
||||
[ext_resource type="Texture2D" uid="uid://i43jaaejvh5f" path="res://ui/indicators/energy/energy.png" id="17_l6135"]
|
||||
[ext_resource type="Texture2D" uid="uid://bef36h52n7lxb" path="res://ui/indicators/energy/border-energy.png" id="18_uvuuk"]
|
||||
[ext_resource type="Texture2D" uid="uid://blq0anccuu387" path="res://ui/pages/resources.en.png" id="19_an6vj"]
|
||||
@@ -41,7 +42,14 @@
|
||||
[ext_resource type="Texture2D" uid="uid://bwqmmmg6w7dho" path="res://ui/indicators/trends/trend_icon_4.png" id="39_jms70"]
|
||||
[ext_resource type="Texture2D" uid="uid://4tpbmpe6tbk0" path="res://ui/indicators/trends/trend_bar5.png" id="40_50rdj"]
|
||||
[ext_resource type="Texture2D" uid="uid://cnf3ml5gj2cvl" path="res://ui/indicators/trends/trend_icon_5.png" id="41_mi6gc"]
|
||||
[ext_resource type="Script" uid="uid://xte4iwvipeve" path="res://command_processor.gd" id="42_1s1fv"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_behgl"]
|
||||
script/source = "extends Node
|
||||
|
||||
func print_smth(smth: String):
|
||||
pass
|
||||
print(smth)
|
||||
"
|
||||
|
||||
[node name="World" type="Node2D" unique_id=1392592456]
|
||||
|
||||
@@ -493,6 +501,9 @@ layout_mode = 2
|
||||
custom_minimum_size = Vector2(1080, 1024)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Actions" parent="Stage/StageRows/PageScroller/HBoxContainer/StarPage" unique_id=503388208 instance=ExtResource("17_ifjjt")]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="StructurePage" type="VBoxContainer" parent="Stage/StageRows/PageScroller/HBoxContainer" unique_id=435979853]
|
||||
layout_mode = 2
|
||||
|
||||
@@ -627,6 +638,9 @@ layout_mode = 2
|
||||
custom_minimum_size = Vector2(1080, 1024)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Actions" parent="Stage/StageRows/PageScroller/HBoxContainer/StructurePage" unique_id=1391835556 instance=ExtResource("17_ifjjt")]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="LifePage" type="VBoxContainer" parent="Stage/StageRows/PageScroller/HBoxContainer" unique_id=1519563846]
|
||||
layout_mode = 2
|
||||
|
||||
@@ -825,16 +839,12 @@ offset_bottom = 1024.0
|
||||
[node name="Border" parent="Stage/StageRows" unique_id=145801370 instance=ExtResource("12_58wjt")]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="Stage/StageRows" unique_id=1880020851]
|
||||
custom_minimum_size = Vector2(0, 184)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ItemAmountUpdate" type="Timer" parent="Stage" unique_id=1953928024]
|
||||
wait_time = 0.2
|
||||
autostart = true
|
||||
|
||||
[node name="CommandProcessor" type="Node" parent="." unique_id=2069361293]
|
||||
script = ExtResource("42_1s1fv")
|
||||
script = SubResource("GDScript_behgl")
|
||||
|
||||
[connection signal="timeout" from="Background/Timer" to="Background" method="randomize_parallax"]
|
||||
[connection signal="pressed" from="Stage/StageRows/TopMenu/BurgerButton" to="Stage" method="_on_topmenu_button_pressed" binds= ["Burger"]]
|
||||
|
||||
Reference in New Issue
Block a user