Implement item unlocking mechanism and refactor save functionality; update scene timer node
This commit is contained in:
+48
-24
@@ -73,6 +73,7 @@ var g_active_items: Dictionary = {}
|
||||
|
||||
var owniverse:Owniverse = Owniverse.new()
|
||||
var owniverse_items: Dictionary[String, OwniverseItem] = {}
|
||||
var locked_items: Array = []
|
||||
|
||||
var item_list_to_update: Dictionary = {}
|
||||
|
||||
@@ -98,6 +99,23 @@ func set_owniverse_item_value() -> void:
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
func _unlock_items():
|
||||
var _new_locked_items = []
|
||||
for _item_id in locked_items:
|
||||
#print(_item_id ' | ', _entity.unlock)
|
||||
var _flag_to_unlock = true
|
||||
for _elem in owniverse.entities[_item_id].unlock:
|
||||
if owniverse.stats.total_amount[_elem] < owniverse.entities[_item_id].unlock[_elem]:
|
||||
_flag_to_unlock = false
|
||||
break
|
||||
|
||||
if _flag_to_unlock:
|
||||
owniverse_items[_item_id].set_visible(true)
|
||||
else:
|
||||
_new_locked_items.append(_item_id)
|
||||
|
||||
|
||||
func _on_indicator_pressed(indicator_name: String, page: int = 0):
|
||||
_set_description(indicator_name, page)
|
||||
|
||||
@@ -160,7 +178,7 @@ func _init_owniverse_items() -> bool:
|
||||
item.item_activated.connect(item_activated)
|
||||
|
||||
owniverse_items[item_id] = item
|
||||
|
||||
|
||||
return false
|
||||
|
||||
|
||||
@@ -172,7 +190,8 @@ func item_activated(item: OwniverseItem) -> void:
|
||||
owniverse.produce(item.item_id, 100_000)
|
||||
|
||||
func _unlock_item(item_id: String):
|
||||
owniverse_items[item_id].set_visible(true)
|
||||
pass
|
||||
#owniverse_items[item_id].set_visible(true)
|
||||
|
||||
|
||||
func _check_counters(delta: float) -> Array:
|
||||
@@ -191,7 +210,7 @@ func _check_counters(delta: float) -> Array:
|
||||
return actions
|
||||
|
||||
|
||||
#region Swipe
|
||||
#region Swipe and page
|
||||
|
||||
func _do_actions(actions: Array) -> void:
|
||||
for action: String in actions:
|
||||
@@ -226,11 +245,34 @@ func _input(event: InputEvent) -> void:
|
||||
g_counters.swipe.value = 0
|
||||
elif event is InputEventScreenTouch:
|
||||
pass
|
||||
|
||||
|
||||
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)
|
||||
page_actions[pa].set_actions(item_id, amount)
|
||||
|
||||
|
||||
func _page_action_pressed(page_id: int, action_amount: float) -> void:
|
||||
if !g_active_items.has(page_id):
|
||||
return
|
||||
|
||||
var item_id: String = g_active_items[page_id].item_id
|
||||
|
||||
if action_amount > 0:
|
||||
owniverse.produce(item_id, action_amount)
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
owniverse.init_enitities()
|
||||
var _output = owniverse.init_enitities()
|
||||
locked_items = _output.locked_items
|
||||
print(locked_items)
|
||||
owniverse.load_data()
|
||||
_init_owniverse_items()
|
||||
|
||||
@@ -255,25 +297,6 @@ func _process(delta: float) -> void:
|
||||
_do_actions(actions)
|
||||
|
||||
_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)
|
||||
page_actions[pa].set_actions(item_id, amount)
|
||||
|
||||
|
||||
|
||||
func _page_action_pressed(page_id: int, action_amount: float) -> void:
|
||||
if !g_active_items.has(page_id):
|
||||
return
|
||||
|
||||
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:
|
||||
@@ -308,5 +331,6 @@ func _on_topmenu_button_pressed(ButtonName) -> void:
|
||||
#z *= 10
|
||||
|
||||
|
||||
func _on_save_data() -> void:
|
||||
func _on_unlock_and_save_timeout() -> void:
|
||||
owniverse.save_data()
|
||||
_unlock_items()
|
||||
|
||||
Reference in New Issue
Block a user