aboutsummaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-05-08 01:14:00 +0200
committer hop311 <hop3114@gmail.com>2024-05-08 01:37:33 +0200
commitac29e4040fc20c50c8f0eb64b1194f6398165eb0 (patch)
treeb6460c44a29fe8bac9ba125a8464c88c8b9b6e89 /game
parentac1504f6fa981947bd9543d24325b3751236e925 (diff)
Generate building modelsmodels
Diffstat (limited to 'game')
-rw-r--r--game/src/Game/GameSession/GameSession.gd1
-rw-r--r--game/src/Game/GameSession/ModelManager.gd19
2 files changed, 20 insertions, 0 deletions
diff --git a/game/src/Game/GameSession/GameSession.gd b/game/src/Game/GameSession/GameSession.gd
index a07ce32..843ecd8 100644
--- a/game/src/Game/GameSession/GameSession.gd
+++ b/game/src/Game/GameSession/GameSession.gd
@@ -9,6 +9,7 @@ func _ready() -> void:
push_error("Failed to setup game")
_model_manager.generate_units()
+ _model_manager.generate_buildings()
func _process(_delta : float) -> void:
GameSingleton.try_tick()
diff --git a/game/src/Game/GameSession/ModelManager.gd b/game/src/Game/GameSession/ModelManager.gd
index 17d2c1e..8cec49d 100644
--- a/game/src/Game/GameSession/ModelManager.gd
+++ b/game/src/Game/GameSession/ModelManager.gd
@@ -61,6 +61,25 @@ func _generate_unit(unit_dict : Dictionary) -> void:
add_child(model)
+func generate_buildings() -> void:
+ for building : Dictionary in ModelSingleton.get_buildings():
+ _generate_building(building)
+
+func _generate_building(building_dict : Dictionary) -> void:
+ const model_key : StringName = &"model"
+ const position_key : StringName = &"position"
+ const rotation_key : StringName = &"rotation"
+
+ var model : Node3D = _generate_model(building_dict[model_key])
+ if not model:
+ return
+
+ model.scale *= MODEL_SCALE
+ model.rotate_y(PI + building_dict.get(rotation_key, 0.0))
+ model.set_position(_map_view._map_to_world_coords(building_dict[position_key]) + Vector3(0, 0.1 * MODEL_SCALE, 0))
+
+ add_child(model)
+
func _generate_model(model_dict : Dictionary, culture : String = "", is_unit : bool = false) -> Node3D:
const file_key : StringName = &"file"
const scale_key : StringName = &"scale"