diff --git a/Autoload/Global.gd b/Autoload/Global.gd index 921230c..af3b295 100644 --- a/Autoload/Global.gd +++ b/Autoload/Global.gd @@ -34,14 +34,15 @@ func get_description(item_id: String, items: Array = []) -> String: return description -func format(value: float, digits: int = 0) -> String: +func format_number(value: float, digits: int = 0) -> String: + if value == 0: return "" 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) + var exp_value = int(floor(log(abs(value)) / log(10.0))) + var mantissa = value / pow(10.0, exp_value) - return "%.*f" % [digits, mantissa] + "E%+d" % exp + return "%.*f" % [digits, mantissa] + "E%+d" % exp_value func _ready() -> void: diff --git a/Stage/stage.gd b/Stage/stage.gd index c7e8c2f..dcf12ad 100644 --- a/Stage/stage.gd +++ b/Stage/stage.gd @@ -93,9 +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[item_id].set_label(owniverse.items_to_update[item_id]) owniverse.items_to_update = {} @@ -175,7 +173,7 @@ 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, 1000) + owniverse.produce(item.item_id, 100_000) func _unlock_item(item_id: String): owniverse_items[item_id].set_visible(true) @@ -253,14 +251,9 @@ func _process(delta: float) -> void: 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() @@ -268,12 +261,17 @@ func _process(delta: float) -> void: 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: diff --git a/UI/actions/actions.gd b/UI/actions/actions.gd index 0321187..6a14d8f 100644 --- a/UI/actions/actions.gd +++ b/UI/actions/actions.gd @@ -12,6 +12,7 @@ signal action_pressed(page_id, amount: float) ] var page_id: int = -1 +var current_item_id = "" var action_values: Dictionary = { 0: 0, @@ -22,11 +23,23 @@ var action_values: Dictionary = { } +func set_actions(item_id: String, value: float) -> void: + current_item_id = item_id + _set_action_values(_get_distribution(value)) -func set_action_values(values: Array) -> void: +func _get_distribution(value: float) -> Array: + var distribution: Array = [value, 0, 0, 0, 0] + + var exp_value = int(floor(log(abs(value)) / log(10.0))) + var floor_value = max(exp_value - 4, -1) + for ev in range(exp_value, floor_value, -1): + distribution.push_front(pow(10.0, ev)) + return distribution + +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 "" + action_labels[ind].text = Global.format_number(values[ind]) if values[ind] > 0 else "" func _on_action_button_pressed(button_id: int) -> void: diff --git a/UI/actions/actions.tscn b/UI/actions/actions.tscn index bccb55a..9eabbfc 100644 --- a/UI/actions/actions.tscn +++ b/UI/actions/actions.tscn @@ -5,7 +5,7 @@ [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) +custom_minimum_size = Vector2(0, 216) script = ExtResource("1_cjivn") [node name="ActionControl0" type="Control" parent="." unique_id=1275614326] @@ -22,6 +22,7 @@ theme_override_font_sizes/font_size = 32 horizontal_alignment = 1 [node name="TextureButton" type="TextureButton" parent="ActionControl0" unique_id=1122042557] +custom_minimum_size = Vector2(216, 184) layout_mode = 0 offset_top = 32.0 offset_right = 216.0 @@ -42,6 +43,7 @@ theme_override_font_sizes/font_size = 32 horizontal_alignment = 1 [node name="TextureButton" type="TextureButton" parent="ActionControl1" unique_id=1538851090] +custom_minimum_size = Vector2(216, 184) layout_mode = 0 offset_top = 32.0 offset_right = 216.0 @@ -62,6 +64,7 @@ theme_override_font_sizes/font_size = 32 horizontal_alignment = 1 [node name="TextureButton" type="TextureButton" parent="ActionControl2" unique_id=1137903803] +custom_minimum_size = Vector2(216, 184) layout_mode = 0 offset_top = 32.0 offset_right = 216.0 @@ -82,6 +85,7 @@ theme_override_font_sizes/font_size = 32 horizontal_alignment = 1 [node name="TextureButton" type="TextureButton" parent="ActionControl3" unique_id=1783481629] +custom_minimum_size = Vector2(216, 184) layout_mode = 0 offset_top = 32.0 offset_right = 216.0 @@ -102,6 +106,7 @@ theme_override_font_sizes/font_size = 32 horizontal_alignment = 1 [node name="TextureButton" type="TextureButton" parent="ActionControl4" unique_id=1477690280] +custom_minimum_size = Vector2(216, 184) layout_mode = 0 offset_top = 32.0 offset_right = 216.0 diff --git a/UI/owniverse_item/owniverse_item.gd b/UI/owniverse_item/owniverse_item.gd index af679c3..9dc420a 100644 --- a/UI/owniverse_item/owniverse_item.gd +++ b/UI/owniverse_item/owniverse_item.gd @@ -19,6 +19,10 @@ var item_sub_page: int = -1 var item_type = "" +func set_label(value: float) -> void: + description.text = Global.format_number(value) + + func set_selection(flag: bool) -> void: selection.visible = flag diff --git a/export_presets.cfg b/export_presets.cfg index 055a969..06a0a65 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -8,7 +8,7 @@ custom_features="" export_filter="all_resources" include_filter="" exclude_filter="" -export_path="../../Documents/Owad/Owniverse.I/Builds/owniverse.0.6.11-127.exe" +export_path="../../Documents/Owad/Owniverse.I/Builds/owniverse.0.6.12-128.exe" patches=PackedStringArray() patch_delta_encoding=false patch_delta_compression_level_zstd=19 diff --git a/project.godot b/project.godot index 7625821..a78ceec 100644 --- a/project.godot +++ b/project.godot @@ -15,7 +15,7 @@ compatibility/default_parent_skeleton_in_mesh_instance_3d=true [application] config/name="Owniverse" -config/version="0.6.10" +config/version="0.6.12" run/main_scene="uid://bv384dpmvjv8o" config/features=PackedStringArray("4.6", "Mobile") boot_splash/show_image=false diff --git a/test_save_manual.gd b/test_save_manual.gd index 707339f..51504a7 100644 --- a/test_save_manual.gd +++ b/test_save_manual.gd @@ -2,7 +2,6 @@ extends SceneTree func _init(): #print("Testing SaveManager...") - # Instantiate Global manually var global_script = load("res://Autoload/Global.gd") var global_instance = global_script.new() @@ -20,37 +19,37 @@ func _init(): # Workaround: I'll just copy the logic I want to test. - var data = global_instance.Owniverse - #print("Data to save: ", data) + # var data = global_instance.Owniverse + # #print("Data to save: ", data) - var filename = "user://test_save_check.dat" - var password = "test" + # var filename = "user://test_save_check.dat" + # var password = "test" - var file = FileAccess.open_encrypted_with_pass(filename, FileAccess.WRITE, password) - if file == null: - print("Error opening file for write: ", FileAccess.get_open_error()) - quit(1) - return + # var file = FileAccess.open_encrypted_with_pass(filename, FileAccess.WRITE, password) + # if file == null: + # print("Error opening file for write: ", FileAccess.get_open_error()) + # quit(1) + # return - #print("Saving...") - file.store_var(data) - file.close() + # #print("Saving...") + # file.store_var(data) + # file.close() - #print("Loading...") - file = FileAccess.open_encrypted_with_pass(filename, FileAccess.READ, password) - if file == null: - printerr("Error opening file for read") - quit(1) - return + # #print("Loading...") + # file = FileAccess.open_encrypted_with_pass(filename, FileAccess.READ, password) + # if file == null: + # printerr("Error opening file for read") + # quit(1) + # return - var loaded_data = file.get_var() - #print("Loaded data: ", loaded_data) + # var loaded_data = file.get_var() + # #print("Loaded data: ", loaded_data) - if str(data) == str(loaded_data): - print("SUCCESS: Data matches.") - else: - printerr("FAILURE: Data mismatch.") - print("Original: ", data) - print("Loaded: ", loaded_data) + # if str(data) == str(loaded_data): + # print("SUCCESS: Data matches.") + # else: + # printerr("FAILURE: Data mismatch.") + # print("Original: ", data) + # print("Loaded: ", loaded_data) quit() diff --git a/world/owniverse.gd b/world/owniverse.gd index bd2f334..5a84431 100644 --- a/world/owniverse.gd +++ b/world/owniverse.gd @@ -23,10 +23,7 @@ func cycle(delta: float) -> void: _check_locked_items() -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 +func produce(item_id: String, amount: float) -> void: var entity: OwniverseEntity = entities[item_id] var entity_transaction = {} @@ -38,10 +35,9 @@ func produce(item_id: String, amount: int) -> void: entity_transaction[elem] = -amount * entity.cost[elem] - print("→: ", entity_transaction) for elem in entity_transaction: - _process_enitity(elem, amount) - _process_enitity(entity, amount) + _process_enitity(elem, entity_transaction[elem]) + _process_enitity(item_id, amount) func automated_production(_delta: float) -> void: @@ -51,24 +47,30 @@ func automated_production(_delta: float) -> void: func get_available_to_produce(item_id: String) -> float: - #print(item_id) - return 1_000 + var entity: OwniverseEntity = entities[item_id] + if entity.cost == {}: return 0 + var amount: float = 1E50 + for elem in entity.cost: + amount = min(floorf(current_amount[elem] / entity.cost[elem]), amount) + #print(elem, amount) + return amount # add to all lists -func _process_enitity(entity: OwniverseEntity, amount: int) -> void: +func _process_enitity(entity_id: String, amount: float) -> void: if amount == 0: return - _count_amount(entity, amount) - items_to_update[entity.id] = current_amount[entity.id] + _count_amount(entity_id, amount) + items_to_update[entity_id] = current_amount[entity_id] -func _count_amount(entity: OwniverseEntity, amount: int) -> void: - current_amount[entity.id] += amount +func _count_amount(entity_id: String, amount: float) -> void: + current_amount[entity_id] += amount + var entity: OwniverseEntity = entities[entity_id] if entity.group_as != "": current_amount[entity.group_as] += amount if amount <= 0: return - cumulative_amount[entity.id] += amount + cumulative_amount[entity_id] += amount if entity.group_as != "": cumulative_amount[entity.group_as] += amount diff --git a/world/world.tscn b/world/world.tscn index 57f553e..61a8c7b 100644 --- a/world/world.tscn +++ b/world/world.tscn @@ -43,6 +43,8 @@ [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"] +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_ifjjt"] + [sub_resource type="GDScript" id="GDScript_behgl"] script/source = "extends Node @@ -248,6 +250,14 @@ custom_minimum_size = Vector2(1080, 1024) layout_mode = 2 mouse_filter = 1 +[node name="ActionBorder" parent="Stage/StageRows/PageScroller/HBoxContainer/ForcePage" unique_id=101392860 instance=ExtResource("12_58wjt")] +layout_mode = 2 + +[node name="Panel" type="PanelContainer" parent="Stage/StageRows/PageScroller/HBoxContainer/ForcePage" unique_id=609868831] +custom_minimum_size = Vector2(0, 216) +layout_mode = 2 +theme_override_styles/panel = SubResource("StyleBoxEmpty_ifjjt") + [node name="ResourcePage" type="VBoxContainer" parent="Stage/StageRows/PageScroller/HBoxContainer" unique_id=1417647206] layout_mode = 2 @@ -391,6 +401,14 @@ layout_mode = 2 size_flags_horizontal = 3 context_menu_enabled = true +[node name="ActionBorder" parent="Stage/StageRows/PageScroller/HBoxContainer/ResourcePage" unique_id=1789647912 instance=ExtResource("12_58wjt")] +layout_mode = 2 + +[node name="Panel" type="PanelContainer" parent="Stage/StageRows/PageScroller/HBoxContainer/ResourcePage" unique_id=1336208519] +custom_minimum_size = Vector2(0, 216) +layout_mode = 2 +theme_override_styles/panel = SubResource("StyleBoxEmpty_ifjjt") + [node name="StarPage" type="VBoxContainer" parent="Stage/StageRows/PageScroller/HBoxContainer" unique_id=270059674] layout_mode = 2 @@ -501,6 +519,9 @@ layout_mode = 2 custom_minimum_size = Vector2(1080, 1024) layout_mode = 2 +[node name="ActionBorder" parent="Stage/StageRows/PageScroller/HBoxContainer/StarPage" unique_id=136439467 instance=ExtResource("12_58wjt")] +layout_mode = 2 + [node name="Actions" parent="Stage/StageRows/PageScroller/HBoxContainer/StarPage" unique_id=503388208 instance=ExtResource("17_ifjjt")] layout_mode = 2 @@ -638,6 +659,9 @@ layout_mode = 2 custom_minimum_size = Vector2(1080, 1024) layout_mode = 2 +[node name="ActionBorder" parent="Stage/StageRows/PageScroller/HBoxContainer/StructurePage" unique_id=449208508 instance=ExtResource("12_58wjt")] +layout_mode = 2 + [node name="Actions" parent="Stage/StageRows/PageScroller/HBoxContainer/StructurePage" unique_id=1391835556 instance=ExtResource("17_ifjjt")] layout_mode = 2 @@ -836,6 +860,14 @@ offset_top = 512.0 offset_right = 1080.0 offset_bottom = 1024.0 +[node name="ActionBorder" parent="Stage/StageRows/PageScroller/HBoxContainer/LifePage" unique_id=160841192 instance=ExtResource("12_58wjt")] +layout_mode = 2 + +[node name="Panel" type="PanelContainer" parent="Stage/StageRows/PageScroller/HBoxContainer/LifePage" unique_id=116394684] +custom_minimum_size = Vector2(0, 216) +layout_mode = 2 +theme_override_styles/panel = SubResource("StyleBoxEmpty_ifjjt") + [node name="Border" parent="Stage/StageRows" unique_id=145801370 instance=ExtResource("12_58wjt")] layout_mode = 2