diff --git a/CameraController.gd b/CameraController.gd new file mode 100644 index 0000000..a0f9377 --- /dev/null +++ b/CameraController.gd @@ -0,0 +1,12 @@ +extends Camera2D + +func _process(delta): + const speed = 300.0 + if Input.is_key_pressed(KEY_W): + position.y -= delta * speed + if Input.is_key_pressed(KEY_S): + position.y += delta * speed + if Input.is_key_pressed(KEY_A): + position.x -= delta * speed + if Input.is_key_pressed(KEY_D): + position.x += delta * speed diff --git a/CameraController.gd.uid b/CameraController.gd.uid new file mode 100644 index 0000000..d783238 --- /dev/null +++ b/CameraController.gd.uid @@ -0,0 +1 @@ +uid://d0vowgemo3buy diff --git a/ResourceScripts/BuildingData.gd b/ResourceScripts/BuildingData.gd index d1cd6d7..9cf0f87 100644 --- a/ResourceScripts/BuildingData.gd +++ b/ResourceScripts/BuildingData.gd @@ -9,9 +9,18 @@ enum RenderStyle { Circles } +enum Availability { + Starting, + Hidden, + Unlockable +} + @export_group("Basic") @export var tile_name: String +@export var availability: Availability = Availability.Hidden @export var area_type: GridInput.AreaType = GridInput.AreaType.Rectangle + +@export_group("Rendering") @export var style: RenderStyle = RenderStyle.RandomBuilding @export_color_no_alpha var color: Color diff --git a/ResourceScripts/ResearchData.gd b/ResourceScripts/ResearchData.gd new file mode 100644 index 0000000..af6f68b --- /dev/null +++ b/ResourceScripts/ResearchData.gd @@ -0,0 +1,7 @@ +extends Resource +class_name ResearchData + +@export var prerequisits: Array[ResearchData] = [] + +@export var cost_resource: ResourceController.ResourceType +@export var cost_amount: int = 0 diff --git a/ResourceScripts/ResearchData.gd.uid b/ResourceScripts/ResearchData.gd.uid new file mode 100644 index 0000000..bc316e2 --- /dev/null +++ b/ResourceScripts/ResearchData.gd.uid @@ -0,0 +1 @@ +uid://dc3sudtjnlpr1 diff --git a/Scripts/BuildMenu.gd b/Scripts/BuildMenu.gd index 8dcbdc6..e1824e7 100644 --- a/Scripts/BuildMenu.gd +++ b/Scripts/BuildMenu.gd @@ -5,6 +5,40 @@ class_name BuildMenu @export var grid_input: GridInput @export var grid: Grid +# at some point this the buildingdata stuff will need to be pulled somewhere else! + +var building_datas: Array[BuildingData] = [] + +func load_building_datas(): + var unexplored_dirs = [ "res://Tiles" ] + var discovered_data = [] + + while unexplored_dirs.size() != 0: + var root_path = unexplored_dirs.pop_front() + + var files = DirAccess.get_files_at(root_path) + for file in files: + var new_path = root_path + "/" + file + discovered_data.append(new_path) + #print(new_path) + #print(discovered_data) + + var dirs = DirAccess.get_directories_at(root_path) + for dir in dirs: unexplored_dirs.append(root_path + "/" + dir) + + for child in get_children(): child.queue_free() + + for res_path in discovered_data: + var resource: BuildingData = load(res_path) + if resource.availability != BuildingData.Availability.Starting: + continue + var new_button = BuildButton.new() + new_button.building = resource + add_child(new_button) + +func _ready(): + load_building_datas() + func build_button_pressed(button: BuildButton): grid_input.request_area( button.building, @@ -20,7 +54,6 @@ func tile_is_valid_at_location(building: BuildingData, tile_pos: Vector2i) -> bo if !requirement.is_satisfied_at_position(self.grid, tile_pos): return false return true - func request_confirmed(building: BuildingData, area: Rect2i) -> void: for x in range(area.position.x, area.position.x + area.size.x): @@ -29,6 +62,5 @@ func request_confirmed(building: BuildingData, area: Rect2i) -> void: var new_tile = Building.new(Vector2i(x, y), Vector2i.ONE, building) grid.add_child(new_tile) - func request_cancelled(building: BuildingData) -> void: pass diff --git a/Scripts/Building.gd b/Scripts/Building.gd index 38d30cf..065ac4a 100644 --- a/Scripts/Building.gd +++ b/Scripts/Building.gd @@ -11,6 +11,8 @@ var triangle_points = PackedVector2Array([ var history: Array[BuildingData] = [] var data: BuildingData = null +var upgrade_timer: int = 0 +const max_upgrade_timer: int = 10 func attempt_upgrade(new_data: BuildingData) -> bool: var old_data = data diff --git a/Scripts/CursorPool.gd b/Scripts/CursorPool.gd index 5831f68..69a5fea 100644 --- a/Scripts/CursorPool.gd +++ b/Scripts/CursorPool.gd @@ -19,6 +19,8 @@ class Cursor: var cursors: Array[Cursor] = [] var current_cursor: Cursor = null +var stored_color: Color = Color.WHITE + func new_cursor(color: Color) -> Cursor: var cursor = Cursor.new() cursors.append(cursor) @@ -35,16 +37,35 @@ func new_cursor(color: Color) -> Cursor: return cursor +func change_color(color: Color): + if current_cursor == null: return + if color == current_cursor.color: return + var box = current_cursor.box + var opacity = current_cursor.opacity + var animation_state = current_cursor.animation + var dbox = current_cursor.desired_box + var dopacity = current_cursor.desired_opacity + explode() + new_cursor(color) + current_cursor.box = box + current_cursor.desired_box = dbox + current_cursor.opacity = opacity + current_cursor.desired_opacity = dopacity + current_cursor.animation = animation_state + # cursor removal type beats. func fade_out() -> void: if current_cursor == null: return current_cursor.animation = AnimationState.Fading current_cursor.desired_opacity = 0.0 + current_cursor = null + func explode() -> void: if current_cursor == null: return current_cursor.animation = AnimationState.Exploding current_cursor.desired_box = current_cursor.desired_box.grow(10) current_cursor.desired_opacity = 0.0 + current_cursor = null # override / util func _process(delta) -> void: diff --git a/Scripts/DebugMenu.gd b/Scripts/DebugMenu.gd index 5b88c48..fe9348d 100644 --- a/Scripts/DebugMenu.gd +++ b/Scripts/DebugMenu.gd @@ -4,14 +4,18 @@ extends VBoxContainer @export var overlay_enabled_button: Button @export var overlay_selection_button: OptionButton @export var overlay_display_values: Button +@export var reload_building_data_button: Button +@export var build_menu: BuildMenu func _ready(): + build_menu = Util.find(BuildMenu) var grid_fields = Grid.Field.keys() for idx in range(grid_fields.size()): overlay_selection_button.add_item(grid_fields[idx], idx) overlay_enabled_button.toggled.connect(update_overlay) overlay_display_values.toggled.connect(update_overlay) overlay_selection_button.item_selected.connect(update_overlay) + reload_building_data_button.pressed.connect(build_menu.load_building_datas) func update_overlay(data): grid.debug_overlay_display_values = overlay_display_values.button_pressed diff --git a/Scripts/DeconstructionController.gd b/Scripts/DeconstructionController.gd new file mode 100644 index 0000000..11b321e --- /dev/null +++ b/Scripts/DeconstructionController.gd @@ -0,0 +1,34 @@ +extends Node2D + +@export var grid_input: GridInput +var input_enabled: bool = false + +func _input(event): + if event is InputEventKey and event.pressed: + if event.keycode == KEY_B: + toggle() + +func toggle(): + input_enabled = !input_enabled + if input_enabled: enable_decon() + else: disable_decon() + +func enable_decon(): + grid_input.request_area( + self, + _confirm_area, + _cancel_area, + GridInput.Style.Delete, + GridInput.AreaType.Rectangle, + false + ) + +func disable_decon(): + grid_input.clear_request() + +func _confirm_area(context, area: Rect2i): + pass + +func _cancel_area(context): + print("decon cancelled") + input_enabled = false diff --git a/Scripts/DeconstructionController.gd.uid b/Scripts/DeconstructionController.gd.uid new file mode 100644 index 0000000..b42d74e --- /dev/null +++ b/Scripts/DeconstructionController.gd.uid @@ -0,0 +1 @@ +uid://r4k5yal152we diff --git a/Scripts/GridInput.gd b/Scripts/GridInput.gd index 55a8c4e..fc365b0 100644 --- a/Scripts/GridInput.gd +++ b/Scripts/GridInput.gd @@ -2,7 +2,7 @@ extends Node2D class_name GridInput @onready var grid: Grid = $/root/Root/Grid -var highlight_color: Color = Color(0.075, 0.536, 0.75, 0.38) +var highlight_color: Color = Color(1.0, 1.0, 1.0, 0.38) var build_color: Color = Color(0.087, 0.62, 0.087, 0.514) var deletion_color: Color = Color(0.76, 0.237, 0.106, 0.4) var current_color = highlight_color @@ -58,10 +58,11 @@ func _left_click(pos: Vector2): _grid_clicked(tile_pos) func _right_click(pos: Vector2): _cancel_operation() - cursor_pool.explode() - if !mouse_in_grid: return - cursor_pool.new_cursor(current_color) - _update_cursor() + #cursor_pool.explode() + #if !mouse_in_grid: return + #cursor_pool.new_cursor(current_color) + #_update_cursor() + var mouse_in_grid: bool = false # TODO init this correctly lol func __mouse_may_have_left_or_entered_grid(pos: Vector2): @@ -189,11 +190,15 @@ func clear_request(): _reset() func request_area(ctx, confirm, cancel, style: Style, area_type: AreaType, one_shot: bool): + if request != null: + clear_request() + request = Request.new() request.confirmed = confirm request.cancelled = cancel request.context = ctx current_marquee_type = area_type + _set_style(style) func _reset(): @@ -205,3 +210,4 @@ func _set_style(style: Style): Style.Highlight: current_color = highlight_color Style.Build: current_color = build_color Style.Delete: current_color = deletion_color + cursor_pool.change_color(current_color) diff --git a/Scripts/ResearchController.gd b/Scripts/ResearchController.gd new file mode 100644 index 0000000..e8f5e49 --- /dev/null +++ b/Scripts/ResearchController.gd @@ -0,0 +1,12 @@ +extends Node + +var research_data: Array[ResearchData] = [] + +func _ready(): + reload() + +func reload(): + research_data = [] + var unexplored = [] + var root = load("res://Research/") + #for diff --git a/Scripts/ResearchController.gd.uid b/Scripts/ResearchController.gd.uid new file mode 100644 index 0000000..ac6307c --- /dev/null +++ b/Scripts/ResearchController.gd.uid @@ -0,0 +1 @@ +uid://b6p6apq8obptm diff --git a/Tiles/Farm/Reservation.tres b/Tiles/Farm/Reservation.tres index f896fef..179334e 100644 --- a/Tiles/Farm/Reservation.tres +++ b/Tiles/Farm/Reservation.tres @@ -9,6 +9,7 @@ [resource] script = ExtResource("4_rxh8u") tile_name = "Farmland" +availability = 0 style = 2 color = Color(0.182, 0.7, 0.29423332, 1) upgrade_paths = Array[ExtResource("4_rxh8u")]([ExtResource("5_kjhvl")]) diff --git a/Tiles/Housing/Housing.tres b/Tiles/Housing/Housing.tres index f0eaff1..ba81575 100644 --- a/Tiles/Housing/Housing.tres +++ b/Tiles/Housing/Housing.tres @@ -10,6 +10,7 @@ [resource] script = ExtResource("4_y6hfj") tile_name = "Housing" +availability = 2 style = 2 color = Color(0.93333334, 0.39215687, 0.39215687, 1) upgrade_paths = Array[ExtResource("4_y6hfj")]([ExtResource("4_vifl3"), ExtResource("6_ad1a7")]) diff --git a/Tiles/Industry/Gathering Camp.tres b/Tiles/Industry/Gathering Camp.tres index fa50b50..f0c9f42 100644 --- a/Tiles/Industry/Gathering Camp.tres +++ b/Tiles/Industry/Gathering Camp.tres @@ -10,6 +10,7 @@ [resource] script = ExtResource("4_ex0ko") tile_name = "Gathering Camp" +availability = 0 style = 2 color = Color(0.65, 0.57135, 0.43549997, 1) upgrade_paths = Array[ExtResource("4_ex0ko")]([ExtResource("6_lmdb6"), ExtResource("5_adjmk")]) diff --git a/World.tscn b/World.tscn index e2cea50..c0782b0 100644 --- a/World.tscn +++ b/World.tscn @@ -1,10 +1,13 @@ -[gd_scene load_steps=18 format=3 uid="uid://co6md8v2b8hhu"] +[gd_scene load_steps=21 format=3 uid="uid://co6md8v2b8hhu"] [ext_resource type="Script" uid="uid://8lkq20gwkrvx" path="res://Scripts/Grid.gd" id="1_2s04l"] [ext_resource type="Script" uid="uid://cuqcfju7y8ply" path="res://Scripts/SelectionManager.gd" id="1_anesy"] +[ext_resource type="Script" uid="uid://b6p6apq8obptm" path="res://Scripts/ResearchController.gd" id="1_sjtuv"] +[ext_resource type="Script" uid="uid://d0vowgemo3buy" path="res://CameraController.gd" id="2_cvq6i"] [ext_resource type="Script" uid="uid://xe60g0el2j5x" path="res://Scripts/GridInput.gd" id="3_62nr3"] [ext_resource type="Script" uid="uid://du3m15i8ahlu5" path="res://Scripts/CursorPool.gd" id="3_fvag4"] [ext_resource type="Script" uid="uid://j6fc2qc5t3qa" path="res://Scripts/FPSCounter.gd" id="5_eu7l1"] +[ext_resource type="Script" uid="uid://r4k5yal152we" path="res://Scripts/DeconstructionController.gd" id="6_6tx0c"] [ext_resource type="Theme" uid="uid://dks3mt6h14i2s" path="res://Gradients/DefaultTheme.tres" id="6_bah7m"] [ext_resource type="Script" uid="uid://d1lhn37ijatdp" path="res://Scripts/BuildMenu.gd" id="6_wygdx"] [ext_resource type="Script" uid="uid://p8y4cfg2aonj" path="res://Scripts/BuildButton.gd" id="7_bah7m"] @@ -20,7 +23,11 @@ [node name="Root" type="Node2D"] +[node name="ResearchController" type="Node" parent="."] +script = ExtResource("1_sjtuv") + [node name="Camera2D" type="Camera2D" parent="."] +script = ExtResource("2_cvq6i") [node name="Grid" type="Node2D" parent="."] script = ExtResource("1_2s04l") @@ -29,7 +36,6 @@ cell_size = 48 grid_color = Color(0.6627451, 0.7764706, 0.5647059, 1) line_color = Color(1, 1, 1, 0) debug_overlay_enabled = false -debug_overlay_display_values = null [node name="GridInput" type="Node2D" parent="." node_paths=PackedStringArray("selection_manager")] script = ExtResource("3_62nr3") @@ -38,6 +44,10 @@ selection_manager = NodePath("../SelectionManager") [node name="CursorPool" type="Node2D" parent="GridInput"] script = ExtResource("3_fvag4") +[node name="Deconstruction Controller" type="Node2D" parent="." node_paths=PackedStringArray("grid_input")] +script = ExtResource("6_6tx0c") +grid_input = NodePath("../GridInput") + [node name="SelectionManager" type="Node2D" parent="."] script = ExtResource("1_anesy") @@ -64,17 +74,16 @@ layout_mode = 2 metadata/_tab_index = 0 [node name="VBox" type="VBoxContainer" parent="CanvasLayer/Left Panel/TabContainer/Build" node_paths=PackedStringArray("grid_input", "grid")] -layout_mode = 0 -offset_right = 280.0 -offset_bottom = 826.0 +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 script = ExtResource("6_wygdx") grid_input = NodePath("../../../../../GridInput") grid = NodePath("../../../../../Grid") -[node name="Label" type="Label" parent="CanvasLayer/Left Panel/TabContainer/Build/VBox"] -layout_mode = 2 -text = "Zoning" - [node name="Build Road" type="Button" parent="CanvasLayer/Left Panel/TabContainer/Build/VBox"] layout_mode = 2 text = "Road" @@ -103,7 +112,7 @@ building = ExtResource("11_ee7l0") layout_mode = 2 metadata/_tab_index = 1 -[node name="Overlay Controller" type="VBoxContainer" parent="CanvasLayer/Left Panel/TabContainer/Debug" node_paths=PackedStringArray("grid", "overlay_enabled_button", "overlay_selection_button", "overlay_display_values")] +[node name="Overlay Controller" type="VBoxContainer" parent="CanvasLayer/Left Panel/TabContainer/Debug" node_paths=PackedStringArray("grid", "overlay_enabled_button", "overlay_selection_button", "overlay_display_values", "reload_building_data_button")] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 @@ -115,6 +124,7 @@ grid = NodePath("../../../../../Grid") overlay_enabled_button = NodePath("Enable") overlay_selection_button = NodePath("Select Field") overlay_display_values = NodePath("Display Values") +reload_building_data_button = NodePath("Reload Building Data") [node name="Enable" type="CheckButton" parent="CanvasLayer/Left Panel/TabContainer/Debug/Overlay Controller"] layout_mode = 2 @@ -128,6 +138,13 @@ text = "Display Values" layout_mode = 2 size_flags_horizontal = 3 +[node name="HSeparator" type="HSeparator" parent="CanvasLayer/Left Panel/TabContainer/Debug/Overlay Controller"] +layout_mode = 2 + +[node name="Reload Building Data" type="Button" parent="CanvasLayer/Left Panel/TabContainer/Debug/Overlay Controller"] +layout_mode = 2 +text = "Reload Building Data" + [node name="Selection" type="TabBar" parent="CanvasLayer/Left Panel/TabContainer"] visible = false layout_mode = 2 @@ -158,7 +175,7 @@ anchors_preset = 11 anchor_left = 1.0 anchor_right = 1.0 anchor_bottom = 1.0 -offset_left = -273.0 +offset_left = -300.0 grow_horizontal = 0 grow_vertical = 2 theme = ExtResource("6_bah7m")