Add action buttons and related functionality; refactor production logic and update entity definitions

This commit is contained in:
Kirill
2026-06-03 23:26:44 +03:00
parent c21048add3
commit 934d890887
11 changed files with 253 additions and 25 deletions
+38 -7
View File
@@ -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,16 +242,42 @@ 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: