Splitters part 1
This commit is contained in:
parent
39c52694da
commit
3c0777f4fd
9 changed files with 150 additions and 2 deletions
15
generic/prototypes/splitter.tres
Normal file
15
generic/prototypes/splitter.tres
Normal file
|
@ -0,0 +1,15 @@
|
|||
[gd_resource type="Resource" script_class="Prototype" load_steps=5 format=3 uid="uid://bm2tggegnoik2"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c80sp6f77l5ha" path="res://scripts/prototype.gd" id="1_cghkd"]
|
||||
[ext_resource type="Texture2D" uid="uid://gfkhedfdi7ug" path="res://sprites/atlasses/Popekko.png" id="1_flgjh"]
|
||||
[ext_resource type="PackedScene" uid="uid://bp4uvx2sdunfr" path="res://scenes/structures/splitter.tscn" id="2_2ry43"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_04mjq"]
|
||||
atlas = ExtResource("1_flgjh")
|
||||
region = Rect2(80, 16, 16, 32)
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_cghkd")
|
||||
scene = ExtResource("2_2ry43")
|
||||
preview = SubResource("AtlasTexture_04mjq")
|
||||
metadata/_custom_type_script = "uid://c80sp6f77l5ha"
|
65
scenes/structures/splitter.tscn
Normal file
65
scenes/structures/splitter.tscn
Normal file
|
@ -0,0 +1,65 @@
|
|||
[gd_scene load_steps=17 format=3 uid="uid://bp4uvx2sdunfr"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bbd7o2st8kmgl" path="res://scripts/structure.gd" id="1_0ta8r"]
|
||||
[ext_resource type="Script" uid="uid://bd4ojfqrl8idm" path="res://scripts/inventory/inventory_slot.gd" id="2_lbove"]
|
||||
[ext_resource type="Script" uid="uid://dlt3mbu6hk572" path="res://scripts/inventory/splitter_inventory.gd" id="3_2ulpw"]
|
||||
[ext_resource type="Texture2D" uid="uid://gfkhedfdi7ug" path="res://sprites/atlasses/Popekko.png" id="4_iov8t"]
|
||||
[ext_resource type="Script" uid="uid://lchhqigib2t0" path="res://scripts/structures/directional_sprite.gd" id="5_mimwr"]
|
||||
[ext_resource type="Script" uid="uid://bml2n6vo5my0c" path="res://scripts/inventory/advanced_rotation.gd" id="6_mimwr"]
|
||||
[ext_resource type="Script" uid="uid://bac6ei0tpoiqe" path="res://scripts/structures/splitter.gd" id="7_0dkfh"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_iov8t"]
|
||||
resource_local_to_scene = true
|
||||
script = ExtResource("3_2ulpw")
|
||||
capacity = 4
|
||||
metadata/_custom_type_script = "uid://dlt3mbu6hk572"
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_0dkfh"]
|
||||
atlas = ExtResource("4_iov8t")
|
||||
region = Rect2(80, 16, 16, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_04mjq"]
|
||||
atlas = ExtResource("4_iov8t")
|
||||
region = Rect2(80, 16, 16, 32)
|
||||
|
||||
[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_41jic"]
|
||||
load_path = "res://.godot/imported/Popekko.png-5c34a5f2a8c85fcf59453310fa6553d9.ctex"
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ksqgd"]
|
||||
atlas = SubResource("CompressedTexture2D_41jic")
|
||||
region = Rect2(80, 64, 32, 16)
|
||||
|
||||
[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_f7n4f"]
|
||||
load_path = "res://.godot/imported/Popekko.png-5c34a5f2a8c85fcf59453310fa6553d9.ctex"
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_0x331"]
|
||||
atlas = SubResource("CompressedTexture2D_f7n4f")
|
||||
region = Rect2(96, 16, 16, 32)
|
||||
|
||||
[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_hmwxr"]
|
||||
load_path = "res://.godot/imported/Popekko.png-5c34a5f2a8c85fcf59453310fa6553d9.ctex"
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_upfxh"]
|
||||
atlas = SubResource("CompressedTexture2D_hmwxr")
|
||||
region = Rect2(80, 48, 32, 16)
|
||||
|
||||
[node name="Splitter" type="Node2D"]
|
||||
script = ExtResource("1_0ta8r")
|
||||
dimensions = Rect2i(0, 0, 1, 2)
|
||||
inventory = SubResource("Resource_iov8t")
|
||||
maximum_directions = 4
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="." node_paths=PackedStringArray("structure")]
|
||||
texture = SubResource("AtlasTexture_0dkfh")
|
||||
offset = Vector2(0, 8)
|
||||
script = ExtResource("5_mimwr")
|
||||
textures = Array[Texture]([SubResource("AtlasTexture_04mjq"), SubResource("AtlasTexture_ksqgd"), SubResource("AtlasTexture_0x331"), SubResource("AtlasTexture_upfxh")])
|
||||
structure = NodePath("..")
|
||||
|
||||
[node name="AdvancedRotation" type="Node" parent="." node_paths=PackedStringArray("structure", "sprite")]
|
||||
script = ExtResource("6_mimwr")
|
||||
structure = NodePath("..")
|
||||
sprite = NodePath("../Sprite2D")
|
||||
|
||||
[node name="Splitter" type="Node2D" parent="."]
|
||||
script = ExtResource("7_0dkfh")
|
15
scripts/inventory/advanced_rotation.gd
Normal file
15
scripts/inventory/advanced_rotation.gd
Normal file
|
@ -0,0 +1,15 @@
|
|||
extends Node
|
||||
|
||||
@export var structure : Structure
|
||||
@export var sprite : Sprite2D
|
||||
|
||||
@onready var initial_dimensions : Rect2i = structure.dimensions
|
||||
@onready var initial_offset : Vector2 = sprite.offset
|
||||
|
||||
func _ready() -> void:
|
||||
structure.changed_direction.connect(on_changed_direction)
|
||||
|
||||
func on_changed_direction(to: float,max_directions : int):
|
||||
var calculated_size = Vector2(initial_dimensions.size).rotated(to).abs().ceil()
|
||||
structure.dimensions = Rect2i(initial_dimensions.position,calculated_size)
|
||||
sprite.offset = initial_offset.rotated(to).abs()
|
1
scripts/inventory/advanced_rotation.gd.uid
Normal file
1
scripts/inventory/advanced_rotation.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://bml2n6vo5my0c
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
extends Inventory
|
||||
|
||||
class_name SplitterInventory
|
||||
|
||||
@export var capacity : int:
|
||||
set(value):
|
||||
if value < 0:
|
||||
|
@ -25,3 +27,48 @@ func deferred_init():
|
|||
for i in range(capacity):
|
||||
upper_array[i] = InventorySlot.new()
|
||||
down_array[i] = InventorySlot.new()
|
||||
|
||||
func add(stack : Stack, context: InventoryContext = null) -> Stack:
|
||||
if context == null:
|
||||
return stack
|
||||
if context.position == context.target.global_position:
|
||||
return add_to_array(stack,upper_array,context)
|
||||
return add_to_array(stack,down_array,context)
|
||||
|
||||
func add_to_array(stack: Stack, array: Array[InventorySlot], context: InventoryContext = null) -> Stack:
|
||||
for i in range(len(array)):
|
||||
if array[i].held_item == null or array[i].held_item == stack.held_item:
|
||||
stack_added.emit(stack,i)
|
||||
array[i].merge_stack(stack)
|
||||
if stack.is_valid() == false:
|
||||
return null
|
||||
return stack
|
||||
|
||||
func can_add(item : Item = null, context: InventoryContext = null) -> bool:
|
||||
if context == null:
|
||||
return false
|
||||
if item == null:
|
||||
for i in range(capacity):
|
||||
if upper_array[i].amount == 0 or down_array[i].amount == 0:
|
||||
return true
|
||||
else:
|
||||
for i in range(capacity):
|
||||
if upper_array[i].amount == 0:
|
||||
return upper_array[i].can_be_merged(item)
|
||||
if down_array[i].amount ==0:
|
||||
return down_array[i].can_be_merged(item)
|
||||
return false
|
||||
|
||||
func pop() -> Stack:
|
||||
return null
|
||||
|
||||
func peek() -> Stack:
|
||||
return null
|
||||
|
||||
## Tries to take certain item from inventory. Returns null if no item found
|
||||
func take(item : Item,amount: int) -> Stack:
|
||||
return null
|
||||
|
||||
## Finds first entry of item. Returns -1 if no item found
|
||||
func find(item : Item) -> int:
|
||||
return -1
|
||||
|
|
|
@ -31,9 +31,12 @@ func _draw() -> void:
|
|||
## dv : Vector2 - get position in tiles [br]
|
||||
func get_relative(dv : Vector2) -> Structure:
|
||||
if get_parent() is GridController:
|
||||
return get_parent().get_at(global_position+dv*Globals.GRID_SIZE)
|
||||
return get_parent().get_at(relative_tile_as_global(dv))
|
||||
return null
|
||||
|
||||
func relative_tile_as_global(dv: Vector2) -> Vector2:
|
||||
return 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
|
||||
|
|
|
@ -24,7 +24,7 @@ func _process(_delta: float) -> void:
|
|||
var output : Structure = get_output_structure()
|
||||
if output == null:
|
||||
return
|
||||
var transfer_context : InventoryContext = InventoryContext.new(structure_parent,output,get_output_position())
|
||||
var transfer_context : InventoryContext = InventoryContext.new(structure_parent,output,structure_parent.relative_tile_as_global(get_output_position()))
|
||||
if output.inventory.can_add(inventory.output_slot.held_item,transfer_context):
|
||||
inventory.output_slot.merge_stack(output.inventory.add(inventory.output_slot.extract(),transfer_context))
|
||||
|
||||
|
|
1
scripts/structures/splitter.gd
Normal file
1
scripts/structures/splitter.gd
Normal file
|
@ -0,0 +1 @@
|
|||
extends StructureBehaviour
|
1
scripts/structures/splitter.gd.uid
Normal file
1
scripts/structures/splitter.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://bac6ei0tpoiqe
|
Loading…
Add table
Add a link
Reference in a new issue