diff --git a/generic/constructibles/conveyor.tres b/generic/constructibles/conveyor.tres index 04d8ee9..cf8b491 100644 --- a/generic/constructibles/conveyor.tres +++ b/generic/constructibles/conveyor.tres @@ -1,7 +1,7 @@ -[gd_resource type="Resource" script_class="Prototype" load_steps=5 format=3 uid="uid://dj524jjal1f0n"] +[gd_resource type="Resource" script_class="Constructible" load_steps=5 format=3 uid="uid://dj524jjal1f0n"] -[ext_resource type="Script" uid="uid://c80sp6f77l5ha" path="res://scripts/prototype.gd" id="1_53h7j"] -[ext_resource type="Texture2D" uid="uid://dinyjq8853usn" path="res://sprites/atlasses/Popekko.png" id="1_x27pp"] +[ext_resource type="Script" uid="uid://c80sp6f77l5ha" path="res://scripts/constructible.gd" id="1_53h7j"] +[ext_resource type="Texture2D" uid="uid://cbtre16ilxte0" path="res://sprites/atlasses/Popekko.png" id="1_x27pp"] [ext_resource type="PackedScene" uid="uid://b0h8dd82b3ox5" path="res://scenes/conveyor.tscn" id="2_hinjf"] [sub_resource type="AtlasTexture" id="AtlasTexture_uvy8r"] diff --git a/generic/constructibles/dbg_assembler.tres b/generic/constructibles/dbg_assembler.tres deleted file mode 100644 index 857a443..0000000 --- a/generic/constructibles/dbg_assembler.tres +++ /dev/null @@ -1,15 +0,0 @@ -[gd_resource type="Resource" script_class="Constructible" load_steps=5 format=3 uid="uid://yn1iesx30nfu"] - -[ext_resource type="Script" uid="uid://c80sp6f77l5ha" path="res://scripts/prototype.gd" id="1_mqcr0"] -[ext_resource type="Texture2D" uid="uid://dinyjq8853usn" path="res://sprites/atlasses/Popekko.png" id="1_sh8t1"] -[ext_resource type="PackedScene" uid="uid://dfatkxv6n55dw" path="res://scenes/debug_assembler.tscn" id="2_kf3x0"] - -[sub_resource type="AtlasTexture" id="AtlasTexture_kf3x0"] -atlas = ExtResource("1_sh8t1") -region = Rect2(32, 0, 32, 32) - -[resource] -script = ExtResource("1_mqcr0") -scene = ExtResource("2_kf3x0") -preview = SubResource("AtlasTexture_kf3x0") -metadata/_custom_type_script = "uid://c80sp6f77l5ha" diff --git a/project.godot b/project.godot index 352b36b..b6648e2 100644 --- a/project.godot +++ b/project.godot @@ -18,8 +18,8 @@ config/icon="res://icon.svg" [autoload] GuiEventBus="*res://scripts/gui/gui_event_bus.gd" -RuntimePlayerData="*res://scripts/autoloads/runtime_player_data.gd" -Registry="*res://scripts/autoloads/registry.gd" +RuntimePlayerData="*res://scripts/runtime_player_data.gd" +Registry="*res://scripts/registry.gd" [display] diff --git a/scenes/2d_world.tscn b/scenes/2d_world.tscn index 4e0d946..5e93434 100644 --- a/scenes/2d_world.tscn +++ b/scenes/2d_world.tscn @@ -1,11 +1,10 @@ -[gd_scene load_steps=10 format=3 uid="uid://u7thalwj5742"] +[gd_scene load_steps=9 format=3 uid="uid://u7thalwj5742"] [ext_resource type="PackedScene" uid="uid://b7du4vul4bmpq" path="res://scenes/player_platform.tscn" id="1_4ia00"] [ext_resource type="Script" uid="uid://db37xmo8ygwhg" path="res://scripts/gui/construction_button.gd" id="2_27lod"] [ext_resource type="Resource" uid="uid://dj524jjal1f0n" path="res://generic/constructibles/conveyor.tres" id="3_2crwe"] -[ext_resource type="Script" uid="uid://b4nkk0ndqcto" path="res://scripts/placement_manager.gd" id="4_i7yte"] +[ext_resource type="Script" uid="uid://b4nkk0ndqcto" path="res://scripts/construction_placer.gd" id="4_i7yte"] [ext_resource type="PackedScene" uid="uid://bac552xgua68e" path="res://scenes/other_platform.tscn" id="5_mnxrb"] -[ext_resource type="Resource" uid="uid://yn1iesx30nfu" path="res://generic/constructibles/dbg_assembler.tres" id="5_ymyc2"] [sub_resource type="Animation" id="Animation_bq5r8"] length = 0.001 @@ -82,24 +81,6 @@ expand_icon = true script = ExtResource("2_27lod") constructible = ExtResource("3_2crwe") -[node name="AssemblerButton" type="Button" parent="GUI/Panel"] -layout_mode = 1 -anchors_preset = -1 -anchor_left = 0.008 -anchor_top = 0.086 -anchor_right = 0.1 -anchor_bottom = 0.88600004 -offset_left = 50.904 -offset_top = -0.01999998 -offset_right = 50.8 -offset_bottom = -0.020004272 -size_flags_horizontal = 3 -theme_type_variation = &"CRT" -icon_alignment = 1 -expand_icon = true -script = ExtResource("2_27lod") -constructible = ExtResource("5_ymyc2") - [node name="Placer" type="Node2D" parent="."] script = ExtResource("4_i7yte") diff --git a/scenes/conveyor.tscn b/scenes/conveyor.tscn index 4f9ddf3..dbf0273 100644 --- a/scenes/conveyor.tscn +++ b/scenes/conveyor.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=4 format=3 uid="uid://b0h8dd82b3ox5"] -[ext_resource type="Texture2D" uid="uid://dinyjq8853usn" path="res://sprites/atlasses/Popekko.png" id="1_kqxj7"] -[ext_resource type="Script" uid="uid://bbd7o2st8kmgl" path="res://scripts/structure.gd" id="1_y326v"] +[ext_resource type="Texture2D" uid="uid://cbtre16ilxte0" path="res://sprites/atlasses/Popekko.png" id="1_kqxj7"] +[ext_resource type="Script" uid="uid://bbd7o2st8kmgl" path="res://scripts/construction.gd" id="1_y326v"] [sub_resource type="AtlasTexture" id="AtlasTexture_uvy8r"] atlas = ExtResource("1_kqxj7") diff --git a/scenes/debug_assembler.tscn b/scenes/debug_assembler.tscn deleted file mode 100644 index 1b8d172..0000000 --- a/scenes/debug_assembler.tscn +++ /dev/null @@ -1,16 +0,0 @@ -[gd_scene load_steps=4 format=3 uid="uid://dfatkxv6n55dw"] - -[ext_resource type="Script" uid="uid://bbd7o2st8kmgl" path="res://scripts/structure.gd" id="1_k5y3y"] -[ext_resource type="Texture2D" uid="uid://dinyjq8853usn" path="res://sprites/atlasses/Popekko.png" id="2_4befw"] - -[sub_resource type="AtlasTexture" id="AtlasTexture_xh4eg"] -atlas = ExtResource("2_4befw") -region = Rect2(32, 0, 32, 32) - -[node name="DebugAssembler" type="Node2D"] -script = ExtResource("1_k5y3y") -dimensions = Rect2i(0, 0, 2, 2) - -[node name="Sprite2D" type="Sprite2D" parent="."] -texture = SubResource("AtlasTexture_xh4eg") -offset = Vector2(8, 8) diff --git a/scenes/other_platform.tscn b/scenes/other_platform.tscn index 47d0b84..125ccab 100644 --- a/scenes/other_platform.tscn +++ b/scenes/other_platform.tscn @@ -1,20 +1,13 @@ -[gd_scene load_steps=4 format=4 uid="uid://bac552xgua68e"] +[gd_scene load_steps=3 format=4 uid="uid://bac552xgua68e"] [ext_resource type="TileSet" uid="uid://bv75bu0af04vs" path="res://generic/platform.tres" id="1_fs1oy"] -[ext_resource type="Script" uid="uid://lw1ya3iu14uf" path="res://scripts/placement_zone.gd" id="2_bwire"] -[ext_resource type="Script" uid="uid://x5edy155eg0s" path="res://scripts/grid_controller.gd" id="3_qaudu"] +[ext_resource type="Script" uid="uid://lw1ya3iu14uf" path="res://scripts/build_zone.gd" id="2_bwire"] [node name="OtherPlatform" type="TileMapLayer"] tile_map_data = PackedByteArray("AAAAAAAAAAAAAAAAAAAAAAEAAAAAAAEAAAAAAAIAAAAAAAEAAAAAAAMAAAAAAAEAAAAAAAQAAAAAAAEAAAABAAAAAAAAAAEAAAABAAEAAAAAAAEAAAABAAIAAAAAAAEAAAABAAMAAAAAAAAAAAABAAQAAAAAAAEAAAACAAAAAAAAAAAAAAACAAEAAAAAAAEAAAACAAIAAAAAAAEAAAACAAMAAAAAAAAAAAACAAQAAAAAAAAAAAD/////AAACAAEAAAD//wAAAAAEAAIAAAD//wEAAAAEAAIAAAD//wIAAAAEAAIAAAD//wMAAAAEAAIAAAD//wQAAAAEAAIAAAAAAP//AAABAAIAAAABAP//AAABAAIAAAACAP//AAABAAIAAAADAP//AAADAAEAAAD//wUAAAAEAAEAAAADAAUAAAAFAAEAAAAAAAUAAAAGAAEAAAABAAUAAAAGAAEAAAACAAUAAAAGAAEAAAADAAAAAAAFAAIAAAADAAEAAAAFAAIAAAADAAIAAAAFAAIAAAADAAMAAAAFAAIAAAADAAQAAAAFAAIAAAA=") tile_set = ExtResource("1_fs1oy") -[node name="BuildZone" type="Marker2D" parent="." node_paths=PackedStringArray("grid_controller")] +[node name="BuildZone" type="Marker2D" parent="."] script = ExtResource("2_bwire") building_rect = Rect2(0, 0, 48, 80) -grid_controller = NodePath("../EntityHolder") metadata/_custom_type_script = "uid://lw1ya3iu14uf" - -[node name="EntityHolder" type="Node2D" parent="." node_paths=PackedStringArray("building_zone")] -script = ExtResource("3_qaudu") -building_zone = NodePath("../BuildZone") -metadata/_custom_type_script = "uid://x5edy155eg0s" diff --git a/scenes/player_platform.tscn b/scenes/player_platform.tscn index ca73456..c23ecc3 100644 --- a/scenes/player_platform.tscn +++ b/scenes/player_platform.tscn @@ -1,8 +1,8 @@ [gd_scene load_steps=4 format=4 uid="uid://b7du4vul4bmpq"] [ext_resource type="TileSet" uid="uid://bv75bu0af04vs" path="res://generic/platform.tres" id="1_khkq2"] -[ext_resource type="Script" uid="uid://lw1ya3iu14uf" path="res://scripts/placement_zone.gd" id="2_wpmwa"] -[ext_resource type="Script" uid="uid://x5edy155eg0s" path="res://scripts/grid_controller.gd" id="3_6hjoe"] +[ext_resource type="Script" uid="uid://lw1ya3iu14uf" path="res://scripts/build_zone.gd" id="2_wpmwa"] +[ext_resource type="Script" uid="uid://x5edy155eg0s" path="res://scripts/entity_holder.gd" id="3_6hjoe"] [node name="PlayerPlatform" type="Node2D"] @@ -10,10 +10,9 @@ tile_map_data = PackedByteArray("AAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAACAAAAAAAAAAEAAAADAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAGAAAAAAAAAAEAAAAHAAAAAAAAAAAAAAAIAAAAAAAAAAEAAAAJAAAAAAAAAAEAAAAKAAAAAAAAAAEAAAALAAAAAAAAAAAAAAAMAAAAAAAAAAEAAAANAAAAAAAAAAEAAAAOAAAAAAAAAAEAAAAPAAAAAAAAAAAAAAAQAAAAAAAAAAEAAAAQAAEAAAAAAAAAAAAPAAEAAAAAAAAAAAAOAAEAAAAAAAEAAAANAAEAAAAAAAAAAAAMAAEAAAAAAAAAAAALAAEAAAAAAAEAA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AAAAAIAAAAEAP//AAAAAAIAAAAFAP//AAAAAAIAAAAGAP//AAAAAAIAAAAHAP//AAAAAAIAAAAIAP//AAAAAAIAAAAJAP//AAAAAAIAAAAKAP//AAAAAAIAAAALAP//AAAAAAIAAAAMAP//AAAAAAIAAAANAP//AAAAAAIAAAAOAP//AAAAAAIAAAAPAP//AAAAAAIAAAAQAP//AAAAAAIAAAD/////AAACAAIAAAARAP//AAADAAIAAAD//wgAAAADAAAAAAARAAgAAAAEAAAAAAAQAAgAAAACAAAAAAAPAAgAAAACAAAAAAAOAAgAAAACAAAAAAANAAgAAAACAAAAAAAMAAgAAAACAAAAAAALAAgAAAACAAAAAAAKAAgAAAACAAAAAAAJAAgAAAACAAAAAAAIAAgAAAACAAAAAAAHAAgAAAACAAAAAAAGAAgAAAACAAAAAAAFAAgAAAACAAAAAAAEAAgAAAACAAAAAAADAAgAAAACAAAAAAACAAgAAAACAAAAAAABAAgAAAACAAAAAAAAAAgAAAACAAAAAAA=") tile_set = ExtResource("1_khkq2") -[node name="BuildRect" type="Marker2D" parent="." node_paths=PackedStringArray("grid_controller")] +[node name="BuildRect" type="Marker2D" parent="."] script = ExtResource("2_wpmwa") building_rect = Rect2(0, 0, 272, 128) -grid_controller = NodePath("../EntityHolder") [node name="EntityHolder" type="Node2D" parent="." node_paths=PackedStringArray("building_zone")] script = ExtResource("3_6hjoe") diff --git a/scripts/autoloads/registry.gd b/scripts/autoloads/registry.gd deleted file mode 100644 index 76dbf46..0000000 --- a/scripts/autoloads/registry.gd +++ /dev/null @@ -1,2 +0,0 @@ -## Global class for runtime -extends Node diff --git a/scripts/placement_zone.gd b/scripts/build_zone.gd similarity index 72% rename from scripts/placement_zone.gd rename to scripts/build_zone.gd index 84d1efa..23a16f8 100644 --- a/scripts/placement_zone.gd +++ b/scripts/build_zone.gd @@ -4,7 +4,9 @@ ## Class that helps to manage construction sites extends Marker2D -class_name PlacementZone +class_name BuildZone + +const GRID_SIZE : Vector2 = Vector2(16,16) ## Rect that used for bounds check and conversions @export var building_rect : Rect2: @@ -15,11 +17,9 @@ class_name PlacementZone get: return building_rect -@export var grid_controller : GridController - func _ready() -> void: if not Engine.is_editor_hint(): - RuntimePlayerData.build_zones.append(self) + Registry.build_zones.append(self) func _draw() -> void: if Engine.is_editor_hint() and EditorInterface.get_inspector().get_edited_object() == self: @@ -37,7 +37,7 @@ func is_global_point_in_zone(point: Vector2) -> bool: func indexify_point(point : Vector2) -> int: if is_point_in_zone(point) == false: return -1 - return int(point.x) / int(Globals.GRID_SIZE.x) + int(building_rect.size.x/Globals.GRID_SIZE.x)*(int(point.y) / int(Globals.GRID_SIZE.y)) + return int(point.x) / int(GRID_SIZE.x) + int(building_rect.size.x/GRID_SIZE.x)*(int(point.y) / int(GRID_SIZE.y)) ## Returns index of point (global coordinates) to be used in array func indexify_global_point(point : Vector2) -> int: @@ -45,7 +45,7 @@ func indexify_global_point(point : Vector2) -> int: ## Inverses indexification of point, returning snapped position func inverse_index(index: int) -> Vector2: - return to_global(Vector2(index%int(building_rect.size.x/Globals.GRID_SIZE.x)*Globals.GRID_SIZE.x,index / int(building_rect.size.x/Globals.GRID_SIZE.x) * Globals.GRID_SIZE.y)) + return to_global(Vector2(index%int(building_rect.size.x/GRID_SIZE.x)*GRID_SIZE.x,index / int(building_rect.size.x/GRID_SIZE.x) * GRID_SIZE.y)) ## Returns snapped position of point (global coordinates). ## Equivalent of [code] @@ -54,8 +54,8 @@ func inverse_index(index: int) -> Vector2: func get_placement_position(point : Vector2) -> Vector2: if is_global_point_in_zone(point) == false: return Vector2.ZERO - return to_global((to_local(point) / Globals.GRID_SIZE).floor()*Globals.GRID_SIZE + Globals.GRID_SIZE/2.0) + return to_global((to_local(point) / GRID_SIZE).floor()*GRID_SIZE + GRID_SIZE/2.0) ## Returns capacity of building zone to be used in the array func get_capacity() -> int: - return int(building_rect.size.x/Globals.GRID_SIZE.x)*int(building_rect.size.y/Globals.GRID_SIZE.y) + return int(building_rect.size.x/GRID_SIZE.x)*int(building_rect.size.y/GRID_SIZE.y) diff --git a/scripts/placement_zone.gd.uid b/scripts/build_zone.gd.uid similarity index 100% rename from scripts/placement_zone.gd.uid rename to scripts/build_zone.gd.uid diff --git a/scripts/constructible.gd b/scripts/constructible.gd new file mode 100644 index 0000000..5fbd326 --- /dev/null +++ b/scripts/constructible.gd @@ -0,0 +1,6 @@ +extends Resource + +class_name Constructible + +@export var scene : PackedScene +@export var preview : Texture2D diff --git a/scripts/prototype.gd.uid b/scripts/constructible.gd.uid similarity index 100% rename from scripts/prototype.gd.uid rename to scripts/constructible.gd.uid diff --git a/scripts/construction.gd b/scripts/construction.gd new file mode 100644 index 0000000..7d86f32 --- /dev/null +++ b/scripts/construction.gd @@ -0,0 +1,6 @@ +extends Node2D + +class_name Construction + +func get_relative(dv : Vector2) -> Construction: + return get_parent().get_at(global_position+dv) diff --git a/scripts/structure.gd.uid b/scripts/construction.gd.uid similarity index 100% rename from scripts/structure.gd.uid rename to scripts/construction.gd.uid diff --git a/scripts/placement_manager.gd b/scripts/construction_placer.gd similarity index 57% rename from scripts/placement_manager.gd rename to scripts/construction_placer.gd index d58e676..bbbdb82 100644 --- a/scripts/placement_manager.gd +++ b/scripts/construction_placer.gd @@ -1,7 +1,6 @@ extends Node2D -## Currently held structure -var held_construction : Structure +var held_construction : Construction func _ready() -> void: GuiEventBus.construction_selected.connect(on_construction_selected) @@ -14,13 +13,13 @@ func _input(event: InputEvent) -> void: if zone == null: held_construction.queue_free() else: - if held_construction.try_place(zone): + if zone.get_parent().get_node("EntityHolder").add_construction(held_construction): held_construction = null if event.is_action_pressed("plc_cancel"): held_construction.queue_free() -func on_construction_selected(constructible : Prototype): +func on_construction_selected(constructible : Constructible): if held_construction: held_construction.queue_free() held_construction = constructible.scene.instantiate() @@ -28,17 +27,16 @@ func on_construction_selected(constructible : Prototype): func _process(_delta: float) -> void: - if held_construction == null: - return - var mouse_pos = get_global_mouse_position() - var zone = try_get_zone(mouse_pos) - if zone and held_construction.can_be_placed(zone): - global_position = zone.get_placement_position(mouse_pos) - else: - global_position = mouse_pos + if held_construction != null: + var mouse_pos = get_global_mouse_position() + var zone = try_get_zone(mouse_pos) + if zone: + global_position = zone.get_placement_position(mouse_pos) + else: + global_position = mouse_pos -func try_get_zone(point : Vector2) -> PlacementZone: - for zone in RuntimePlayerData.build_zones: +func try_get_zone(point : Vector2) -> BuildZone: + for zone in Registry.build_zones: if zone.is_global_point_in_zone(point): return zone return null diff --git a/scripts/placement_manager.gd.uid b/scripts/construction_placer.gd.uid similarity index 100% rename from scripts/placement_manager.gd.uid rename to scripts/construction_placer.gd.uid diff --git a/scripts/entity_holder.gd b/scripts/entity_holder.gd new file mode 100644 index 0000000..6b6b129 --- /dev/null +++ b/scripts/entity_holder.gd @@ -0,0 +1,22 @@ +extends Node2D + +class_name EntityHolder + +const GRID_SIZE : Vector2 = Vector2(16,16) + +@export var building_zone : BuildZone +var constructions : Array[Construction] + +func _ready() -> void: + constructions.resize(building_zone.get_capacity()) + +func add_construction(construction : Construction) -> bool: + if constructions[building_zone.indexify_global_point(construction.global_position)]: + return false + construction.reparent(self) + construction.global_position = building_zone.get_placement_position(construction.global_position) + constructions[building_zone.indexify_global_point(construction.global_position)] = construction + return true + +func get_at(point : Vector2): + return constructions[building_zone.indexify_global_point(point)] diff --git a/scripts/grid_controller.gd.uid b/scripts/entity_holder.gd.uid similarity index 100% rename from scripts/grid_controller.gd.uid rename to scripts/entity_holder.gd.uid diff --git a/scripts/globals.gd b/scripts/globals.gd deleted file mode 100644 index d7ff107..0000000 --- a/scripts/globals.gd +++ /dev/null @@ -1,6 +0,0 @@ -@abstract -extends Object - -class_name Globals - -const GRID_SIZE : Vector2 = Vector2(16,16) diff --git a/scripts/globals.gd.uid b/scripts/globals.gd.uid deleted file mode 100644 index 4bb6907..0000000 --- a/scripts/globals.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://bnmjkc8vfd7mo diff --git a/scripts/grid_controller.gd b/scripts/grid_controller.gd deleted file mode 100644 index 15cb8b4..0000000 --- a/scripts/grid_controller.gd +++ /dev/null @@ -1,42 +0,0 @@ -extends Node2D - -# TODO: Make able to hold multiple placement zones, supporting uniform forms - -## Class that contains all structures of platform - -class_name GridController - - -## Building zone controller uses for checks and capacity -@export var building_zone : PlacementZone - -## Internal structure storage -var structures : Array[Structure] - -func _ready() -> void: - structures.resize(building_zone.get_capacity()) - -## Tries to add structure to its internal storage [br] -## Returns false if has colliding structures -func add_structure(structure : Structure) -> bool: - var structure_dp = structure.get_dimension_points() - for point in structure_dp: - if structures[building_zone.indexify_global_point(structure.global_position + point)]: - return false - structure.reparent(self) - structure.global_position = building_zone.get_placement_position(structure.global_position) - - for point in structure_dp: - structures[building_zone.indexify_global_point(structure.global_position + point)] = structure - return true - -## Returns structure at point. [br] -## Returns null if no structure is at point -func get_at(point : Vector2) -> Structure: - var index = building_zone.indexify_global_point(point) - if index == -1: - return null - return structures[index] - -func is_point_occupied(point : Vector2) -> bool: - return get_at(point) != null diff --git a/scripts/gui/construction_button.gd b/scripts/gui/construction_button.gd index a38d23e..b56e8c8 100644 --- a/scripts/gui/construction_button.gd +++ b/scripts/gui/construction_button.gd @@ -1,6 +1,6 @@ extends Button -@export var constructible : Prototype +@export var constructible : Constructible func _ready() -> void: icon = constructible.preview diff --git a/scripts/gui/gui_event_bus.gd b/scripts/gui/gui_event_bus.gd index 57b7d3b..a5ab2b0 100644 --- a/scripts/gui/gui_event_bus.gd +++ b/scripts/gui/gui_event_bus.gd @@ -2,5 +2,5 @@ extends Node @warning_ignore_start("unused_signal") -signal construction_selected(constructible : Prototype) -signal construction_placed(constructible : Prototype) +signal construction_selected(constructible : Constructible) +signal construction_placed(constructible : Constructible) diff --git a/scripts/prototype.gd b/scripts/prototype.gd deleted file mode 100644 index 83f60a9..0000000 --- a/scripts/prototype.gd +++ /dev/null @@ -1,11 +0,0 @@ -extends Resource - -## Player instantiatable resource - -class_name Prototype - -## Scene to instantiate -@export var scene : PackedScene - -## UI Preview -@export var preview : Texture2D diff --git a/scripts/autoloads/runtime_player_data.gd b/scripts/registry.gd similarity index 53% rename from scripts/autoloads/runtime_player_data.gd rename to scripts/registry.gd index 4f199b3..e408bfa 100644 --- a/scripts/autoloads/runtime_player_data.gd +++ b/scripts/registry.gd @@ -1,12 +1,9 @@ -## Global class for player in-game data - extends Node func _ready() -> void: get_tree().scene_changed.connect(cleanup_runtime_cache) -## Method to cleanup all data that will be nulled func cleanup_runtime_cache(): build_zones.clear() -var build_zones : Array[PlacementZone] +var build_zones : Array[BuildZone] diff --git a/scripts/autoloads/registry.gd.uid b/scripts/registry.gd.uid similarity index 100% rename from scripts/autoloads/registry.gd.uid rename to scripts/registry.gd.uid diff --git a/scripts/runtime_player_data.gd b/scripts/runtime_player_data.gd new file mode 100644 index 0000000..61510e1 --- /dev/null +++ b/scripts/runtime_player_data.gd @@ -0,0 +1 @@ +extends Node diff --git a/scripts/autoloads/runtime_player_data.gd.uid b/scripts/runtime_player_data.gd.uid similarity index 100% rename from scripts/autoloads/runtime_player_data.gd.uid rename to scripts/runtime_player_data.gd.uid diff --git a/scripts/structure.gd b/scripts/structure.gd deleted file mode 100644 index 16792e4..0000000 --- a/scripts/structure.gd +++ /dev/null @@ -1,55 +0,0 @@ -@tool -extends Node2D - -## Game object that interact with other structures in its grid space -class_name Structure - -## Dimensions of structure in grid tiles -@export var dimensions : Rect2i = Rect2i(0,0,1,1): - set(value): - dimensions = value - if Engine.is_editor_hint(): - queue_redraw() - get: - return dimensions - -## Debug draw of points -func _draw() -> void: - if Engine.is_editor_hint(): - for x in range(dimensions.size.x): - for y in range(dimensions.size.y): - draw_circle((dimensions.position+Vector2i(x,y)) * Vector2i(Globals.GRID_SIZE),2,Color.AQUA) - -## Get structure at tile coordinates relative to this structure [br] -## dv : Vector2 - get position in tiles [br] -func get_relative(dv : Vector2) -> Structure: - return get_parent().get_at(global_position+dv*Globals.GRID_SIZE) - -## Check structure is in zone and does not collide with any other structures [br] -## Returns true if structure is in zone and does not collide with any other structure [br] -## Returns false if structure is not in zone or does not collide with any other structure -func can_be_placed(zone : PlacementZone) -> bool: - for dp in get_dimension_points(): - var point = global_position + dp - if zone.is_global_point_in_zone(point) == false: - return false - if zone.grid_controller.is_point_occupied(point): - return false - return true - -## Tries to place structure in zone's grid controller -## Returns false if structure is not in zone or collides with any structure -func try_place(zone : PlacementZone) -> bool: - if can_be_placed(zone) == false: - return false - - return zone.grid_controller.add_structure(self) - -## Returns array of integer points in dimensions -func get_dimension_points() -> Array[Vector2]: - var result : Array[Vector2] = [] - result.resize(dimensions.size.x*dimensions.size.y) - for x in range(dimensions.size.x): - for y in range(dimensions.size.y): - result[x + y * dimensions.size.x] = (Vector2(x,y)*Globals.GRID_SIZE + Vector2(dimensions.position)) - return result diff --git a/sprites/atlasses/Popekko.png b/sprites/atlasses/Popekko.png index 8ff06cb..48fd6af 100644 Binary files a/sprites/atlasses/Popekko.png and b/sprites/atlasses/Popekko.png differ diff --git a/sprites/atlasses/Popekko.png.import b/sprites/atlasses/Popekko.png.import index f2b9199..e1cba67 100644 --- a/sprites/atlasses/Popekko.png.import +++ b/sprites/atlasses/Popekko.png.import @@ -2,7 +2,7 @@ importer="texture" type="CompressedTexture2D" -uid="uid://dinyjq8853usn" +uid="uid://cbtre16ilxte0" path="res://.godot/imported/Popekko.png-5c34a5f2a8c85fcf59453310fa6553d9.ctex" metadata={ "vram_texture": false