Ajout du comportement des ItemContainer

This commit is contained in:
Luna Manson 2024-02-17 16:31:03 +01:00
parent a26b557d2f
commit 962378fe93
18 changed files with 285 additions and 13 deletions

View file

@ -8,7 +8,6 @@ size = Vector2(16, 16)
[node name="Crate" type="Area2D"]
script = ExtResource("1_a65k5")
Interact_Type = "Crate1"
[node name="Sprite2D" type="Sprite2D" parent="."]
texture_filter = 1
@ -32,3 +31,4 @@ position = Vector2(16, 0)
shape = SubResource("RectangleShape2D_jjien")
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
[connection signal="body_exited" from="." to="." method="_on_body_exited"]

View file

@ -0,0 +1,13 @@
[gd_scene load_steps=4 format=3 uid="uid://d1oww5u6d2464"]
[ext_resource type="PackedScene" uid="uid://nv8r4yu48mbj" path="res://Scene/Interactibles/Crate.tscn" id="1_4363q"]
[ext_resource type="Script" path="res://Scripts/Shelf.gd" id="2_5mi56"]
[ext_resource type="Texture2D" uid="uid://dfoc57ynahbbg" path="res://Tilemaps/Tiles/tile_0277.png" id="2_m2jbe"]
[node name="Crate" instance=ExtResource("1_4363q")]
script = ExtResource("2_5mi56")
duration = 0
duration_type = 0
[node name="Sprite2D" parent="." index="0"]
texture = ExtResource("2_m2jbe")

34
Scene/Tes888C.tmp Normal file
View file

@ -0,0 +1,34 @@
[gd_scene load_steps=4 format=3 uid="uid://bvam15obn13sp"]
[ext_resource type="TileSet" uid="uid://btq4xft7ghfa1" path="res://Tilemaps/TestScene.tres" id="1_ppucb"]
[ext_resource type="Script" path="res://Scripts/NavigationTiles.gd" id="2_j8mqm"]
[ext_resource type="PackedScene" uid="uid://dy12im5456ufx" path="res://Scene/PlayerScene.tscn" id="3_hlgkw"]
[node name="Node2D" type="Node2D"]
[node name="Camera2D" type="Camera2D" parent="."]
scale = Vector2(1, 0.68)
offset = Vector2(84.925, 47.62)
zoom = Vector2(6.645, 6.645)
[node name="NavigationMap" type="TileMap" parent="."]
texture_filter = 1
tile_set = ExtResource("1_ppucb")
format = 2
layer_0/name = "Background"
layer_0/tile_data = PackedInt32Array(65537, 524288, 0, 131073, 524288, 1, 196609, 524288, 1, 262145, 524288, 2, 327681, 1048576, 1610612740, 65538, 589824, 0, 131074, 589824, 1, 196610, 589824, 1, 262146, 589824, 2, 327682, 1048576, 1610612742, 65539, 589824, 0, 196611, 589824, 1, 262147, 589824, 2, 327683, 1048576, 1610612742, 65540, 589824, 0, 262148, 589824, 2, 327684, 1048576, 1610612742, 65541, 655360, 0, 131077, 655360, 1, 196613, 655360, 1, 262149, 655360, 2, 327685, 1048576, 1610612742, 65542, 1048576, 5, 131078, 1048576, 5, 196614, 1048576, 5, 262150, 1048576, 5, 327686, 1048576, 7, 0, 1048576, 4, 65536, 1048576, 5, 131072, 1048576, 5, 196608, 1048576, 5, 262144, 1048576, 5, 327680, 1048576, 7, 1, 1048576, 1610612740, 2, 1048576, 1610612742, 3, 1048576, 1610612742, 4, 1048576, 1610612742, 5, 1048576, 1610612742, 6, 1048576, 4, 131075, 589824, 1, 196612, 589824, 1, 131076, 589824, 1)
layer_1/name = "Object"
layer_1/tile_data = PackedInt32Array(131076, 3, 65536, 196610, 3, 131072)
layer_2/name = "ColisionMask"
layer_2/modulate = Color(1, 1, 1, 0)
layer_2/tile_data = PackedInt32Array(131076, 1048576, 5)
script = ExtResource("2_j8mqm")
[node name="PlayerScene" parent="." instance=ExtResource("3_hlgkw")]
position = Vector2(24, 24)
[connection signal="body_entered" from="NavigationMap/Crate" to="NavigationMap/Crate" method="_on_body_entered"]
[connection signal="body_exited" from="NavigationMap/Crate" to="NavigationMap/Crate" method="_on_body_exited"]
[connection signal="body_entered" from="NavigationMap/@Area2D@35587" to="NavigationMap/@Area2D@35587" method="_on_body_entered"]
[connection signal="body_exited" from="NavigationMap/@Area2D@35587" to="NavigationMap/@Area2D@35587" method="_on_body_exited"]
[connection signal="remove_interact" from="PlayerScene" to="PlayerScene" method="_on_remove_interact"]

View file

@ -18,7 +18,7 @@ format = 2
layer_0/name = "Background"
layer_0/tile_data = PackedInt32Array(65537, 524288, 0, 131073, 524288, 1, 196609, 524288, 1, 262145, 524288, 2, 327681, 1048576, 1610612740, 65538, 589824, 0, 131074, 589824, 1, 196610, 589824, 1, 262146, 589824, 2, 327682, 1048576, 1610612742, 65539, 589824, 0, 196611, 589824, 1, 262147, 589824, 2, 327683, 1048576, 1610612742, 65540, 589824, 0, 262148, 589824, 2, 327684, 1048576, 1610612742, 65541, 655360, 0, 131077, 655360, 1, 196613, 655360, 1, 262149, 655360, 2, 327685, 1048576, 1610612742, 65542, 1048576, 5, 131078, 1048576, 5, 196614, 1048576, 5, 262150, 1048576, 5, 327686, 1048576, 7, 0, 1048576, 4, 65536, 1048576, 5, 131072, 1048576, 5, 196608, 1048576, 5, 262144, 1048576, 5, 327680, 1048576, 7, 1, 1048576, 1610612740, 2, 1048576, 1610612742, 3, 1048576, 1610612742, 4, 1048576, 1610612742, 5, 1048576, 1610612742, 6, 1048576, 4, 131075, 589824, 1, 196612, 589824, 1, 131076, 589824, 1)
layer_1/name = "Object"
layer_1/tile_data = PackedInt32Array(131076, 3, 65536)
layer_1/tile_data = PackedInt32Array(131076, 3, 65536, 196610, 3, 131072)
layer_2/name = "ColisionMask"
layer_2/modulate = Color(1, 1, 1, 0)
layer_2/tile_data = PackedInt32Array(131076, 1048576, 5)
@ -27,4 +27,4 @@ script = ExtResource("2_j8mqm")
[node name="PlayerScene" parent="." instance=ExtResource("3_hlgkw")]
position = Vector2(24, 24)
[connection signal="body_entered" from="NavigationMap/Crate" to="NavigationMap/Crate" method="_on_body_entered"]
[connection signal="remove_interact" from="PlayerScene" to="PlayerScene" method="_on_remove_interact"]

View file

@ -1,9 +1,15 @@
extends Interactible
extends ItemContainer
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
var firstitem = Item.new()
firstitem.name = "rouge"
firstitem.Icon = Sprite2D.new()
firstitem.Icon.set_texture(preload("res://Sprite/IMG_0156.PNG"))
firstitem.Icon.set_texture_filter(CanvasItem.TEXTURE_FILTER_NEAREST)
items.append(firstitem)
# Called every frame. 'delta' is the elapsed time since the previous frame.
@ -12,7 +18,8 @@ func _process(delta):
func _on_body_entered(body : Player):
body.can_interact.emit(Interact_Type,self)
body.can_interact.emit(self)
func _on_body_exited(body: Player):
body.remove_interact.emit() # Replace with function body.

View file

@ -1,6 +1,4 @@
class_name Interactible extends Area2D
@export
var Interact_Type = "none"

View file

@ -0,0 +1,5 @@
class_name Item extends Node
var Name : String = "none"
var Icon : Sprite2D

View file

@ -0,0 +1,17 @@
class_name ItemContainer extends Interactible
@export
var items : Array[Item]
func pop_item(index: int = 0):
pass
func add_item(item: Item):
pass

View file

@ -0,0 +1,8 @@
class_name ItemProcessor extends ItemContainer
@export_group("Processor config")
@export var duration : int = 0
@export var duration_type : DURATION_TYPE
enum DURATION_TYPE {Instant, AP, Turn}

View file

@ -3,7 +3,16 @@ class_name Player
@onready var gridcontrol: TileMap = $"../NavigationMap"
signal can_interact(object : Interactible)
signal remove_interact()
var current_path : Array[Vector2i]
var object_near : Interactible
var can_interact_flag : bool
var held_item : Item
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
@ -31,9 +40,35 @@ func _unhandled_input(event):
gridcontrol.local_to_map(click_position)
).slice(1)
signal can_interact(object : String)
func _shortcut_input(event):
if event.is_action_pressed("interact") && can_interact_flag:
if object_near is ItemContainer :
if not object_near.items.is_empty() && held_item == null:
held_item = object_near.items[0]
object_near.pop_item(0)
_add_item_overhead()
else :
object_near.add_item(held_item)
remove_child(held_item)
remove_child(held_item.Icon)
held_item = null
func _on_can_interact(Interact_Type: String, object : Interactible):
prints("yippie", Interact_Type)
func _on_can_interact(object : Interactible):
can_interact_flag = true
object_near = object
func _on_remove_interact():
can_interact_flag = false
object_near = null
func _add_item_overhead() :
add_child(held_item)
add_child(held_item.Icon)
held_item.Icon.set_scale(Vector2(0.5,0.5))
held_item.Icon.offset = Vector2i(0,-10)
held_item.Icon.modulate = Color(1,1,1,0.4)

18
Scripts/Shelf.gd Normal file
View file

@ -0,0 +1,18 @@
extends ItemProcessor
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _on_body_entered(body : Player):
body.can_interact.emit(self)
func _on_body_exited(body: Player):
body.remove_interact.emit() # Replace with function body.

BIN
Sprite/IMG_0156.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://d4kuxsq8yf2t2"
path="res://.godot/imported/IMG_0156.PNG-5b08894a60fc22746c1de93eda63d789.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprite/IMG_0156.PNG"
dest_files=["res://.godot/imported/IMG_0156.PNG-5b08894a60fc22746c1de93eda63d789.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -1,7 +1,8 @@
[gd_resource type="TileSet" load_steps=5 format=3 uid="uid://btq4xft7ghfa1"]
[gd_resource type="TileSet" load_steps=6 format=3 uid="uid://btq4xft7ghfa1"]
[ext_resource type="Texture2D" uid="uid://n6wwhbhv6t6t" path="res://Tilemaps/tilemap_packed.png" id="1_eewka"]
[ext_resource type="PackedScene" uid="uid://nv8r4yu48mbj" path="res://Scene/Interactibles/Crate.tscn" id="2_oi0ah"]
[ext_resource type="PackedScene" uid="uid://d1oww5u6d2464" path="res://Scene/Interactibles/Shelf.tscn" id="3_imt3x"]
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_om8rr"]
resource_name = "Tilemap1"
@ -505,6 +506,7 @@ texture = ExtResource("1_eewka")
[sub_resource type="TileSetScenesCollectionSource" id="TileSetScenesCollectionSource_t8dt2"]
scenes/1/scene = ExtResource("2_oi0ah")
scenes/2/scene = ExtResource("3_imt3x")
[resource]
custom_data_layer_0/name = "is_solid"

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dfoc57ynahbbg"
path="res://.godot/imported/tile_0277.png-5c4f65ba33c8e2c8baa32bd926f7b9e3.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Tilemaps/Tiles/tile_0277.png"
dest_files=["res://.godot/imported/tile_0277.png-5c4f65ba33c8e2c8baa32bd926f7b9e3.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

62
export_presets.cfg Normal file
View file

@ -0,0 +1,62 @@
[preset.0]
name="Windows Desktop"
platform="Windows Desktop"
runnable=true
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path=""
encryption_include_filters=""
encryption_exclude_filters=""
encrypt_pck=false
encrypt_directory=false
[preset.0.options]
custom_template/debug=""
custom_template/release=""
debug/export_console_wrapper=1
binary_format/embed_pck=false
texture_format/bptc=true
texture_format/s3tc=true
texture_format/etc=false
texture_format/etc2=false
binary_format/architecture="x86_64"
codesign/enable=false
codesign/timestamp=true
codesign/timestamp_server_url=""
codesign/digest_algorithm=1
codesign/description=""
codesign/custom_options=PackedStringArray()
application/modify_resources=true
application/icon=""
application/console_wrapper_icon=""
application/icon_interpolation=4
application/file_version=""
application/product_version=""
application/company_name=""
application/product_name=""
application/file_description=""
application/copyright=""
application/trademarks=""
application/export_angle=0
ssh_remote_deploy/enabled=false
ssh_remote_deploy/host="user@host_ip"
ssh_remote_deploy/port="22"
ssh_remote_deploy/extra_args_ssh=""
ssh_remote_deploy/extra_args_scp=""
ssh_remote_deploy/run_script="Expand-Archive -LiteralPath '{temp_dir}\\{archive_name}' -DestinationPath '{temp_dir}'
$action = New-ScheduledTaskAction -Execute '{temp_dir}\\{exe_name}' -Argument '{cmd_args}'
$trigger = New-ScheduledTaskTrigger -Once -At 00:00
$settings = New-ScheduledTaskSettingsSet
$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings
Register-ScheduledTask godot_remote_debug -InputObject $task -Force:$true
Start-ScheduledTask -TaskName godot_remote_debug
while (Get-ScheduledTask -TaskName godot_remote_debug | ? State -eq running) { Start-Sleep -Milliseconds 100 }
Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue"
ssh_remote_deploy/cleanup_script="Stop-ScheduledTask -TaskName godot_remote_debug -ErrorAction:SilentlyContinue
Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue
Remove-Item -Recurse -Force '{temp_dir}'"

View file

@ -27,3 +27,8 @@ move_to={
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(160, 17),"global_position":Vector2(164, 58),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
]
}
interact={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"echo":false,"script":null)
]
}