diff --git a/Script/Gui/ConfirmDialog.gd b/Script/Gui/ConfirmDialog.gd index 9e4d9b3c..734036f9 100644 --- a/Script/Gui/ConfirmDialog.gd +++ b/Script/Gui/ConfirmDialog.gd @@ -7,14 +7,9 @@ func _ready(): func popup_confirm(confirm_text:String, on_ok_pressed:Callable): dialog_text = confirm_text - var button_pressed_signal:Signal = get_ok_button().pressed - if current_callable.is_valid() and current_callable != on_ok_pressed: button_pressed_signal.disconnect(current_callable) - button_pressed_signal.connect(on_ok_pressed) - current_callable = on_ok_pressed - popup_centered_clamped() diff --git a/addons/rakugo_game_template/Autoloads/AppSettings.gd b/addons/rakugo_game_template/Autoloads/AppSettings.gd index 7eb98f17..3b63e2e7 100644 --- a/addons/rakugo_game_template/Autoloads/AppSettings.gd +++ b/addons/rakugo_game_template/Autoloads/AppSettings.gd @@ -19,46 +19,34 @@ var busses_volume := {} func _ready(): var err = config_file.load(CONFIG_FILE_LOCATION) - if err != OK: return - #load input_events if config_file.has_section(INPUT_SECTION): var action_names = config_file.get_section_keys(INPUT_SECTION) - for action_name in action_names: if not InputMap.has_action(action_name): push_error("Action: " + action_name + ", does not exist in the InputMap !") continue - InputMap.action_erase_events(action_name) InputMap.action_add_event( action_name, config_file.get_value(INPUT_SECTION, action_name)) - #audio if config_file.has_section(AUDIO_SECTION): if config_file.get_value(AUDIO_SECTION, MUTE_SETTING, false): AudioServer.set_bus_mute(MASTER_BUS_INDEX, true) - var dictio = config_file.get_value(AUDIO_SECTION, BUSSES_VOLUME, {}) - for bus_index in dictio: AudioServer.set_bus_volume_db(bus_index, linear_to_db(dictio[bus_index])) - #video if config_file.has_section(VIDEO_SECTION): var main_window = get_window() - if config_file.get_value(VIDEO_SECTION, FULLSCREEN_ENABLED, is_master_muted()): main_window.mode = Window.MODE_EXCLUSIVE_FULLSCREEN - if config_file.has_section_key(VIDEO_SECTION, SCREEN_RESOLUTION): var res_value = config_file.get_value(VIDEO_SECTION, SCREEN_RESOLUTION) - main_window.content_scale_size = res_value - if main_window.mode != Window.MODE_EXCLUSIVE_FULLSCREEN: main_window.size = res_value @@ -76,9 +64,7 @@ func reset_to_default_inputs() -> void: # Audio func set_bus_volume_from_linear(bus_index : int, linear : float) -> void: AudioServer.set_bus_volume_db(bus_index, linear_to_db(linear)) - busses_volume[bus_index] = linear - config_file.set_value(AUDIO_SECTION, BUSSES_VOLUME, busses_volume) func is_master_muted() -> bool: @@ -86,29 +72,22 @@ func is_master_muted() -> bool: func set_mute(mute_flag : bool) -> void: AudioServer.set_bus_mute(MASTER_BUS_INDEX, mute_flag) - config_file.set_value(AUDIO_SECTION, MUTE_SETTING, mute_flag) # Video func set_fullscreen(value:bool): var main_window = get_window() - main_window.mode = Window.MODE_EXCLUSIVE_FULLSCREEN if value else Window.MODE_WINDOWED - if main_window.mode == Window.MODE_WINDOWED: main_window.size = config_file.get_value(VIDEO_SECTION, SCREEN_RESOLUTION, Vector2i( ProjectSettings.get_setting("display/window/size/viewport_width"), ProjectSettings.get_setting("display/window/size/viewport_height"))) - config_file.set_value(VIDEO_SECTION, FULLSCREEN_ENABLED, value) func set_resolution(value : Vector2i) -> void: var main_window = get_window() - main_window.content_scale_size = value - if main_window.mode != Window.MODE_EXCLUSIVE_FULLSCREEN: main_window.size = value - config_file.set_value(VIDEO_SECTION, SCREEN_RESOLUTION, value) diff --git a/addons/rakugo_game_template/Autoloads/SceneLoader.gd b/addons/rakugo_game_template/Autoloads/SceneLoader.gd index 74e7db37..319f73cd 100644 --- a/addons/rakugo_game_template/Autoloads/SceneLoader.gd +++ b/addons/rakugo_game_template/Autoloads/SceneLoader.gd @@ -41,18 +41,14 @@ func get_resource(): func change_scene_to_resource() -> void: var current_tree = get_tree() current_tree.paused = true - Transitions.transition(Transitions.transition_type.Diamond) await Transitions.animation_player.animation_finished - var err = current_tree.change_scene_to_packed(get_resource()) if err: push_error("failed to change scenes: %d" % err) current_tree.quit() - Transitions.transition(Transitions.transition_type.Diamond, true) await Transitions.animation_player.animation_finished - current_tree.paused = false func change_scene_to_loading_screen() -> void: diff --git a/addons/rakugo_game_template/Autoloads/Transitions/Shaders/Circle_mask.gdshader b/addons/rakugo_game_template/Autoloads/Transitions/Shaders/Circle_mask.gdshader index b7ae7702..4e6783b1 100644 --- a/addons/rakugo_game_template/Autoloads/Transitions/Shaders/Circle_mask.gdshader +++ b/addons/rakugo_game_template/Autoloads/Transitions/Shaders/Circle_mask.gdshader @@ -10,8 +10,8 @@ void fragment() { float ratio = 1.0 / size_ratio; float dist = distance(vec2(location_x, location_y), vec2(mix(0.5, UV.x, ratio), UV.y)); float alpha_total = (1.0 - step(size, dist)); - if (invert == true) { + if (invert) { alpha_total = 1.0 - alpha_total; } COLOR.a = alpha_total; -} \ No newline at end of file +} diff --git a/addons/rakugo_game_template/Autoloads/Transitions/Shaders/Diamond.gdshader b/addons/rakugo_game_template/Autoloads/Transitions/Shaders/Diamond.gdshader index 4a7f65b9..cd75036a 100644 --- a/addons/rakugo_game_template/Autoloads/Transitions/Shaders/Diamond.gdshader +++ b/addons/rakugo_game_template/Autoloads/Transitions/Shaders/Diamond.gdshader @@ -9,10 +9,7 @@ uniform float progress : hint_range(0, 1); // Size of each diamond, in pixels. uniform float diamondPixelSize = 10.0; - - void fragment() { - float xFraction = fract(FRAGCOORD.x / diamondPixelSize); float yFraction = fract(FRAGCOORD.y / diamondPixelSize); float xDistance = abs(xFraction - 0.5); @@ -20,5 +17,4 @@ void fragment() { if (xDistance + yDistance + UV.x + UV.y > progress * 4.0) { discard; } - -} \ No newline at end of file +} diff --git a/addons/rakugo_game_template/Autoloads/Transitions/Shaders/Line.gdshader b/addons/rakugo_game_template/Autoloads/Transitions/Shaders/Line.gdshader index c0202eb0..da9e255c 100644 --- a/addons/rakugo_game_template/Autoloads/Transitions/Shaders/Line.gdshader +++ b/addons/rakugo_game_template/Autoloads/Transitions/Shaders/Line.gdshader @@ -20,4 +20,4 @@ void fragment() { COLOR = vec4(0.0); } } -} \ No newline at end of file +} diff --git a/addons/rakugo_game_template/Autoloads/Transitions/Shaders/Square_mask.gdshader b/addons/rakugo_game_template/Autoloads/Transitions/Shaders/Square_mask.gdshader index da28f38e..422fcfe5 100644 --- a/addons/rakugo_game_template/Autoloads/Transitions/Shaders/Square_mask.gdshader +++ b/addons/rakugo_game_template/Autoloads/Transitions/Shaders/Square_mask.gdshader @@ -13,8 +13,8 @@ void fragment() { float alpha3 = step(size + location_y, mix(0.5, UV.y, ratio_height)); float alpha4 = step(size - location_y, mix(0.5, 1.0-UV.y, ratio_height)); float alpha_total = alpha1 * alpha2 * alpha3 * alpha4; - if (invert == true) { + if (invert) { alpha_total = 1.0 - alpha_total; } COLOR.a = alpha_total; -} \ No newline at end of file +} diff --git a/addons/rakugo_game_template/Autoloads/Transitions/Shaders/Swipe_Mask.gdshader b/addons/rakugo_game_template/Autoloads/Transitions/Shaders/Swipe_Mask.gdshader index 11c09860..2e957e54 100644 --- a/addons/rakugo_game_template/Autoloads/Transitions/Shaders/Swipe_Mask.gdshader +++ b/addons/rakugo_game_template/Autoloads/Transitions/Shaders/Swipe_Mask.gdshader @@ -6,8 +6,8 @@ uniform bool invert_xy = false; void fragment() { float which_axis = UV.x; - if (invert_xy == true) { + if (invert_xy) { which_axis = UV.y; } COLOR.a = (1.0 - step(size * wipe_direction, which_axis * wipe_direction)); -} \ No newline at end of file +} diff --git a/addons/rakugo_game_template/Autoloads/Transitions/transitions.gd b/addons/rakugo_game_template/Autoloads/Transitions/transitions.gd index 82afcaf0..46666362 100644 --- a/addons/rakugo_game_template/Autoloads/Transitions/transitions.gd +++ b/addons/rakugo_game_template/Autoloads/Transitions/transitions.gd @@ -13,9 +13,7 @@ func screen_ratio (): func transition (transition_name:transition_type, reverse :bool = false) : stop_mouse.mouse_filter = Control.MOUSE_FILTER_STOP color_rect.show() - var transition_name_str :String - match transition_name: transition_type.Swipe: transition_name_str = "Swipe" @@ -28,11 +26,9 @@ func transition (transition_name:transition_type, reverse :bool = false) : transition_name_str = "Diamond" transition_type.Line: transition_name_str = "Line" - if reverse : animation_player.play_backwards(transition_name_str) return - animation_player.play(transition_name_str) func _on_animation_finished(anim_name): diff --git a/addons/rakugo_game_template/Autoloads/UISoundManager/UISoundManager.gd b/addons/rakugo_game_template/Autoloads/UISoundManager/UISoundManager.gd index 0d0e68fd..de900829 100644 --- a/addons/rakugo_game_template/Autoloads/UISoundManager/UISoundManager.gd +++ b/addons/rakugo_game_template/Autoloads/UISoundManager/UISoundManager.gd @@ -11,34 +11,35 @@ extends Node func get_one_audio_stream(array:Array): if array.is_empty(): return null - if array.size() == 1: return array[0] - return array.pick_random() + func _on_event(audio_array:Array): audio_stream_player.stream = get_one_audio_stream(audio_array) audio_stream_player.play() + func _on_event_pressed(): _on_event(audio_streams_pressed) + func _on_event_hovered(): _on_event(audio_streams_hovered) + func _connect_stream_player(node : Node, signal_name : StringName, callable:Callable, unbind_count:int = 0) -> void: if unbind_count > 0: callable = callable.unbind(unbind_count) - if not node.is_connected(signal_name, callable): node.connect(signal_name, callable) + func connect_ui_sounds(node: Node) -> void: if node is Button: _connect_stream_player(node, &"mouse_entered", _on_event_hovered) _connect_stream_player(node, &"pressed", _on_event_pressed) - if node is OptionButton: _connect_stream_player(node, &"item_selected", _on_event_pressed, 1) elif node is TabBar: @@ -50,17 +51,16 @@ func connect_ui_sounds(node: Node) -> void: elif node is LineEdit: _connect_stream_player(node, &"mouse_entered", _on_event_hovered) _connect_stream_player(node, &"text_submitted", _on_event_pressed) - + + func _on_node_added(node:Node): if not node is Control: return - connect_ui_sounds(node) + func _ready(): if audio_streams_pressed.is_empty() and audio_streams_hovered.is_empty(): return - audio_stream_player.bus = audio_bus - get_tree().node_added.connect(_on_node_added) diff --git a/addons/rakugo_game_template/rakugo_game_template.gd b/addons/rakugo_game_template/rakugo_game_template.gd index d8920465..ab795867 100644 --- a/addons/rakugo_game_template/rakugo_game_template.gd +++ b/addons/rakugo_game_template/rakugo_game_template.gd @@ -11,7 +11,6 @@ func _enter_tree(): add_autoload_singleton("ProjectMusicController", "res://addons/rakugo_game_template/Autoloads/ProjectMusicController.tscn") add_autoload_singleton("UISoundManager", "res://addons/rakugo_game_template/Autoloads/UISoundManager/UISoundManager.tscn") add_autoload_singleton("Transitions", "res://addons/rakugo_game_template/Autoloads/Transitions/transitions.tscn") - init_setting_if_empty(RGT_Globals.loading_scene_setting_path, "res://scenes/LoadingScreen/LoadingScreen.tscn") init_setting_if_empty(RGT_Globals.main_menu_setting_path, "res://scenes/MainMenu/MainMenu.tscn") init_setting_if_empty(RGT_Globals.first_game_scene_setting_path, "res://scenes/Game/game.tscn") @@ -22,7 +21,6 @@ func _exit_tree(): remove_autoload_singleton("ProjectMusicController") remove_autoload_singleton("UISoundManager") remove_autoload_singleton("Transitions") - RGT_Globals.loading_scene_setting = null RGT_Globals.main_menu_setting = null RGT_Globals.first_game_scene_setting = null diff --git a/addons/rakugo_game_template/scripts/MusicController.gd b/addons/rakugo_game_template/scripts/MusicController.gd index 4f6ac41b..95cbcc22 100644 --- a/addons/rakugo_game_template/scripts/MusicController.gd +++ b/addons/rakugo_game_template/scripts/MusicController.gd @@ -20,18 +20,21 @@ const MINIMUM_VOLUME_DB = -80 if fade_out_duration < 0: fade_out_duration = 0 + @export var fade_in_duration : float = 0.0 : set(value): fade_in_duration = value if fade_in_duration < 0: fade_in_duration = 0 + @export var blend_volume_duration : float = 0.0 : set(value): blend_volume_duration = value if blend_volume_duration < 0: blend_volume_duration = 0 + ## Matched stream players with no stream set will stop current playback. @export var empty_streams_stop_player : bool = true @@ -43,6 +46,7 @@ func fade_out( duration : float = 0.0 ): tween.tween_property(music_stream_player, "volume_db", MINIMUM_VOLUME_DB, duration) return tween + func fade_in( duration : float = 0.0 ): if not is_zero_approx(duration): var target_volume_db = music_stream_player.volume_db @@ -51,6 +55,7 @@ func fade_in( duration : float = 0.0 ): tween.tween_property(music_stream_player, "volume_db", target_volume_db, duration) return tween + func blend_to( target_volume_db : float, duration : float = 0.0 ): if not is_zero_approx(duration): var tween = get_tree().create_tween() @@ -58,16 +63,19 @@ func blend_to( target_volume_db : float, duration : float = 0.0 ): return tween music_stream_player.volume_db = target_volume_db + func stop(): if music_stream_player == null: return music_stream_player.stop() + func play(): if music_stream_player == null: return music_stream_player.play() + func _fade_out_and_free(): if music_stream_player == null: return @@ -77,12 +85,14 @@ func _fade_out_and_free(): await( tween.finished ) stream_player.queue_free() + func _play_and_fade_in(): if music_stream_player == null: return music_stream_player.play() fade_in( fade_in_duration ) + func _is_matching_stream( stream_player : AudioStreamPlayer ) -> bool: if stream_player.bus != audio_bus: return false @@ -90,15 +100,18 @@ func _is_matching_stream( stream_player : AudioStreamPlayer ) -> bool: return false return music_stream_player.stream == stream_player.stream + func _reparent_music_player( stream_player : AudioStreamPlayer ): stream_player.call_deferred("reparent", self) music_stream_player = stream_player + func _blend_in_stream_player( stream_player : AudioStreamPlayer ): _fade_out_and_free() _reparent_music_player(stream_player) _play_and_fade_in() + func check_for_music_player( node: Node ) -> void: if node == music_stream_player : return if not (node is AudioStreamPlayer and node.autoplay) : return @@ -113,11 +126,13 @@ func check_for_music_player( node: Node ) -> void: return _blend_in_stream_player(node) + func _ready() -> void: var tree_node = get_tree() if not tree_node.node_added.is_connected(check_for_music_player): tree_node.node_added.connect(check_for_music_player) + func _exit_tree(): var tree_node = get_tree() if tree_node.node_added.is_connected(check_for_music_player): diff --git a/theLudovyc/Building/Building.gd b/theLudovyc/Building/Building.gd index a53ea1fa..bb05b6ac 100644 --- a/theLudovyc/Building/Building.gd +++ b/theLudovyc/Building/Building.gd @@ -5,54 +5,53 @@ class_name Building2D signal selected(type) -@export var building_id:Buildings.Ids +@export var building_id: Buildings.Ids -var event_bus:EventBus +var event_bus: EventBus var is_selected := false + func build(): var current_scene = get_tree().current_scene - if current_scene.has_node("EventBus"): event_bus = current_scene.get_node("EventBus") event_bus.send_building_selected.connect(_on_building_selected) - var area2d := $Area2D - area2d.input_event.connect(_on_Area2d_input_event) area2d.mouse_entered.connect(_on_Area2d_mouse_entered) area2d.mouse_exited.connect(_on_Area2d_mouse_exited) + func _on_Area2d_input_event(viewport, event, shape_idx): if not is_selected and event.is_action_pressed("alt_command"): is_selected = true - modulate = Color.YELLOW - if event_bus != null: event_bus.send_building_selected.emit(self) - + + func _on_Area2d_mouse_entered(): if not is_selected: modulate = Color.YELLOW + func _on_Area2d_mouse_exited(): if not is_selected: modulate = Color.WHITE -func _on_building_selected(building_node:Building2D): + +func _on_building_selected(building_node: Building2D): if is_selected and building_node != self: is_selected = false - modulate = Color.WHITE - + + func select(): is_selected = true - modulate = Color.YELLOW + func deselect(): is_selected = false - modulate = Color.WHITE diff --git a/theLudovyc/Building/Buildings.gd b/theLudovyc/Building/Buildings.gd index f5245b10..77cf918a 100644 --- a/theLudovyc/Building/Buildings.gd +++ b/theLudovyc/Building/Buildings.gd @@ -1,83 +1,61 @@ extends Object class_name Buildings -enum Types{ - Placeholder, - Warehouse, - Residential, - Producing -} +enum Types { Placeholder, Warehouse, Residential, Producing } -enum Ids{ - Warehouse, - Tent, - Lumberjack -} +enum Ids { Warehouse, Tent, Lumberjack } -enum Datas{ - Name, - Type, - Cost, - Produce, - Max_Workers -} +enum Datas { Name, Type, Cost, Produce, Max_Workers } const datas = { - Ids.Warehouse:{ - Datas.Name:&"Warehouse", - Datas.Type:Types.Warehouse + Ids.Warehouse: {Datas.Name: &"Warehouse", Datas.Type: Types.Warehouse}, + Ids.Tent: + { + Datas.Name: &"Tent", + Datas.Type: Types.Residential, + Datas.Cost: [[Resources.Types.Wood, 1], [Resources.Types.Textile, 1]], + Datas.Max_Workers: 4 }, - Ids.Tent:{ - Datas.Name:&"Tent", - Datas.Type:Types.Residential, - Datas.Cost:[ - [Resources.Types.Wood, 1], [Resources.Types.Textile, 1] - ], - Datas.Max_Workers:4 - }, - Ids.Lumberjack:{ - Datas.Name:&"Lumberjack", - Datas.Type:Types.Producing, - Datas.Cost:[ - [Resources.Types.Wood, 1], [Resources.Types.Textile, 1] - ], - Datas.Produce:Resources.Types.Wood, - Datas.Max_Workers:4 + Ids.Lumberjack: + { + Datas.Name: &"Lumberjack", + Datas.Type: Types.Producing, + Datas.Cost: [[Resources.Types.Wood, 1], [Resources.Types.Textile, 1]], + Datas.Produce: Resources.Types.Wood, + Datas.Max_Workers: 4 } } + # warning: conflict with get_name -static func get_building_name(building_id:Buildings.Ids) -> StringName: +static func get_building_name(building_id: Buildings.Ids) -> StringName: if not datas.has(building_id): return StringName() - return datas[building_id][Datas.Name] -static func get_building_type(building_id:Buildings.Ids) -> Types: + +static func get_building_type(building_id: Buildings.Ids) -> Types: if not datas.has(building_id): return Types.Placeholder - return datas[building_id].get(Datas.Type, Types.Placeholder) -static func get_building_cost(building_id:Buildings.Ids) -> Array: + +static func get_building_cost(building_id: Buildings.Ids) -> Array: if not datas.has(building_id): return [] - var building_datas = datas[building_id] - if not building_datas.has(Datas.Cost): return [] - return building_datas[Datas.Cost] -static func get_produce_resource(building_id:Buildings.Ids) -> Resources.Types: + +static func get_produce_resource(building_id: Buildings.Ids) -> Resources.Types: if not datas.has(building_id): return -1 - return datas[building_id].get(Datas.Produce, -1) - -static func get_max_workers(building_id:Buildings.Ids) -> int: + + +static func get_max_workers(building_id: Buildings.Ids) -> int: if not datas.has(building_id): return -1 - return datas[building_id].get(Datas.Max_Workers, -1) diff --git a/theLudovyc/Camera2D.gd b/theLudovyc/Camera2D.gd index 551169d8..14f75c65 100644 --- a/theLudovyc/Camera2D.gd +++ b/theLudovyc/Camera2D.gd @@ -4,13 +4,15 @@ const SPEED = 500 const Edge_Limit = 10 -var pos_limit_top_left:Vector2 -var pos_limit_bot_right:Vector2 +var pos_limit_top_left: Vector2 +var pos_limit_bot_right: Vector2 + # Called when the node enters the scene tree for the first time. func _ready(): #Input.mouse_mode = Input.MOUSE_MODE_CONFINED - pass # Replace with function body. + pass # Replace with function body. + # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): @@ -18,29 +20,23 @@ func _process(delta): # #var viewport_rect = get_viewport_rect() # - var dir:Vector2 - + var dir: Vector2 #if mouse_pos.x < Edge_Limit: - #dir.x = -1 - # + #dir.x = -1 + # #if mouse_pos.x > viewport_rect.size.x - Edge_Limit: - #dir.x = 1 + #dir.x = 1 # #if mouse_pos.y < Edge_Limit: - #dir.y = -1 - # + #dir.y = -1 + # #if mouse_pos.y > viewport_rect.size.y - Edge_Limit: - #dir.y = 1 - # + #dir.y = 1 + # #dir = dir.normalized() - + #if dir.length() == 0: dir = Input.get_vector("move_left", "move_right", "move_up", "move_down") - position += dir * SPEED * delta - position.x = clamp(position.x, pos_limit_top_left.x, pos_limit_bot_right.x) - position.y = clamp(position.y, pos_limit_top_left.y, pos_limit_bot_right.y) - - pass diff --git a/theLudovyc/Entities.gd b/theLudovyc/Entities.gd index cc5af7fa..d6b38916 100644 --- a/theLudovyc/Entities.gd +++ b/theLudovyc/Entities.gd @@ -1,8 +1,3 @@ extends Node -enum types{ - Warehouse, - Residential, - Lumberjack, - Spruce -} +enum types { Warehouse, Residential, Lumberjack, Spruce } diff --git a/theLudovyc/EntityStatic.gd b/theLudovyc/EntityStatic.gd index c0eb4ea7..30a84612 100644 --- a/theLudovyc/EntityStatic.gd +++ b/theLudovyc/EntityStatic.gd @@ -15,23 +15,22 @@ class_name EntityStatic height = p_height update_offset() + func _ready(): if Engine.is_editor_hint(): texture_changed.connect(_on_texture_changed) - + + func update_offset(): if texture == null: return - if centered: centered = false - var final_height = height - - if (final_height%2 == 0): + if final_height % 2 == 0: final_height -= 1 - offset = Vector2(0, -texture.get_height()) + Vector2(-width * 32, final_height * 16) - + + func _on_texture_changed(): update_offset() diff --git a/theLudovyc/EventBus.gd b/theLudovyc/EventBus.gd index 2911cb3b..1316c5e0 100644 --- a/theLudovyc/EventBus.gd +++ b/theLudovyc/EventBus.gd @@ -14,8 +14,8 @@ signal send_building_selected(building_node) signal ask_deselect_building signal ask_select_warehouse -signal ask_demolish_current_building() -signal send_current_building_demolished() +signal ask_demolish_current_building +signal send_current_building_demolished ## POPULATION / WORKER signal population_updated(population_count) diff --git a/theLudovyc/GUI/BotMenu.gd b/theLudovyc/GUI/BotMenu.gd index b38a17b9..53454505 100644 --- a/theLudovyc/GUI/BotMenu.gd +++ b/theLudovyc/GUI/BotMenu.gd @@ -2,14 +2,14 @@ extends VBoxContainer @onready var panel_container = %PanelContainer -func set_menu_visibility(b:bool): + +func set_menu_visibility(b: bool): # avoid resize bug panel_container.visible = b - visible = b - + + func invert_menu_visibility(): # avoid resize bug panel_container.visible = !panel_container.visible - visible = !visible diff --git a/theLudovyc/GUI/BuildingContainer.gd b/theLudovyc/GUI/BuildingContainer.gd index 5fa8b22e..ca43494a 100644 --- a/theLudovyc/GUI/BuildingContainer.gd +++ b/theLudovyc/GUI/BuildingContainer.gd @@ -4,35 +4,40 @@ extends VBoxContainer @onready var building_info_container = $BuildingInfoContainer -@onready var event_bus:EventBus +@onready var event_bus: EventBus @onready var confirmation_dialog := %ConfirmationDialog const confirmation_text = "Are you sure you want to demolish this building?" + func _ready(): event_bus = get_tree().current_scene.get_node_or_null("EventBus") -func update_infos(building:Building2D): + +func update_infos(building: Building2D): var building_id = building.building_id - + name_label.text = Buildings.get_building_name(building_id) - + building_info_container.update_infos(building_id) + func _on_DeleteButton_pressed(): confirmation_dialog.canceled.connect(_on_ConfirmationDialog_canceled) confirmation_dialog.confirmed.connect(_on_ConfirmationDialog_confirmed) confirmation_dialog.dialog_text = confirmation_text confirmation_dialog.popup_centered() - + + func _on_ConfirmationDialog_canceled(): confirmation_dialog.canceled.disconnect(_on_ConfirmationDialog_canceled) confirmation_dialog.confirmed.disconnect(_on_ConfirmationDialog_confirmed) - + + func _on_ConfirmationDialog_confirmed(): confirmation_dialog.canceled.disconnect(_on_ConfirmationDialog_canceled) confirmation_dialog.confirmed.disconnect(_on_ConfirmationDialog_confirmed) - + if event_bus != null: event_bus.ask_demolish_current_building.emit() diff --git a/theLudovyc/GUI/BuildingInfoContainer.gd b/theLudovyc/GUI/BuildingInfoContainer.gd index 3c77668a..7a723e8e 100644 --- a/theLudovyc/GUI/BuildingInfoContainer.gd +++ b/theLudovyc/GUI/BuildingInfoContainer.gd @@ -4,24 +4,24 @@ extends TabContainer @onready var building_producing_container = $BuildingProducingContainer -enum Tabs{ - Residential, - Producing -} +enum Tabs { Residential, Producing } -func show_building_info_tab(tab_id:Tabs, building_id:Buildings.Ids): + +func show_building_info_tab(tab_id: Tabs, building_id: Buildings.Ids): visible = true - + current_tab = tab_id - + get_child(tab_id).update_infos(building_id) -func update_infos(building_id:Buildings.Ids): - match(Buildings.get_building_type(building_id)): + +func update_infos(building_id: Buildings.Ids): + match Buildings.get_building_type(building_id): Buildings.Types.Residential: show_building_info_tab(Tabs.Residential, building_id) - + Buildings.Types.Producing: show_building_info_tab(Tabs.Producing, building_id) - - _: visible = false + + _: + visible = false diff --git a/theLudovyc/GUI/BuildingProducingContainer.gd b/theLudovyc/GUI/BuildingProducingContainer.gd index a605aa50..cad97b1c 100644 --- a/theLudovyc/GUI/BuildingProducingContainer.gd +++ b/theLudovyc/GUI/BuildingProducingContainer.gd @@ -8,13 +8,14 @@ extends VBoxContainer @onready var workers_label = $HBoxContainer/WorkerContainer/ValueLabel -func update_infos(building_id:Buildings.Ids): + +func update_infos(building_id: Buildings.Ids): var resource_type = Buildings.get_produce_resource(building_id) - + resource_in.resource_type = Recipes.get_recipe_input(resource_type) - + resource_out.resource_type = resource_type ticks_label.text = str(Recipes.get_recipe_needed_ticks(resource_type)) - + workers_label.text = str(Buildings.get_max_workers(building_id)) diff --git a/theLudovyc/GUI/BuildingResidentialContainer.gd b/theLudovyc/GUI/BuildingResidentialContainer.gd index 2993364d..9357b1ce 100644 --- a/theLudovyc/GUI/BuildingResidentialContainer.gd +++ b/theLudovyc/GUI/BuildingResidentialContainer.gd @@ -2,6 +2,6 @@ extends HBoxContainer @onready var resident_label = $ValueLabel -func update_infos(building_id:Buildings.Ids): - resident_label.text = Helper.get_string_from_signed_int( - Buildings.get_max_workers(building_id)) + +func update_infos(building_id: Buildings.Ids): + resident_label.text = Helper.get_string_from_signed_int(Buildings.get_max_workers(building_id)) diff --git a/theLudovyc/GUI/ButtonBuild.gd b/theLudovyc/GUI/ButtonBuild.gd index 1e0d68c0..a0f537d0 100644 --- a/theLudovyc/GUI/ButtonBuild.gd +++ b/theLudovyc/GUI/ButtonBuild.gd @@ -1,3 +1,3 @@ extends TextureButton -@export var building_id:Buildings.Ids +@export var building_id: Buildings.Ids diff --git a/theLudovyc/GUI/CustomSpinBox.gd b/theLudovyc/GUI/CustomSpinBox.gd index eb0363f1..db491c91 100644 --- a/theLudovyc/GUI/CustomSpinBox.gd +++ b/theLudovyc/GUI/CustomSpinBox.gd @@ -2,15 +2,20 @@ extends SpinBox @onready var line_edit = get_line_edit() + # Called when the node enters the scene tree for the first time. func _ready(): line_edit.context_menu_enabled = false line_edit.gui_input.connect(_on_gui_input) - pass # Replace with function body. + pass # Replace with function body. + -func _on_gui_input(event:InputEvent): - if event is InputEventKey and event.pressed and \ - (event.keycode == KEY_ENTER or event.keycode == KEY_KP_ENTER): +func _on_gui_input(event: InputEvent): + if ( + event is InputEventKey + and event.pressed + and (event.keycode == KEY_ENTER or event.keycode == KEY_KP_ENTER) + ): line_edit.release_focus() line_edit.accept_event() diff --git a/theLudovyc/GUI/GUI.gd b/theLudovyc/GUI/GUI.gd index acf1d745..44f811e0 100644 --- a/theLudovyc/GUI/GUI.gd +++ b/theLudovyc/GUI/GUI.gd @@ -3,22 +3,21 @@ class_name GUI @onready var rtl_info := $RichTextLabelInfo -enum { - ResourceButton -} +enum { ResourceButton } -const scenes = { - ResourceButton:preload("res://theLudovyc/GUI/ResourceButton.tscn") -} +const scenes = {ResourceButton: preload("res://theLudovyc/GUI/ResourceButton.tscn")} -func set_rtl_info_text(text:String): + +func set_rtl_info_text(text: String): rtl_info.text = text - -func set_rtl_info_text_money_cost(amount:int): + + +func set_rtl_info_text_money_cost(amount: int): rtl_info.clear() - + rtl_info.append_text("[center]" + str(amount) + " ") rtl_info.add_image(TheBank.money_icon, 20) -func set_rtl_visibility(b:bool): + +func set_rtl_visibility(b: bool): rtl_info.visible = b diff --git a/theLudovyc/GUI/GridContainer.gd b/theLudovyc/GUI/GridContainer.gd index 05c216df..21c69581 100644 --- a/theLudovyc/GUI/GridContainer.gd +++ b/theLudovyc/GUI/GridContainer.gd @@ -1,6 +1,6 @@ extends GridContainer -var event_bus:EventBus +var event_bus: EventBus @onready var widget := %Widget @@ -8,38 +8,43 @@ var event_bus:EventBus @onready var tooltip := %WidgetTooltip + # Called when the node enters the scene tree for the first time. func _ready(): var root_node = get_tree().current_scene - - if (root_node.has_node("EventBus")): + + if root_node.has_node("EventBus"): event_bus = root_node.get_node("EventBus") - + event_bus.send_building_created.connect(_on_building_event.unbind(1)) event_bus.send_building_creation_aborted.connect(_on_building_event.unbind(1)) - + for child in get_children(): child.pressed.connect(_on_building_button_pressed.bind(child.building_id)) child.mouse_entered.connect(_on_building_button_mouse_entered.bind(child.building_id)) child.mouse_exited.connect(_on_building_button_mouse_exited) -func _on_building_button_pressed(building_id:Buildings.Ids): - if (event_bus): + +func _on_building_button_pressed(building_id: Buildings.Ids): + if event_bus: event_bus.ask_create_building.emit(building_id) - + widget.disable_buttons(true) - + bottom_container.set_menu_visibility(false) + func _on_building_event(): widget.disable_buttons(false) - + bottom_container.set_menu_visibility(true) - -func _on_building_button_mouse_entered(building_id:Buildings.Ids): + + +func _on_building_button_mouse_entered(building_id: Buildings.Ids): tooltip.set_building_info(building_id) tooltip.visible = true - + + func _on_building_button_mouse_exited(): tooltip.visible = false pass diff --git a/theLudovyc/GUI/LabelPopulation.gd b/theLudovyc/GUI/LabelPopulation.gd index a597b2ae..d6b13343 100644 --- a/theLudovyc/GUI/LabelPopulation.gd +++ b/theLudovyc/GUI/LabelPopulation.gd @@ -1,13 +1,17 @@ extends Label + # Called when the node enters the scene tree for the first time. func _ready(): var current_node = get_tree().current_scene - + if current_node.has_node("EventBus"): - current_node.get_node("EventBus").connect("population_updated", _on_EventBus_popupation_updated) - - pass # Replace with function body. + current_node.get_node("EventBus").connect( + "population_updated", _on_EventBus_popupation_updated + ) + + pass # Replace with function body. + func _on_EventBus_popupation_updated(population_count): text = str(population_count) diff --git a/theLudovyc/GUI/LabelWorkers.gd b/theLudovyc/GUI/LabelWorkers.gd index c3914251..e6098e23 100644 --- a/theLudovyc/GUI/LabelWorkers.gd +++ b/theLudovyc/GUI/LabelWorkers.gd @@ -1,13 +1,17 @@ extends Label + # Called when the node enters the scene tree for the first time. func _ready(): var current_node = get_tree().current_scene - + if current_node.has_node("EventBus"): - current_node.get_node("EventBus").connect("available_workers_updated", _on_EventBus_available_workers_updated_updated) - - pass # Replace with function body. + current_node.get_node("EventBus").connect( + "available_workers_updated", _on_EventBus_available_workers_updated_updated + ) + + pass # Replace with function body. + func _on_EventBus_available_workers_updated_updated(available_workers_amount): text = "(" + Helper.get_string_from_signed_int(available_workers_amount) + ")" diff --git a/theLudovyc/GUI/MarketContainer.gd b/theLudovyc/GUI/MarketContainer.gd index cb28b289..ee6627fe 100644 --- a/theLudovyc/GUI/MarketContainer.gd +++ b/theLudovyc/GUI/MarketContainer.gd @@ -1,6 +1,6 @@ extends VBoxContainer -var event_bus:EventBus = null +var event_bus: EventBus = null var resource_order_scene = preload("res://theLudovyc/GUI/ResourceOrder.tscn") @@ -12,46 +12,52 @@ var resource_order_scene = preload("res://theLudovyc/GUI/ResourceOrder.tscn") var order_nodes = {} + func _ready(): var current_scene = get_tree().current_scene - + if current_scene.has_node("EventBus"): event_bus = current_scene.get_node("EventBus") as EventBus - + event_bus.send_create_new_order.connect(_on_receive_create_new_order) event_bus.send_remove_order.connect(_on_receive_remove_order) event_bus.send_update_order_buy.connect(_on_receive_update_order_buy) - event_bus.money_production_rate_updated.connect( - _on_receive_money_production_rate_updated) - + event_bus.money_production_rate_updated.connect(_on_receive_money_production_rate_updated) + resource_popup.result.connect(_on_ResourcePopup_result) -func _on_ResourcePopup_result(resource_type:Resources.Types): + +func _on_ResourcePopup_result(resource_type: Resources.Types): event_bus.ask_create_new_order.emit(resource_type) + func _on_NewOrderButton_pressed(): resource_popup.popup_centered() - -func _on_receive_create_new_order(resource_type:Resources.Types): + + +func _on_receive_create_new_order(resource_type: Resources.Types): var resource_order = resource_order_scene.instantiate() - + order_container.add_child(resource_order) - + resource_order._resource_type = resource_type - + order_nodes[resource_type] = resource_order -func _on_receive_remove_order(resource_type:Resources.Types): + +func _on_receive_remove_order(resource_type: Resources.Types): order_nodes[resource_type].queue_free() - + order_nodes.erase(resource_type) -func _on_receive_update_order_buy(resource_type:Resources.Types, buy_amount:int): + +func _on_receive_update_order_buy(resource_type: Resources.Types, buy_amount: int): if not order_nodes.has(resource_type): #ERROR pass - + order_nodes[resource_type].force_buy_amount(buy_amount) + func _on_receive_money_production_rate_updated(production_rate): tooltip.set_money_production_rate_info(production_rate) diff --git a/theLudovyc/GUI/MoneyControl.gd b/theLudovyc/GUI/MoneyControl.gd index 9a6738e8..c1a591fd 100644 --- a/theLudovyc/GUI/MoneyControl.gd +++ b/theLudovyc/GUI/MoneyControl.gd @@ -3,21 +3,25 @@ extends PanelContainer @onready var label_amount := $HBoxContainer/PanelContainer/HBoxContainer/LabelAmount @onready var label_production_rate := $HBoxContainer/PanelContainer/HBoxContainer/LabelProductionRate + # Called when the node$".", $HBoxContainer/PanelContainer/HBoxContainer/LabelProductionRate enters the scene tree for the first time. func _ready(): var current_node = get_tree().current_scene - + if current_node.has_node("EventBus"): var event_bus = current_node.get_node("EventBus") - + event_bus.connect("money_updated", _on_EventBus_money_updated) - event_bus.connect("money_production_rate_updated", - _on_EventBus_money_production_rate_updated) - + event_bus.connect( + "money_production_rate_updated", _on_EventBus_money_production_rate_updated + ) + $TextureButton.get_node("TextureRect").texture = TheBank.money_icon + func _on_EventBus_money_updated(amount): label_amount.text = str(amount) - + + func _on_EventBus_money_production_rate_updated(production_rate): label_production_rate.text = "(" + Helper.get_string_from_signed_int(production_rate) + ")" diff --git a/theLudovyc/GUI/ResourceButton.gd b/theLudovyc/GUI/ResourceButton.gd index 4b6f0415..3032cbba 100644 --- a/theLudovyc/GUI/ResourceButton.gd +++ b/theLudovyc/GUI/ResourceButton.gd @@ -1,16 +1,18 @@ extends TextureButton -@export var _type:Resources.Types +@export var _type: Resources.Types -func set_resource_icon(type:Resources.Types): + +func set_resource_icon(type: Resources.Types): if Resources.Icons.has(type): $TextureRect.texture = Resources.Icons[type] + # Called when the node enters the scene tree for the first time. func _ready(): set_resource_icon(_type) - pass # Replace with function body. - + pass # Replace with function body. + # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): diff --git a/theLudovyc/GUI/ResourceControl.gd b/theLudovyc/GUI/ResourceControl.gd index 898510d5..559e5c58 100644 --- a/theLudovyc/GUI/ResourceControl.gd +++ b/theLudovyc/GUI/ResourceControl.gd @@ -1,26 +1,31 @@ extends PanelContainer -@export var resource_type : Resources.Types +@export var resource_type: Resources.Types @onready var label_amount := $HBoxContainer/PanelContainer/HBoxContainer/LabelAmount @onready var label_production_rate := $HBoxContainer/PanelContainer/HBoxContainer/LabelProductionRate + # Called when the node enters the scene tree for the first time. func _ready(): $TextureButton.set_resource_icon(resource_type) - + var current_node = get_tree().current_scene - + if current_node.has_node("EventBus"): var event_bus = current_node.get_node("EventBus") - + event_bus.connect("resource_updated", _on_EventBus_resource_updated) - event_bus.connect("resource_prodution_rate_updated", _on_EventBus_resource_production_rate_updated) + event_bus.connect( + "resource_prodution_rate_updated", _on_EventBus_resource_production_rate_updated + ) + func _on_EventBus_resource_updated(type, amount): if type == resource_type: label_amount.text = str(amount) - + + func _on_EventBus_resource_production_rate_updated(type, rate): if type == resource_type: label_production_rate.text = "(" + Helper.get_string_from_signed_int(rate) + ")" diff --git a/theLudovyc/GUI/ResourceOrder.gd b/theLudovyc/GUI/ResourceOrder.gd index e22e1f28..9e7befa2 100644 --- a/theLudovyc/GUI/ResourceOrder.gd +++ b/theLudovyc/GUI/ResourceOrder.gd @@ -1,6 +1,6 @@ extends HBoxContainer -var event_bus:EventBus = null +var event_bus: EventBus = null @onready var _resource_texture = $VBoxContainer/TextureRect @@ -10,39 +10,45 @@ var event_bus:EventBus = null @onready var label = $VBoxContainer/Label -var _resource_type:Resources.Types: +var _resource_type: Resources.Types: set(value): _resource_type = value - + if is_instance_valid(_resource_texture): if Resources.Icons.has(value): _resource_texture.texture = Resources.Icons[value] + func _ready(): var current_scene = get_tree().current_scene - + if current_scene.has_node("EventBus"): event_bus = current_scene.get_node("EventBus") as EventBus - + event_bus.resource_prodution_rate_updated.connect(_on_resource_prodution_rate_updated) + func _on_BuySpinBox_value_changed(value): if event_bus != null: event_bus.ask_update_order_buy.emit(_resource_type, value) - + + func force_buy_value(buy_amount): buy_spin_box.set_value_no_signal(buy_amount) + func _on_SellSpinBox_value_changed(value): if event_bus != null: event_bus.ask_update_order_sell.emit(_resource_type, value) + func _on_DeleteButton_pressed(): delete_button.disabled = true - + if event_bus != null: event_bus.ask_remove_order.emit(_resource_type) -func _on_resource_prodution_rate_updated(resource_type:Resources.Types, rate:int): + +func _on_resource_prodution_rate_updated(resource_type: Resources.Types, rate: int): if resource_type == _resource_type: label.text = "(" + Helper.get_string_from_signed_int(rate) + ")" diff --git a/theLudovyc/GUI/ResourcePopup.gd b/theLudovyc/GUI/ResourcePopup.gd index a13bc69e..fa907c1d 100644 --- a/theLudovyc/GUI/ResourcePopup.gd +++ b/theLudovyc/GUI/ResourcePopup.gd @@ -4,19 +4,21 @@ extends Window signal result(resource_type) + func _ready(): for resource_type in range(Resources.Types.size()): var resource_button = GUI.scenes[GUI.ResourceButton].instantiate() - + resource_button.pressed.connect(_on_ResourceButton_pressed.bind(resource_type)) - + grid_container.add_child(resource_button) - + resource_button.set_resource_icon(resource_type) pass -func _on_ResourceButton_pressed(resource_type:Resources.Types): + +func _on_ResourceButton_pressed(resource_type: Resources.Types): result.emit(resource_type) - + hide() pass diff --git a/theLudovyc/GUI/ResourceTextureRect.gd b/theLudovyc/GUI/ResourceTextureRect.gd index e17fcf0b..52575054 100644 --- a/theLudovyc/GUI/ResourceTextureRect.gd +++ b/theLudovyc/GUI/ResourceTextureRect.gd @@ -1,7 +1,7 @@ extends TextureRect -@export var resource_type:Resources.Types: +@export var resource_type: Resources.Types: set(value): resource_type = value - + texture = Resources.get_resource_icon(resource_type) diff --git a/theLudovyc/GUI/RichTextLabelInfo.gd b/theLudovyc/GUI/RichTextLabelInfo.gd index 481fa7f7..4d6b90ee 100644 --- a/theLudovyc/GUI/RichTextLabelInfo.gd +++ b/theLudovyc/GUI/RichTextLabelInfo.gd @@ -1,13 +1,15 @@ extends RichTextLabel + # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): position = get_global_mouse_position() - Vector2(size.x / 2, size.y * 1.25) pass + func _on_visibility_changed(): # to avoid teleport effect - if (visible): + if visible: position = get_global_mouse_position() - Vector2(size.x / 2, size.y * 1.25) - + set_process(visible) diff --git a/theLudovyc/GUI/TabContainer.gd b/theLudovyc/GUI/TabContainer.gd index 1ff63d52..5812b113 100644 --- a/theLudovyc/GUI/TabContainer.gd +++ b/theLudovyc/GUI/TabContainer.gd @@ -1,10 +1,6 @@ extends TabContainer -enum WidgetMenus { - Market, - Build, - Building -} +enum WidgetMenus { Market, Build, Building } @onready var bottom_container = %BottomContainer @@ -12,74 +8,79 @@ enum WidgetMenus { @onready var building_container := $BuildingContainer -var event_bus:EventBus +var event_bus: EventBus + # Called when the node enters the scene tree for the first time. func _ready(): event_bus = get_tree().current_scene.get_node_or_null("EventBus") - + if event_bus != null: event_bus.send_building_selected.connect(_on_receive_building_selected) event_bus.send_current_building_demolished.connect(_on_receive_current_building_demolished) - - pass # Replace with function body. -func on_MenuButton_pressed(menu:WidgetMenus): + pass # Replace with function body. + + +func on_MenuButton_pressed(menu: WidgetMenus): if current_tab != menu: - if current_tab == WidgetMenus.Building or \ - current_tab == WidgetMenus.Market: + if current_tab == WidgetMenus.Building or current_tab == WidgetMenus.Market: event_bus.ask_deselect_building.emit() - + current_tab = menu - + bottom_container.set_menu_visibility(true) return - + bottom_container.invert_menu_visibility() + func _on_BuildMenuButton_pressed(): on_MenuButton_pressed(WidgetMenus.Build) - + if tooltip.visible: tooltip.visible = false + func _on_MarketMenuButton_pressed(): on_MenuButton_pressed(WidgetMenus.Market) - + if bottom_container.visible: if event_bus != null: event_bus.ask_select_warehouse.emit() - + tooltip.visible = true - + tooltip.set_money_production_rate_info() else: if event_bus != null: event_bus.ask_deselect_building.emit() - + tooltip.visible = false - -func _on_receive_building_selected(building:Building2D): + + +func _on_receive_building_selected(building: Building2D): bottom_container.set_menu_visibility(true) - + if Buildings.get_building_type(building.building_id) == Buildings.Types.Warehouse: if current_tab != WidgetMenus.Market: current_tab = WidgetMenus.Market - + if tooltip.visible == false: tooltip.visible = true tooltip.set_money_production_rate_info() - + return - + if current_tab != WidgetMenus.Building: current_tab = WidgetMenus.Building - + if tooltip.visible: tooltip.visible = false - + building_container.update_infos(building) + func _on_receive_current_building_demolished(): if current_tab == WidgetMenus.Building: bottom_container.set_menu_visibility(false) diff --git a/theLudovyc/GUI/Tooltip.gd b/theLudovyc/GUI/Tooltip.gd index 11893c1d..80d4f299 100644 --- a/theLudovyc/GUI/Tooltip.gd +++ b/theLudovyc/GUI/Tooltip.gd @@ -2,31 +2,33 @@ extends PanelContainer @onready var rtl := $VBoxContainer/PanelContainer/RichTextLabel -func set_building_info(building_id:Buildings.Ids): + +func set_building_info(building_id: Buildings.Ids): rtl.clear() - + var building_cost = Buildings.get_building_cost(building_id) - + if building_cost.is_empty(): return - + rtl.add_text("Cost :\n") - + for i in range(building_cost.size()): var cost = building_cost[i] - + if i > 0: rtl.add_text(" / ") - + rtl.add_text(str(cost[1]) + " ") rtl.add_image(Resources.Icons[cost[0]], 20) -func set_money_production_rate_info(production_rate:int = 0): + +func set_money_production_rate_info(production_rate: int = 0): rtl.clear() rtl.append_text("[center]") rtl.add_image(TheBank.money_icon, 20) - + var text_sign = "+" if production_rate >= 0 else "" - + rtl.append_text("(" + text_sign + str(production_rate) + ")") pass diff --git a/theLudovyc/GUI/Widget.gd b/theLudovyc/GUI/Widget.gd index 0a74ea73..79d517cf 100644 --- a/theLudovyc/GUI/Widget.gd +++ b/theLudovyc/GUI/Widget.gd @@ -1,9 +1,8 @@ extends Control -@onready var buttons = [ - $BuildMenuButton, $MarketMenuButton -] +@onready var buttons = [$BuildMenuButton, $MarketMenuButton] -func disable_buttons(b:bool): + +func disable_buttons(b: bool): for button in buttons: button.disabled = b diff --git a/theLudovyc/Game2D.gd b/theLudovyc/Game2D.gd index d903bb48..d4adb299 100644 --- a/theLudovyc/Game2D.gd +++ b/theLudovyc/Game2D.gd @@ -19,60 +19,62 @@ class_name Game2D @onready var pause_menu := %PauseMenu const Buildings_Scenes = { - Buildings.Ids.Warehouse:preload("res://theLudovyc/Building/Warehouse.tscn"), - Buildings.Ids.Tent:preload("res://theLudovyc/Building/Residential.tscn"), - Buildings.Ids.Lumberjack:preload("res://theLudovyc/Building/Lumberjack.tscn") + Buildings.Ids.Warehouse: preload("res://theLudovyc/Building/Warehouse.tscn"), + Buildings.Ids.Tent: preload("res://theLudovyc/Building/Residential.tscn"), + Buildings.Ids.Lumberjack: preload("res://theLudovyc/Building/Lumberjack.tscn") } const Trees_Destroy_Cost = 1 # if not null follow the cursor -var cursor_entity : Building2D +var cursor_entity: Building2D # avoid create building on first clic -var cursor_entity_wait_release : bool = false +var cursor_entity_wait_release: bool = false -var population := 0 : +var population := 0: set(value): population = value event_bus.population_updated.emit(value) event_bus.available_workers_updated.emit(population - the_factory.workers) -var warehouse:Building2D +var warehouse: Building2D + +var current_selected_building: Building2D = null -var current_selected_building:Building2D = null # Called when the node enters the scene tree for the first time. func _ready(): tm.create_island("res://theLudovyc/singularity_40.json") - + # spawn the warehouse warehouse = instantiate_building(Buildings.Ids.Warehouse) - + var warehouse_center_tile = Vector2i(1, 20) - + warehouse.position = tm.map_to_local(warehouse_center_tile) - + tm.build_entityStatic(warehouse, warehouse_center_tile) - + warehouse.build() - + # set camera limits var pos_limits = tm.get_pos_limits() - + cam.pos_limit_top_left = pos_limits[0] cam.pos_limit_bot_right = pos_limits[1] - + # force camera initial pos on warehouse cam.position = warehouse.global_position cam.reset_smoothing() - + # add some initial resources the_bank.money = 100 - + the_storage.add_resource(Resources.Types.Wood, 2) the_storage.add_resource(Resources.Types.Textile, 16) - - pass # Replace with function body. + + pass # Replace with function body. + # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): @@ -80,60 +82,67 @@ func _process(delta): pause_menu.show() pause_menu.set_process(true) get_tree().paused = true - + var mouse_pos = get_viewport().get_mouse_position() - + rtl.text = "" - + rtl.text += str(mouse_pos) + "\n" - + rtl.text += str(cam.get_screen_center_position()) + "\n" - + # may be optimized mouse_pos += cam.get_screen_center_position() - get_viewport().get_visible_rect().size / 2 - + rtl.text += str(mouse_pos) + "\n" - + var tile_pos = tm.local_to_map(mouse_pos) - + rtl.text += str(tile_pos) + "\n" - + rtl.text += str(tm.is_constructible(tile_pos)) + "\n" - + var tile_data = tm.get_cell_tile_data(0, tile_pos) - + if tile_data != null: rtl.text += str(tile_data.terrain_set) + " / " + str(tile_data.terrain) + "\n" - + rtl.text += str(tm.get_cell_atlas_coords(0, tile_pos)) - + #spawn entity - if (cursor_entity): + if cursor_entity: cursor_entity.position = tm.map_to_local(tile_pos) - + var building_id = cursor_entity.building_id - + var trees_to_destroy = tm.is_entityStatic_constructible(cursor_entity, tile_pos) - + var trees_to_destroy_final_cost := 0 - + if trees_to_destroy > 0: trees_to_destroy_final_cost = trees_to_destroy * Trees_Destroy_Cost - + if trees_to_destroy_final_cost > 0: gui.set_rtl_info_text_money_cost(trees_to_destroy_final_cost) gui.set_rtl_visibility(true) else: gui.set_rtl_visibility(false) - + var is_constructible = false - - if trees_to_destroy >= 0 and \ - (trees_to_destroy_final_cost == 0 or \ - (trees_to_destroy_final_cost > 0 and trees_to_destroy_final_cost <= the_bank.money)) \ - and the_storage.has_resources_to_construct_building(building_id): + + if ( + trees_to_destroy >= 0 + and ( + trees_to_destroy_final_cost == 0 + or ( + trees_to_destroy_final_cost > 0 + and trees_to_destroy_final_cost <= the_bank.money + ) + ) + and the_storage.has_resources_to_construct_building(building_id) + ): is_constructible = true - + if is_constructible: if trees_to_destroy > 0: cursor_entity.modulate = Color(Color.ORANGE, 0.6) @@ -141,101 +150,111 @@ func _process(delta): cursor_entity.modulate = Color(Color.GREEN, 0.6) else: cursor_entity.modulate = Color(Color.RED, 0.6) - + if cursor_entity_wait_release and Input.is_action_just_released("alt_command"): cursor_entity_wait_release = false - - if not cursor_entity_wait_release \ - and is_constructible \ - and Input.is_action_just_pressed("alt_command"): - match(Buildings.get_building_type(building_id)): + + if ( + not cursor_entity_wait_release + and is_constructible + and Input.is_action_just_pressed("alt_command") + ): + match Buildings.get_building_type(building_id): Buildings.Types.Residential: var amount := Buildings.get_max_workers(building_id) - + population += amount - + the_factory.population_increase(amount) - + Buildings.Types.Producing: the_factory.add_workers( Buildings.get_produce_resource(building_id), - Buildings.get_max_workers(building_id)) - + Buildings.get_max_workers(building_id) + ) + if trees_to_destroy_final_cost > 0: gui.set_rtl_visibility(false) - + the_bank.money -= trees_to_destroy_final_cost - + the_storage.conclude_building_construction(building_id) - + event_bus.send_building_created.emit(building_id) - + tm.build_entityStatic(cursor_entity, tile_pos) - + cursor_entity.modulate = Color.WHITE cursor_entity.build() cursor_entity = null - + if cursor_entity and Input.is_action_just_pressed("main_command"): if trees_to_destroy_final_cost > 0: gui.set_rtl_visibility(false) - + event_bus.send_building_creation_aborted.emit(building_id) - + cursor_entity.call_deferred("queue_free") cursor_entity = null -func instantiate_building(building_id:Buildings.Ids) -> Building2D: + +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) - + return instance -func _on_EventBus_ask_create_building(building_id:Buildings.Ids): + +func _on_EventBus_ask_create_building(building_id: Buildings.Ids): var entity := instantiate_building(building_id) cursor_entity = entity cursor_entity_wait_release = true cursor_entity.modulate = Color(Color.RED, 0.6) + func _on_EventBus_send_building_selected(building_node): current_selected_building = building_node + func _on_EventBus_ask_deselect_building(): if current_selected_building != null: current_selected_building.deselect() current_selected_building = null + func _on_EventBus_ask_select_warehouse(): current_selected_building = warehouse - + warehouse.select() + func _on_EventBus_ask_demolish_current_building(): tm.demolish_building(current_selected_building) - + var building_id = current_selected_building.building_id - + the_storage.recover_building_construction(building_id) - - match(Buildings.get_building_type(building_id)): + + match Buildings.get_building_type(building_id): Buildings.Types.Residential: var amount := Buildings.get_max_workers(building_id) - + population -= amount - + the_factory.population_decrease(amount) - + Buildings.Types.Producing: the_factory.rem_workers( - Buildings.get_produce_resource(building_id), - Buildings.get_max_workers(building_id)) - _:pass - + Buildings.get_produce_resource(building_id), Buildings.get_max_workers(building_id) + ) + _: + pass + current_selected_building.queue_free() current_selected_building = null - + event_bus.send_current_building_demolished.emit() diff --git a/theLudovyc/Helper.gd b/theLudovyc/Helper.gd index 1dba6dcd..4468658d 100644 --- a/theLudovyc/Helper.gd +++ b/theLudovyc/Helper.gd @@ -1,5 +1,6 @@ extends Object class_name Helper -static func get_string_from_signed_int(i:int): + +static func get_string_from_signed_int(i: int): return ("+" if i >= 0 else "") + str(i) diff --git a/theLudovyc/Resources/Recipes.gd b/theLudovyc/Resources/Recipes.gd index 2d271975..ad66da23 100644 --- a/theLudovyc/Resources/Recipes.gd +++ b/theLudovyc/Resources/Recipes.gd @@ -2,34 +2,27 @@ extends Object class_name Recipes # Needed 1 resource input, tick(s) and Worker(s) to produce 1 resource output -enum Datas{ - Input, - Ticks, - Workers -} - -const datas = { - Resources.Types.Wood : { - Datas.Input : -1, - Datas.Ticks : 1, - Datas.Workers: 4 - } -} - -static func get_recipe_input(resource_type:Resources.Types) -> int: +enum Datas { Input, Ticks, Workers } + +const datas = {Resources.Types.Wood: {Datas.Input: -1, Datas.Ticks: 1, Datas.Workers: 4}} + + +static func get_recipe_input(resource_type: Resources.Types) -> int: if not datas.has(resource_type): return 0 - + return datas[resource_type].get(Datas.Input) -static func get_recipe_needed_ticks(resource_type:Resources.Types) -> int: + +static func get_recipe_needed_ticks(resource_type: Resources.Types) -> int: if not datas.has(resource_type): return 0 - + return datas[resource_type].get(Datas.Ticks, 0) - -static func get_recipe_needed_workers(resource_type:Resources.Types) -> int: + + +static func get_recipe_needed_workers(resource_type: Resources.Types) -> int: if not datas.has(resource_type): return 0 - + return datas[resource_type].get(Datas.Workers, 0) diff --git a/theLudovyc/Resources/Resources.gd b/theLudovyc/Resources/Resources.gd index 1761244f..84b0235d 100644 --- a/theLudovyc/Resources/Resources.gd +++ b/theLudovyc/Resources/Resources.gd @@ -1,26 +1,18 @@ extends Object class_name Resources -enum Types{ - Wood, - Textile -} +enum Types { Wood, Textile } const Icons = { - Types.Wood:preload("res://Art/Image/Gui/Icons/Resources/32/008.png"), - Types.Textile:preload("res://Art/Image/Gui/Icons/Resources/32/003.png") + Types.Wood: preload("res://Art/Image/Gui/Icons/Resources/32/008.png"), + Types.Textile: preload("res://Art/Image/Gui/Icons/Resources/32/003.png") } -static func get_resource_icon(resource_type:Types) -> Texture2D: + +static func get_resource_icon(resource_type: Types) -> Texture2D: return Icons.get(resource_type) -enum LevelTypes{ - Gathered, - TransformedOnce, - TransformedTwice -} -const Levels = { - Types.Wood:LevelTypes.Gathered, - Types.Textile:LevelTypes.TransformedTwice -} +enum LevelTypes { Gathered, TransformedOnce, TransformedTwice } + +const Levels = {Types.Wood: LevelTypes.Gathered, Types.Textile: LevelTypes.TransformedTwice} diff --git a/theLudovyc/TheBank.gd b/theLudovyc/TheBank.gd index 1a8f6a98..1da2df8b 100644 --- a/theLudovyc/TheBank.gd +++ b/theLudovyc/TheBank.gd @@ -9,11 +9,11 @@ const money_icon = preload("res://Art/Image/Gui/Icons/Resources/32/001.png") @onready var the_storage := $"../TheStorage" -var money := 0 : +var money := 0: set(value): money = value event_bus.money_updated.emit(value) - + var money_production_rate := 0: set(value): money_production_rate = value @@ -22,59 +22,62 @@ var money_production_rate := 0: var orders_cost := 0: set(value): orders_cost = value - + update_money_production_rate() + #in futur it will also have buildings_cost func update_money_production_rate(): money_production_rate = orders_cost -func try_to_buy_resource(resource_type:Resources.Types, amount:int) -> bool: + +func try_to_buy_resource(resource_type: Resources.Types, amount: int) -> bool: if amount == 0: return false - - var cost:int = the_market.get_resource_cost(resource_type) * amount - + + var cost: int = the_market.get_resource_cost(resource_type) * amount + if money >= cost: money -= cost return true - + return false - -func conclude_sale(resource_type:Resources.Types, amount:int): + + +func conclude_sale(resource_type: Resources.Types, amount: int): if amount <= 0: return - + money += the_market.get_resource_cost(resource_type) * amount - + recalculate_orders_cost() + # can be optimised if we know the resource type # remove the resource cost then readd if it is needed func recalculate_orders_cost(): var market_orders = the_market.orders - + if market_orders.is_empty(): orders_cost = 0 return - + # do not update the orders_cost directly # it will be updated at each iteration of the loop # so it will be update money production rate at each iteration var tmp_orders_cost := 0 - + for order_key in market_orders: var order = market_orders[order_key] - + var resource_cost = the_market.get_resource_cost(order_key) - + if order.buy_amount > 0: tmp_orders_cost -= resource_cost * order.buy_amount - - if order.sell_amount == 0 or \ - order.sell_amount > the_storage.get_resource_amount(order_key): + + if order.sell_amount == 0 or order.sell_amount > the_storage.get_resource_amount(order_key): continue - + tmp_orders_cost += resource_cost * order.sell_amount - + orders_cost = tmp_orders_cost diff --git a/theLudovyc/TheFactory.gd b/theLudovyc/TheFactory.gd index 4896b9e9..ed039513 100644 --- a/theLudovyc/TheFactory.gd +++ b/theLudovyc/TheFactory.gd @@ -1,11 +1,11 @@ extends Node class_name TheFactory -@onready var game:Game2D = get_parent() +@onready var game: Game2D = get_parent() @onready var storage = $"../TheStorage" @onready var event_bus = $"../EventBus" -enum Production_Line{current_workers, production_rate, current_ticks} +enum Production_Line { current_workers, production_rate, current_ticks } var production_lines = {} var workers := 0: @@ -13,141 +13,148 @@ var workers := 0: workers = value event_bus.available_workers_updated.emit(game.population - workers) -enum Waiting_Lines{resource_type, needed_workers} +enum Waiting_Lines { resource_type, needed_workers } var waiting_lines = [] -func get_production_rate_per_tick(resource_type:Resources.Types) -> int: + +func get_production_rate_per_tick(resource_type: Resources.Types) -> int: if not production_lines.has(resource_type): return 0 - + return production_lines[resource_type][Production_Line.production_rate] -func create_or_update_line(resource_type:Resources.Types, workers_amount:int): + +func create_or_update_line(resource_type: Resources.Types, workers_amount: int): var needed_workers = Recipes.get_recipe_needed_workers(resource_type) - + if production_lines.has(resource_type): var line = production_lines[resource_type] - + line[Production_Line.current_workers] += workers_amount - + line[Production_Line.production_rate] = int( - line[Production_Line.current_workers] / needed_workers) + line[Production_Line.current_workers] / needed_workers + ) else: - var production_rate:int = 0 - - if (workers_amount >= needed_workers): + var production_rate: int = 0 + + if workers_amount >= needed_workers: production_rate = workers_amount / needed_workers - + production_lines[resource_type] = [workers_amount, production_rate, 0] - + storage.update_global_production_rate(resource_type) -func add_workers(resource_type:Resources.Types, workers_amount:int): + +func add_workers(resource_type: Resources.Types, workers_amount: int): if workers_amount == 0: return elif workers_amount < 0: - rem_workers(resource_type, - workers_amount) + rem_workers(resource_type, -workers_amount) return - + workers += workers_amount - + if (game.population - workers) < 0: waiting_lines.push_back([resource_type, workers_amount]) else: create_or_update_line(resource_type, workers_amount) -func rem_workers(resource_type:Resources.Types, workers_amount:int): + +func rem_workers(resource_type: Resources.Types, workers_amount: int): if workers_amount == 0: return elif workers_amount < 0: - add_workers(resource_type, - workers_amount) + add_workers(resource_type, -workers_amount) return - + workers -= workers_amount - + if not waiting_lines.is_empty(): var i := waiting_lines.rfind([resource_type, workers_amount]) - + if i != -1: waiting_lines.remove_at(i) return - + if production_lines.has(resource_type): var line = production_lines[resource_type] - + line[Production_Line.current_workers] -= workers_amount - + if line[Production_Line.current_workers] == 0: production_lines.erase(resource_type) return - + line[Production_Line.production_rate] = int( - line[Production_Line.current_workers] / - Recipes.get_recipe_needed_workers(resource_type)) - + line[Production_Line.current_workers] / Recipes.get_recipe_needed_workers(resource_type) + ) + storage.update_global_production_rate(resource_type) -func population_increase(amount:int): + +func population_increase(amount: int): var population_pool = amount - + var i := 0 - + while i < waiting_lines.size(): if waiting_lines[i][Waiting_Lines.needed_workers] <= population_pool: var waiting_line = waiting_lines.pop_at(i) - + var waiting_line_needed_workers = waiting_line[Waiting_Lines.needed_workers] - - create_or_update_line(waiting_line[Waiting_Lines.resource_type], - waiting_line_needed_workers) - + + create_or_update_line( + waiting_line[Waiting_Lines.resource_type], waiting_line_needed_workers + ) + population_pool -= waiting_line_needed_workers - + if population_pool <= 0: break else: i += 1 - -func population_decrease(amount:int): + + +func population_decrease(amount: int): var population_pool = amount - - while(not production_lines.is_empty()): + + while not production_lines.is_empty(): var resource_type = production_lines.keys().pick_random() - + var line = production_lines[resource_type] - + var current_workers = line[Production_Line.current_workers] - + if current_workers >= amount: line[Production_Line.current_workers] -= amount - + waiting_lines.push_back([resource_type, amount]) - + population_pool -= amount else: line[Production_Line.current_workers] = 0 - + waiting_lines.push_back([resource_type, current_workers]) - + population_pool -= current_workers - + if line[Production_Line.current_workers] == 0: production_lines.erase(resource_type) - + storage.update_global_production_rate(resource_type) - + if population_pool <= 0: break + func _on_TheTicker_tick(): for resource_type in production_lines: var line = production_lines[resource_type] - + line[Production_Line.current_ticks] += 1 - - if line[Production_Line.current_ticks] >= \ - Recipes.get_recipe_needed_ticks(resource_type): - + + if line[Production_Line.current_ticks] >= Recipes.get_recipe_needed_ticks(resource_type): line[Production_Line.current_ticks] = 0 - + storage.add_resource(resource_type, line[Production_Line.production_rate]) diff --git a/theLudovyc/TheMarket.gd b/theLudovyc/TheMarket.gd index 4d770803..0311ba23 100644 --- a/theLudovyc/TheMarket.gd +++ b/theLudovyc/TheMarket.gd @@ -2,90 +2,100 @@ extends Node @onready var the_storage = $"../TheStorage" @onready var the_bank = $"../TheBank" -@onready var event_bus:EventBus = $"../EventBus" +@onready var event_bus: EventBus = $"../EventBus" + class Order: var buy_amount := 0 var sell_amount := 0 + var orders = {} + func _ready(): event_bus.ask_create_new_order.connect(_on_ask_create_new_order) event_bus.ask_remove_order.connect(_on_ask_remove_order) event_bus.ask_update_order_buy.connect(_on_ask_update_order_buy) event_bus.ask_update_order_sell.connect(_on_ask_update_order_sell) -func get_resource_cost(resource_type:Resources.Types) -> int: + +func get_resource_cost(resource_type: Resources.Types) -> int: if not Resources.Levels.has(resource_type): # ERROR return 0 - - return (Resources.Levels[resource_type] + 1) -func get_production_rate_per_cycle(resource_type:Resources.Types) -> int: + return Resources.Levels[resource_type] + 1 + + +func get_production_rate_per_cycle(resource_type: Resources.Types) -> int: if not orders.has(resource_type): return 0 - + var order = orders[resource_type] - + return order.buy_amount - order.sell_amount -func _on_ask_create_new_order(resource_type:Resources.Types): + +func _on_ask_create_new_order(resource_type: Resources.Types): if orders.has(resource_type): # ERROR return - + orders[resource_type] = Order.new() - + if event_bus != null: event_bus.send_create_new_order.emit(resource_type) -func _on_ask_remove_order(resource_type:Resources.Types): + +func _on_ask_remove_order(resource_type: Resources.Types): if event_bus != null: event_bus.send_remove_order.emit(resource_type) - + if orders.erase(resource_type): the_storage.update_global_production_rate(resource_type) - + the_bank.recalculate_orders_cost() -func _on_ask_update_order_buy(resource_type:Resources.Types, buy_amount:int): + +func _on_ask_update_order_buy(resource_type: Resources.Types, buy_amount: int): if not orders.has(resource_type): # ERROR return - + if buy_amount < 0: # ERROR return - + orders[resource_type].buy_amount = buy_amount - + the_bank.recalculate_orders_cost() - + the_storage.update_global_production_rate(resource_type) - -func _on_ask_update_order_sell(resource_type:Resources.Types, sell_amount:int): + + +func _on_ask_update_order_sell(resource_type: Resources.Types, sell_amount: int): if not orders.has(resource_type): # ERROR return - + if sell_amount < 0: # ERROR return - + orders[resource_type].sell_amount = sell_amount - + the_bank.recalculate_orders_cost() - + the_storage.update_global_production_rate(resource_type) + func _on_TheTicker_cycle(): for order_key in orders: var order = orders[order_key] if the_bank.try_to_buy_resource(order_key, order.buy_amount): the_storage.add_resource(order_key, order.buy_amount) - + if the_storage.try_to_sell_resource(order_key, order.sell_amount): the_bank.conclude_sale(order_key, order.sell_amount) diff --git a/theLudovyc/TheStorage.gd b/theLudovyc/TheStorage.gd index d5624d67..c4845ebd 100644 --- a/theLudovyc/TheStorage.gd +++ b/theLudovyc/TheStorage.gd @@ -11,76 +11,83 @@ var storage = {} @onready var the_ticker := $"../TheTicker" -func add_resource(resource_type:Resources.Types, amount:int): + +func add_resource(resource_type: Resources.Types, amount: int): if sign(amount) < 0 and abs(amount) > storage[resource_type]: push_error(name, "Error: cannot consume " + str(amount) + " of " + str(resource_type)) - + storage[resource_type] = 0 else: if storage.has(resource_type): storage[resource_type] += amount else: storage[resource_type] = amount - + event_bus.resource_updated.emit(resource_type, storage[resource_type]) - + if storage[resource_type] == 0: storage.erase(resource_type) -func get_resource_amount(resource_type:Resources.Types): + +func get_resource_amount(resource_type: Resources.Types): if not storage.has(resource_type): return 0 - + return storage[resource_type] -func try_to_sell_resource(resource_type:Resources.Types, amount:int) -> bool: + +func try_to_sell_resource(resource_type: Resources.Types, amount: int) -> bool: if not storage.has(resource_type) or amount <= 0: return false - + if storage[resource_type] >= amount: storage[resource_type] -= amount - + event_bus.resource_updated.emit(resource_type, storage[resource_type]) - + return true - + return false -func update_global_production_rate(resource_type:Resources.Types): - var factory_per_cycle = \ - the_factory.get_production_rate_per_tick(resource_type) * \ - the_ticker.cycle_cooldown - - event_bus.resource_prodution_rate_updated.emit(resource_type, - factory_per_cycle + \ - the_market.get_production_rate_per_cycle(resource_type)) - -func has_resources_to_construct_building(building_id:Buildings.Ids) -> bool: + +func update_global_production_rate(resource_type: Resources.Types): + var factory_per_cycle = ( + the_factory.get_production_rate_per_tick(resource_type) * the_ticker.cycle_cooldown + ) + + event_bus.resource_prodution_rate_updated.emit( + resource_type, factory_per_cycle + the_market.get_production_rate_per_cycle(resource_type) + ) + + +func has_resources_to_construct_building(building_id: Buildings.Ids) -> bool: var building_cost = Buildings.get_building_cost(building_id) - + if building_cost.is_empty(): return true - + for cost in building_cost: if cost[1] > storage.get(cost[0], 0): return false - + return true - -func conclude_building_construction(building_id:Buildings.Ids): + + +func conclude_building_construction(building_id: Buildings.Ids): var building_cost = Buildings.get_building_cost(building_id) - + if building_cost.is_empty(): return - + for cost in building_cost: - add_resource(cost[0], - cost[1]) + add_resource(cost[0], -cost[1]) -func recover_building_construction(building_id:Buildings.Ids): + +func recover_building_construction(building_id: Buildings.Ids): var building_cost = Buildings.get_building_cost(building_id) - + if building_cost.is_empty(): return - + for cost in building_cost: add_resource(cost[0], cost[1]) diff --git a/theLudovyc/TheTicker.gd b/theLudovyc/TheTicker.gd index 922a121b..0cccf819 100644 --- a/theLudovyc/TheTicker.gd +++ b/theLudovyc/TheTicker.gd @@ -6,12 +6,13 @@ signal cycle var cycle_cooldown := 2 var current_ticks := 0 + func _on_timeout(): tick.emit() - + current_ticks += 1 - + if current_ticks >= cycle_cooldown: current_ticks = 0 - + cycle.emit()