Skip to content

Commit

Permalink
Add Tub and Furnace examples
Browse files Browse the repository at this point in the history
  • Loading branch information
UnseenFaith committed Apr 25, 2024
1 parent 309cf31 commit e729aaf
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 3 deletions.
6 changes: 5 additions & 1 deletion nodes/scenes/TestLevel.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=95 format=3 uid="uid://djq34560nwlx"]
[gd_scene load_steps=96 format=3 uid="uid://djq34560nwlx"]

[ext_resource type="Texture2D" uid="uid://0v6r74o2p5lv" path="res://art/isometric-sandbox-sheet.png" id="1_av4hw"]
[ext_resource type="Texture2D" uid="uid://bnrwpcvbm713v" path="res://art/carpet.png" id="1_rdr83"]
Expand Down Expand Up @@ -53,6 +53,7 @@
[ext_resource type="PackedScene" uid="uid://h6wala3xyh6c" path="res://nodes/wip/Tubs/Tub.tscn" id="70_bb2jl"]
[ext_resource type="Texture2D" uid="uid://ldkw52t8yxi7" path="res://art/table-animation/crafting animation29.png" id="70_rnq4y"]
[ext_resource type="Texture2D" uid="uid://5ttf0w01sqsn" path="res://art/table-animation/crafting animation30.png" id="71_b8i2m"]
[ext_resource type="PackedScene" uid="uid://tjdkpgoqr6lw" path="res://nodes/wip/Anvils/Anvil.tscn" id="71_hkiyg"]
[ext_resource type="Texture2D" uid="uid://nltbl2wtwxuh" path="res://art/table-animation/crafting animation31.png" id="72_du6f1"]
[ext_resource type="Texture2D" uid="uid://cvctyqo4l7db4" path="res://art/bubbles/bubbles1.png" id="73_n7n3y"]
[ext_resource type="Texture2D" uid="uid://diaeeoq5dcqwh" path="res://art/bubbles/bubbles2.png" id="74_u2q4d"]
Expand Down Expand Up @@ -1227,5 +1228,8 @@ position = Vector2(496, 240)
[node name="Tub" parent="." instance=ExtResource("70_bb2jl")]
position = Vector2(502, 277)

[node name="Anvil" parent="." instance=ExtResource("71_hkiyg")]
position = Vector2(584, 268)

[connection signal="body_entered" from="TileMap/ZIndexArea" to="TileMap" method="_on_area_2d_body_entered"]
[connection signal="body_exited" from="TileMap/ZIndexArea" to="TileMap" method="_on_area_2d_body_exited"]
117 changes: 117 additions & 0 deletions nodes/wip/Anvils/Anvil.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
extends Area2D
class_name Anvil

# Define the states of this block
enum AnvilState {
IDLE,
SMITHING,
SMITHED
}

@export var flip_horizontally: bool = false

@onready var collision: CollisionPolygon2D = get_node("CollisionShape")
# In the future these two will be merged into a single animatedsprite2d
@onready var sprite: Sprite2D = get_node("Sprite")
@onready var animation: AnimatedSprite2D = get_node("Animation")
@onready var toast: Node2D = get_node("InventoryToast")

var type: Enums.StationType = Enums.StationType.FURNACE
var inventory: PackedStringArray = PackedStringArray([])
var max_size: int = 1
var recipes: Array[Recipe] = []
var state: AnvilState = AnvilState.IDLE

var allowed_items: RegEx = RegEx.new();

func interact(player: Blacksmith, input: StringName) -> bool:
match input:
&"interaction":
match state:
AnvilState.IDLE:
if player.heldItem == null:
if !is_empty():
var item = remove_first_item()
player.equip_item(item)
return true
else:
if inventory.size() == max_size:
return false

var item = player.heldItem.get_groups()[0]

if allowed_items.search(item).strings.size() == 0:
return false

if !Array(inventory).all(func(r): return r == item):
return false

add_item(item)
player.unequip_item()
state = AnvilState.SMITHING

var recipe = find_recipe()
if recipe != null:
print("Starting Smithing")
player.immobile = true
await get_tree().create_timer(5).timeout
print("Finished Smithing")
player.immobile = false
state = AnvilState.SMITHED
return true
AnvilState.SMITHED:
var recipe = find_recipe()
if recipe != null:
var item = recipe.product
inventory = []
player.equip_item(item)
return true
return false

func add_item(item: StringName) -> void:
inventory.append(item)
toast.add_material(item)

func remove_item() -> StringName:
return &"HELLO"
pass

func remove_first_item() -> StringName:
var item = inventory[0]
inventory = inventory.slice(1)
update_toast()
return item

func update_toast():
toast.clear()
for item in inventory:
toast.add_material(item)

func is_empty():
return inventory.size() == 0

func find_recipe() -> Recipe:
for recipe in recipes:
if recipe.ingredients == inventory:
return recipe
return null


# Called when the node enters the scene tree for the first time.
func _ready():
if flip_horizontally:
flip_station()

allowed_items.compile("chunk$")

var recipe = Recipe.new()
recipe.add_ingredient(&"bronze_shield_chunk")
recipe.product = &"bronze_shield"

recipes.append(recipe)

func flip_station():
var collision = get_node("CollisionShape")
collision.scale.x = collision.scale.x * -1
sprite.flip_h = true
animation.flip_h = true
25 changes: 25 additions & 0 deletions nodes/wip/Anvils/Anvil.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[gd_scene load_steps=4 format=3 uid="uid://tjdkpgoqr6lw"]

[ext_resource type="Script" path="res://nodes/wip/Anvils/Anvil.gd" id="1_37r6u"]
[ext_resource type="Texture2D" uid="uid://d2icifub1b3j1" path="res://art/anvil.png" id="2_qnqcg"]
[ext_resource type="PackedScene" uid="uid://dpsr055c1v16j" path="res://nodes/ui/MaterialToast.tscn" id="3_vsw8d"]

[node name="Anvil" type="Area2D" groups=["anvil", "interactable"]]
z_index = 1
collision_layer = 2
collision_mask = 2
script = ExtResource("1_37r6u")

[node name="CollisionShape" type="CollisionPolygon2D" parent="."]
polygon = PackedVector2Array(6, 0, 20, -6, 19, -22, -9, -36, -20, -30, -19, -11)

[node name="Sprite" type="Sprite2D" parent="."]
texture_filter = 1
position = Vector2(0, -17.5)
texture = ExtResource("2_qnqcg")
region_enabled = true
region_rect = Rect2(0, 29, 39, 35)

[node name="Animation" type="AnimatedSprite2D" parent="."]

[node name="InventoryToast" parent="." instance=ExtResource("3_vsw8d")]
2 changes: 1 addition & 1 deletion nodes/wip/Furnace/Furnace.gd
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func _ready():
recipe.add_ingredient(&"bronze_ore")
recipe.add_ingredient(&"bronze_ore")
recipe.add_ingredient(&"bronze_ore")
recipe.product = &"bronze_shield"
recipe.product = &"bronze_shield_chunk"

recipes.append(recipe)

Expand Down
2 changes: 1 addition & 1 deletion nodes/wip/Tubs/Tub.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum TubState {

var type: Enums.StationType = Enums.StationType.TUB
var inventory: PackedStringArray = PackedStringArray([])
var max_size: int = 3
var max_size: int = 1
var recipes: Array[Recipe] = []
var state: TubState = TubState.IDLE

Expand Down

0 comments on commit e729aaf

Please sign in to comment.