Skip to content

Commit

Permalink
[wip] prepare save
Browse files Browse the repository at this point in the history
  • Loading branch information
theludovyc committed Dec 15, 2024
1 parent b9c7a24 commit 01f45bf
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
11 changes: 11 additions & 0 deletions Script/TheBuilder.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extends Node

@onready var node_buildings:Node = %Buildings

func get_buildings_save() -> Dictionary:
var datas:Array

for child:Building2D in node_buildings.get_children():
datas.append([child.building_id, child.position])

return {"Buildings":datas}
24 changes: 16 additions & 8 deletions theLudovyc/Game2D.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ class_name Game2D

@onready var cam := $Camera2D

@onready var node_entities := %Entities
@onready var node_buildings := %Buildings

@onready var the_storage := $TheStorage
@onready var the_bank := $TheBank
@onready var event_bus := $EventBus

@onready var the_storage := $TheStorage
@onready var the_bank := $TheBank
@onready var the_factory := $TheFactory
@onready var the_builder := $TheBuilder

@onready var gui := $GUI
@onready var pause_menu := %PauseMenu
Expand Down Expand Up @@ -49,13 +50,15 @@ func _ready():
# spawn the warehouse
warehouse = instantiate_building(Buildings.Ids.Warehouse)

var warehouse_center_tile = Vector2i(1, 20)
var warehouse_center_tile = tm.ground_layer.local_to_map(Vector2(704, 320))

warehouse.position = tm.ground_layer.map_to_local(warehouse_center_tile)

tm.build_entityStatic(warehouse, warehouse_center_tile)

warehouse.build()

prints(name, warehouse.position)

# set camera limits
var pos_limits = tm.get_pos_limits()
Expand Down Expand Up @@ -203,10 +206,7 @@ func _process(delta):
func instantiate_building(building_id: Buildings.Ids) -> Building2D:
var instance = Buildings_Scenes[building_id].instantiate() as Building2D

node_entities.add_child(instance)

# TODO
#instance.selected.connect(_on_building_selected)
node_buildings.add_child(instance)

return instance

Expand Down Expand Up @@ -260,3 +260,11 @@ func _on_EventBus_ask_demolish_current_building():
current_selected_building = null

event_bus.send_current_building_demolished.emit()

func _on_PauseMenu_ask_to_save() -> void:
var dicoToSave := {}
dicoToSave.merge(the_storage.get_storage_save())
dicoToSave.merge(the_bank.get_bank_save())
dicoToSave.merge(the_builder.get_buildings_save())

pause_menu.save_this_please(dicoToSave)
9 changes: 7 additions & 2 deletions theLudovyc/Game2D.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=17 format=3 uid="uid://bbbuj3ne5rupv"]
[gd_scene load_steps=18 format=3 uid="uid://bbbuj3ne5rupv"]

[ext_resource type="Script" path="res://theLudovyc/Game2D.gd" id="1_i3wk0"]
[ext_resource type="Script" path="res://theLudovyc/EventBus.gd" id="2_jbfdl"]
Expand All @@ -11,6 +11,7 @@
[ext_resource type="Script" path="res://theLudovyc/Camera2D.gd" id="5_7hgfn"]
[ext_resource type="PackedScene" uid="uid://b3s7eqy0blp6g" path="res://theLudovyc/GUI/GUI.tscn" id="6_lovin"]
[ext_resource type="Script" path="res://theLudovyc/TheTicker.gd" id="7_41bva"]
[ext_resource type="Script" path="res://Script/TheBuilder.gd" id="7_gnc51"]
[ext_resource type="TileSet" uid="uid://bhin7dsw4tvvl" path="res://theLudovyc/new_tile_set.tres" id="11_gqnmu"]
[ext_resource type="TileSet" uid="uid://dprvpcto8mhgv" path="res://theLudovyc/tile_set_trees.tres" id="12_25naw"]
[ext_resource type="Script" path="res://Script/World/GroundLayer.gd" id="12_dmqkb"]
Expand All @@ -35,6 +36,9 @@ script = ExtResource("3_6uk0m")
[node name="TheMarket" type="Node" parent="."]
script = ExtResource("4_gvgis")

[node name="TheBuilder" type="Node" parent="."]
script = ExtResource("7_gnc51")

[node name="TheTicker" type="Timer" parent="."]
wait_time = 2.0
autostart = true
Expand Down Expand Up @@ -70,7 +74,7 @@ y_sort_enabled = true
tile_set = ExtResource("12_25naw")
script = ExtResource("14_wtd65")

[node name="Entities" type="Node2D" parent="ZSorter"]
[node name="Buildings" type="Node2D" parent="ZSorter"]
unique_name_in_owner = true
z_index = 1
y_sort_enabled = true
Expand Down Expand Up @@ -100,3 +104,4 @@ unique_name_in_owner = true
[connection signal="cycle" from="TheTicker" to="TheMarket" method="_on_TheTicker_cycle"]
[connection signal="tick" from="TheTicker" to="TheFactory" method="_on_TheTicker_tick"]
[connection signal="timeout" from="TheTicker" to="TheTicker" method="_on_timeout"]
[connection signal="ask_to_save" from="GUI/PauseMenu" to="." method="_on_PauseMenu_ask_to_save"]
3 changes: 3 additions & 0 deletions theLudovyc/TheBank.gd
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,6 @@ func recalculate_orders_cost():
tmp_orders_cost += resource_cost * order.sell_amount

orders_cost = tmp_orders_cost

func get_bank_save() -> Dictionary:
return {"Money": [money, money_production_rate]}
5 changes: 4 additions & 1 deletion theLudovyc/TheStorage.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extends Node
class_name TheStorage

var storage = {}
var storage := {}

@onready var event_bus = $"../EventBus"

Expand Down Expand Up @@ -91,3 +91,6 @@ func recover_building_construction(building_id: Buildings.Ids):

for cost in building_cost:
add_resource(cost[0], cost[1])

func get_storage_save() -> Dictionary:
return {"Storage":storage}

0 comments on commit 01f45bf

Please sign in to comment.