Add food and yam interaction

This commit is contained in:
Daniel Snider 2022-08-14 05:40:14 -07:00
parent 2874c11658
commit d20642e267
41 changed files with 2747 additions and 42 deletions

BIN
assets/ore/Rock.material Normal file

Binary file not shown.

BIN
assets/ore/ore.glb Normal file

Binary file not shown.

1065
assets/ore/ore.glb.import Normal file

File diff suppressed because it is too large Load Diff

5
assets/ore/ore.tscn Normal file
View File

@ -0,0 +1,5 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://assets/ore/ore.glb" type="PackedScene" id=1]
[node name="ore" instance=ExtResource( 1 )]

Binary file not shown.

View File

@ -1,5 +1,12 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=3 format=2]
[ext_resource path="res://assets/protodungman/DungMan.glb" type="PackedScene" id=1]
[sub_resource type="SpatialMaterial" id=1]
albedo_color = Color( 0.666667, 0.870588, 0.760784, 1 )
roughness = 0.72
[node name="DungMan" instance=ExtResource( 1 )]
[node name="Dungee" parent="." index="0"]
material/0 = SubResource( 1 )

Binary file not shown.

BIN
assets/yam/Leaf.material Normal file

Binary file not shown.

BIN
assets/yam/Yam.material Normal file

Binary file not shown.

BIN
assets/yam/yam.glb Normal file

Binary file not shown.

1065
assets/yam/yam.glb.import Normal file

File diff suppressed because it is too large Load Diff

5
assets/yam/yam.tscn Normal file
View File

@ -0,0 +1,5 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://assets/yam/yam.glb" type="PackedScene" id=1]
[node name="yam" instance=ExtResource( 1 )]

View File

@ -0,0 +1,9 @@
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://scripts/ItemType.gd" type="Script" id=1]
[ext_resource path="res://assets/yam/yam.tscn" type="PackedScene" id=2]
[resource]
script = ExtResource( 1 )
name = "Cooked Yam"
visual_scene = ExtResource( 2 )

9
item_types/ore.tres Normal file
View File

@ -0,0 +1,9 @@
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://scripts/ItemType.gd" type="Script" id=1]
[ext_resource path="res://assets/ore/ore.tscn" type="PackedScene" id=2]
[resource]
script = ExtResource( 1 )
name = "Ore"
visual_scene = ExtResource( 2 )

9
item_types/raw_yam.tres Normal file
View File

@ -0,0 +1,9 @@
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://scripts/ItemType.gd" type="Script" id=1]
[ext_resource path="res://assets/yam/yam.tscn" type="PackedScene" id=2]
[resource]
script = ExtResource( 1 )
name = "Raw Yam"
visual_scene = ExtResource( 2 )

View File

@ -0,0 +1,9 @@
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://scripts/ItemType.gd" type="Script" id=1]
[ext_resource path="res://assets/yam/yam.tscn" type="PackedScene" id=2]
[resource]
script = ExtResource( 1 )
name = "Repair Kit"
visual_scene = ExtResource( 2 )

View File

@ -63,6 +63,21 @@ _global_script_classes=[ {
"class": "HistoryRow",
"language": "GDScript",
"path": "res://addons/dialogic/Example Assets/History/HistoryRow.gd"
}, {
"base": "Resource",
"class": "ItemType",
"language": "GDScript",
"path": "res://scripts/ItemType.gd"
}, {
"base": "Resource",
"class": "Recipe",
"language": "GDScript",
"path": "res://scripts/Recipe.gd"
}, {
"base": "Resource",
"class": "RecipeDB",
"language": "GDScript",
"path": "res://scripts/RecipeDB.gd"
} ]
_global_script_class_icons={
"DTS": "",
@ -75,7 +90,10 @@ _global_script_class_icons={
"DialogicParser": "",
"DialogicResources": "",
"DialogicUtil": "",
"HistoryRow": ""
"HistoryRow": "",
"ItemType": "",
"Recipe": "",
"RecipeDB": ""
}
[application]
@ -86,6 +104,8 @@ config/icon="res://icon.png"
[display]
window/size/width=2048
window/size/height=1200
window/dpi/allow_hidpi=true
[editor_plugins]

8
recipes/all_recipes.tres Normal file
View File

@ -0,0 +1,8 @@
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://scripts/RecipeDB.gd" type="Script" id=1]
[ext_resource path="res://recipes/repair_kit_recipe.tres" type="Resource" id=2]
[resource]
script = ExtResource( 1 )
recipes = [ ExtResource( 2 ) ]

View File

@ -0,0 +1,11 @@
[gd_resource type="Resource" load_steps=4 format=2]
[ext_resource path="res://scripts/Recipe.gd" type="Script" id=1]
[ext_resource path="res://item_types/ore.tres" type="Resource" id=2]
[ext_resource path="res://item_types/raw_yam.tres" type="Resource" id=3]
[resource]
script = ExtResource( 1 )
item_type_in_1 = ExtResource( 2 )
item_type_in_2 = ExtResource( 2 )
item_type_out = ExtResource( 3 )

View File

@ -1,9 +1,11 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=7 format=2]
[ext_resource path="res://scenes/player.tscn" type="PackedScene" id=1]
[ext_resource path="res://scenes/moon.tscn" type="PackedScene" id=2]
[ext_resource path="res://scenes/power_station.tscn" type="PackedScene" id=3]
[ext_resource path="res://item_types/raw_yam.tres" type="Resource" id=4]
[ext_resource path="res://scenes/item_holder.tscn" type="PackedScene" id=5]
[ext_resource path="res://item_types/ore.tres" type="Resource" id=6]
[node name="dev_akshay" type="Spatial"]
@ -17,8 +19,11 @@ time_to_generate = 5.0
[node name="item_holder" parent="." instance=ExtResource( 5 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -4.04269, 0, -4.32055 )
start_with_item = "Ore"
start_with_item = ExtResource( 4 )
[node name="item_holder2" parent="." instance=ExtResource( 5 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 3.179, 0, -4.17727 )
start_with_item = "Roe"
start_with_item = ExtResource( 6 )
[node name="item_holder3" parent="." instance=ExtResource( 5 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0480788, 0, -7.2244 )

47
scenes/dinner_table.tscn Normal file
View File

@ -0,0 +1,47 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://scenes/item_holder.tscn" type="PackedScene" id=1]
[sub_resource type="CylinderMesh" id=1]
height = 0.1
radial_segments = 8
[sub_resource type="CylinderMesh" id=2]
top_radius = 0.1
bottom_radius = 0.1
height = 0.738
radial_segments = 16
[sub_resource type="CylinderShape" id=3]
height = 0.87498
[node name="dinner_table" type="Spatial"]
[node name="MeshInstance" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.648164, 0 )
mesh = SubResource( 1 )
[node name="MeshInstance2" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.274821, 0.806474 )
mesh = SubResource( 2 )
[node name="MeshInstance3" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.831715, 0.274821, 0.00579381 )
mesh = SubResource( 2 )
[node name="MeshInstance4" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.012414, 0.274821, -0.832128 )
mesh = SubResource( 2 )
[node name="MeshInstance5" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.809991, 0.274821, 0.00269032 )
mesh = SubResource( 2 )
[node name="StaticBody" type="StaticBody" parent="."]
[node name="CollisionShape" type="CollisionShape" parent="StaticBody"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.439889, 0 )
shape = SubResource( 3 )
[node name="item_holder" parent="." instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.776869, 0 )

View File

@ -1,15 +1,13 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://scripts/hydroponics_station.gd" type="Script" id=2]
[ext_resource path="res://scenes/item_holder.tscn" type="PackedScene" id=1]
[ext_resource path="res://scripts/hydroponics_station/hydroponics_station.gd" type="Script" id=2]
[ext_resource path="res://scenes/coin_machine.tscn" type="PackedScene" id=3]
[sub_resource type="CylinderMesh" id=1]
height = 0.936
radial_segments = 8
[sub_resource type="CubeMesh" id=3]
size = Vector3( 0.4, 1, 0.4 )
[sub_resource type="ConvexPolygonShape" id=2]
points = PoolVector3Array( -0.0608763, 0.449247, 0.974783, -0.0608763, -0.464612, -0.974783, -0.0608763, 0.449247, -0.974783, 0.974783, -0.464612, -0.0608763, -0.974783, -0.464612, 0.0608763, 0.974783, 0.449247, 0.0608763, 0.0606902, -0.464648, 0.97486, -0.974783, 0.449247, -0.0608763, 0.7071, 0.453517, -0.7071, -0.705748, -0.468, -0.705748, -0.7071, 0.453517, 0.7071, 0.7071, 0.453517, 0.7071, 0.705748, -0.468, 0.705748, -0.705748, -0.468, 0.705748, 0.705748, -0.468, -0.705748, -0.7071, 0.453517, -0.7071, 0.0606902, -0.464648, -0.97486, -0.974783, -0.464612, -0.0608763, 0.974783, -0.464612, 0.0608763, -0.0608763, -0.464612, 0.974783, 0.0606902, 0.449283, 0.97486, 0.0606902, 0.449283, -0.97486, 0.974783, 0.449247, -0.0608763, -0.974783, 0.449247, 0.0608763, -0.642208, -0.46642, 0.73398, -0.642208, -0.46642, -0.73398, 0.578116, -0.464071, -0.760529, 0.578116, -0.464071, 0.760529, 0.760589, -0.464107, 0.577971, -0.760589, -0.464107, 0.577971, -0.760589, -0.464107, -0.577971, 0.760589, -0.464107, -0.577971 )
@ -20,12 +18,6 @@ script = ExtResource( 2 )
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.372095, 0 )
mesh = SubResource( 1 )
[node name="Yam" type="MeshInstance" parent="MeshInstance"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.886431, 0 )
visible = false
mesh = SubResource( 3 )
skeleton = NodePath("../../..")
[node name="status_label" type="Label3D" parent="MeshInstance"]
unique_name_in_owner = true
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.737837, 0 )
@ -40,8 +32,12 @@ shape = SubResource( 2 )
[node name="coin_machine" parent="." instance=ExtResource( 3 )]
transform = Transform( 0.540026, 0, 0, 0, 0.571038, 0, 0, 0, 0.497953, 0, 0.418593, 0 )
[node name="item_holder" parent="." instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.991012, 0 )
[node name="grow_timer" type="Timer" parent="."]
one_shot = true
[connection signal="coin_requirement_met" from="coin_machine" to="." method="_on_coin_machine_coin_requirement_met"]
[connection signal="timeout" from="grow_timer" to="." method="_on_Timer_timeout"]
[connection signal="item_changed" from="item_holder" to="." method="_on_item_holder_item_changed"]
[connection signal="timeout" from="grow_timer" to="." method="_on_grow_timer_timeout"]

View File

@ -1,15 +1,11 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=2 format=2]
[ext_resource path="res://scripts/item.gd" type="Script" id=1]
[sub_resource type="CylinderMesh" id=1]
height = 1.0
[node name="item" type="Spatial"]
script = ExtResource( 1 )
[node name="MeshInstance" type="MeshInstance" parent="."]
mesh = SubResource( 1 )
[node name="visual" type="Spatial" parent="."]
[node name="ItemLabel" type="Label3D" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0275149, 0.721019, 1.58046 )

59
scenes/oven.tscn Normal file
View File

@ -0,0 +1,59 @@
[gd_scene load_steps=7 format=2]
[ext_resource path="res://scenes/item_holder.tscn" type="PackedScene" id=1]
[ext_resource path="res://scripts/oven/oven.gd" type="Script" id=2]
[ext_resource path="res://scenes/coin_machine.tscn" type="PackedScene" id=3]
[sub_resource type="SpatialMaterial" id=1]
albedo_color = Color( 0, 0, 0, 1 )
[sub_resource type="CylinderMesh" id=2]
material = SubResource( 1 )
top_radius = 0.5
bottom_radius = 0.5
height = 0.1
radial_segments = 9
[sub_resource type="CubeMesh" id=3]
size = Vector3( 1.362, 0.49, 0.081 )
[node name="oven" type="Spatial"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0063355, 0.00319374, -0.00456095 )
script = ExtResource( 2 )
[node name="CSGBox" type="CSGBox" parent="."]
use_collision = true
width = 1.36825
height = 1.04121
depth = 1.24388
[node name="CSGBox2" type="CSGBox" parent="CSGBox"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.000755012, -0.038668, 0.154754 )
operation = 2
width = 1.20449
height = 0.784214
depth = 1.29741
[node name="coil" type="MeshInstance" parent="CSGBox"]
unique_name_in_owner = true
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.00424552, 0.556925, -0.00761187 )
mesh = SubResource( 2 )
skeleton = NodePath("../..")
[node name="item_holder" parent="CSGBox/coil" instance=ExtResource( 1 )]
unique_name_in_owner = true
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00424552, 0.29638, 0.00761187 )
[node name="backsplash" type="MeshInstance" parent="CSGBox"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.00424552, 0.556925, -0.575066 )
mesh = SubResource( 3 )
skeleton = NodePath("../..")
[node name="coin_machine" parent="." instance=ExtResource( 3 )]
[node name="cook_timer" type="Timer" parent="."]
one_shot = true
[connection signal="item_changed" from="CSGBox/coil/item_holder" to="." method="_on_item_holder_item_changed"]
[connection signal="coin_requirement_met" from="coin_machine" to="." method="_on_coin_machine_coin_requirement_met"]
[connection signal="timeout" from="cook_timer" to="." method="_on_cook_timer_timeout"]

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=8 format=2]
[ext_resource path="res://scripts/Player.gd" type="Script" id=1]
[ext_resource path="res://assets/protodungman/DungMan.glb" type="PackedScene" id=2]
@ -11,11 +11,23 @@ extents = Vector3( 0.25, 0.25, 1 )
radius = 0.210213
height = 0.85525
[sub_resource type="Gradient" id=4]
offsets = PoolRealArray( 0, 0.776119, 1 )
colors = PoolColorArray( 0, 0, 0, 1, 0, 0, 0, 0.429105, 0, 0, 0, 0 )
[sub_resource type="GradientTexture2D" id=5]
gradient = SubResource( 4 )
fill_to = Vector2( 0, 1 )
[node name="Player" type="KinematicBody"]
script = ExtResource( 1 )
[node name="DungMan" parent="." instance=ExtResource( 2 )]
[node name="ItemSpawn" type="Spatial" parent="DungMan"]
unique_name_in_owner = true
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.6244, 0 )
[node name="TriggerVolume" type="Area" parent="DungMan"]
unique_name_in_owner = true
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.630386 )
@ -32,17 +44,19 @@ shape = SubResource( 2 )
transform = Transform( 1, 0, 0, 0, 0.5, 0.866025, 0, -0.866025, 0.5, 0, 5.44166, 3.39746 )
fov = 50.0
[node name="ItemSpawn" type="Spatial" parent="."]
[node name="UI" type="CanvasLayer" parent="."]
[node name="Control" type="Control" parent="UI"]
margin_right = 40.0
margin_bottom = 40.0
[node name="TextureRect" type="TextureRect" parent="UI/Control"]
margin_right = 565.0
margin_bottom = 164.0
texture = SubResource( 5 )
expand = true
[node name="MarginContainer" type="MarginContainer" parent="UI/Control"]
margin_right = 128.0
margin_bottom = 128.0
custom_constants/margin_right = 16
custom_constants/margin_top = 16
custom_constants/margin_left = 16

10
scripts/ItemType.gd Normal file
View File

@ -0,0 +1,10 @@
extends Resource
class_name ItemType
export var name: String
export var visual_scene: PackedScene
func spawn_node() -> Spatial:
var node = preload("res://scenes/item.tscn").instance()
node.set_item_type(self)
return node

View File

@ -87,7 +87,7 @@ func try_trigger_interact(area):
func drop_item_in_hand():
print("player dropped ", item_in_hand.item_name)
var item_dropped = item_in_hand
$ItemSpawn.remove_child(item_in_hand)
$"%ItemSpawn".remove_child(item_in_hand)
item_in_hand = null
return item_dropped
@ -96,10 +96,13 @@ func pick_up_item(item):
if item_in_hand != null:
item_dropped = drop_item_in_hand()
item_in_hand = item
$ItemSpawn.add_child(item_in_hand)
$"%ItemSpawn".add_child(item_in_hand)
print("player picked up ", item_in_hand.item_name)
return item_dropped
func has_item() -> bool:
return item_in_hand != null
func get_item_in_hand():
var item_to_return = null
if item_in_hand != null:

6
scripts/Recipe.gd Normal file
View File

@ -0,0 +1,6 @@
extends Resource
class_name Recipe
export var item_type_in_1: Resource
export var item_type_in_2: Resource
export var item_type_out: Resource

10
scripts/RecipeDB.gd Normal file
View File

@ -0,0 +1,10 @@
extends Resource
class_name RecipeDB
export(Array, Resource) var recipes
func find_recipe(item_type_1: Resource, item_type_2: Resource) -> Resource:
for recipe in recipes:
pass
# TODO, find recipe
return recipes[0] # This is just stubbed; remove later

View File

@ -2,6 +2,36 @@ extends Spatial
export var grow_time: float = 2.0
class GrowerStateIdle:
func _on_coin_machine_coin_requirement_met(player):
pass
func _on_grow_timer_timeout():
pass
func _on_item_holder_item_changed(item):
pass
class GrowerStateGrowing:
func _on_coin_machine_coin_requirement_met(player):
pass
func _on_grow_timer_timeout():
pass
func _on_item_holder_item_changed(item):
pass
class GrowerStateBlocked:
func _on_coin_machine_coin_requirement_met(player):
pass
func _on_grow_timer_timeout():
pass
func _on_item_holder_item_changed(item):
pass
func _ready():
$grow_timer.wait_time = grow_time
@ -10,7 +40,7 @@ func _on_coin_machine_coin_requirement_met(player):
$coin_machine.enabled = false
$grow_timer.start()
func _on_Timer_timeout():
func _on_grow_timer_timeout():
var yam = preload("res://scenes/item_pickup.tscn").instance()
yam.item_name = "yam"
yam.item_amount = 1
@ -25,3 +55,6 @@ func _on_yam_item_tree_exited():
func _process(delta):
$"%status_label".text = "%f" % $grow_timer.time_left
func _on_item_holder_item_changed(item):
pass # Replace with function body.

View File

@ -0,0 +1,32 @@
extends Spatial
const StateIdle = preload("res://scripts/hydroponics_station/state/idle.gd")
const StateGrowing = preload("res://scripts/hydroponics_station/state/growing.gd")
const StateBlocked = preload("res://scripts/hydroponics_station/state/blocked.gd")
export var grow_time: float = 2.0
var state = null
func _ready():
$grow_timer.wait_time = grow_time
state = StateIdle.new()
state.ctx = self
state.enter_from(null)
print("hydroponics_station: NULL -> ", state.NAME)
func change_state(new_state):
print("hydroponics_station: ", state.NAME, " -> ", new_state.NAME)
new_state.ctx = self
state.exit_to(new_state)
new_state.enter_from(state)
state = new_state
func _on_coin_machine_coin_requirement_met(player):
state.on_coin_machine_coin_requirement_met(player)
func _on_grow_timer_timeout():
state.on_grow_timer_timeout()
func _on_item_holder_item_changed(item):
state.on_item_holder_item_changed(item)

View File

@ -0,0 +1,25 @@
extends Reference
const NAME = "blocked"
var ctx = null
func _init():
pass
func enter_from(state):
ctx.get_node("coin_machine").enabled = false
ctx.get_node("item_holder").add_enabled = true
func exit_to(state):
pass
func on_coin_machine_coin_requirement_met(player):
assert(false)
func on_grow_timer_timeout():
assert(false)
func on_item_holder_item_changed(item):
if item == null:
ctx.change_state(ctx.StateIdle.new())

View File

@ -0,0 +1,30 @@
extends Reference
const NAME = "growing"
const raw_yam = preload("res://item_types/raw_yam.tres")
var ctx = null
var mat: SpatialMaterial = SpatialMaterial.new()
func _init():
mat.albedo_color = Color.green
func enter_from(state):
ctx.get_node("coin_machine").enabled = false
ctx.get_node("item_holder").add_enabled = false
ctx.get_node("grow_timer").start()
ctx.get_node("MeshInstance").set_surface_material(0, mat)
func exit_to(state):
ctx.get_node("MeshInstance").set_surface_material(0, null)
func on_coin_machine_coin_requirement_met(player):
assert(false, "coin machine should be disabled while growing")
func on_grow_timer_timeout():
var item_holder = ctx.get_node("item_holder")
item_holder.spawn_item(raw_yam)
ctx.change_state(ctx.StateBlocked.new())
func on_item_holder_item_changed(item):
assert(item.item_type == raw_yam)

View File

@ -0,0 +1,25 @@
extends Reference
const NAME = "idle"
var ctx = null
func _init():
pass
func enter_from(state):
ctx.get_node("coin_machine").enabled = true
ctx.get_node("item_holder").add_enabled = true
func exit_to(state):
pass
func on_coin_machine_coin_requirement_met(player):
ctx.change_state(ctx.StateGrowing.new())
func on_grow_timer_timeout():
assert(false, "grow timer shouldn't trigger while idle")
func on_item_holder_item_changed(item):
assert(item != null)
ctx.change_state(ctx.StateBlocked.new())

View File

@ -1,8 +1,15 @@
extends Spatial
export var item_name : String = ""
export var item_type: Resource setget set_item_type
var item_name: String
# Called when the node enters the scene tree for the first time.
func _ready():
assert(item_name != "")
$ItemLabel.text = "Item: %s" % item_name
func set_item_type(new_value: Resource):
item_type = new_value
if not is_inside_tree():
yield(self, "ready")
item_name = item_type.name
$ItemLabel.text = item_type.name
for child in $visual.get_children():
child.queue_free()
$visual.add_child(item_type.visual_scene.instance())

View File

@ -1,17 +1,21 @@
extends Spatial
signal item_changed(item)
export var start_with_item : String = ""
export var start_with_item : Resource
export var remove_enabled := true
export var add_enabled := true
var item_in_hold
# Called when the node enters the scene tree for the first time.
func _ready():
if start_with_item != "":
var item_instance = preload("res://scenes/item.tscn").instance()
item_instance.item_name = start_with_item
add_item(item_instance)
if start_with_item != null:
add_item(start_with_item.spawn_node())
func remove_item():
func has_item() -> bool:
return item_in_hold != null
func remove_item() -> Node:
assert(item_in_hold != null)
var removed_item = item_in_hold
$ItemSpawn.remove_child(item_in_hold)
@ -23,7 +27,62 @@ func add_item(item):
$ItemSpawn.add_child(item)
item_in_hold = item
func spawn_item(item_type: Resource):
assert(!has_item())
assert(item_type is ItemType)
add_item(item_type.spawn_node())
emit_signal("item_changed", item_in_hold)
func destroy_item():
var removed_item = item_in_hold
$ItemSpawn.remove_child(item_in_hold)
item_in_hold = null
removed_item.queue_free()
emit_signal("item_changed", item_in_hold)
func swap_with_player(player) -> bool:
assert(has_item() and player.has_item())
if not remove_enabled or not add_enabled:
return false
var player_item = player.drop_item_in_hand()
player.pick_up_item(remove_item())
add_item(player_item)
$AudioStreamPlayer.play()
emit_signal("item_changed", item_in_hold)
return true
func give_to_player(player) -> bool:
assert(has_item() and not player.has_item())
if not remove_enabled:
return false
var player_item = player.pick_up_item(remove_item())
$AudioStreamPlayer.play()
emit_signal("item_changed", item_in_hold)
return true
func take_from_player(player) -> bool:
assert(not has_item() and player.has_item())
if not add_enabled:
return false
add_item(player.drop_item_in_hand())
$AudioStreamPlayer.play()
emit_signal("item_changed", item_in_hold)
return true
func on_player_interact(player) -> bool:
if has_item() and player.has_item():
return swap_with_player(player)
elif has_item() and not player.has_item():
return give_to_player(player)
elif not has_item() and player.has_item():
return take_from_player(player)
var player_item = player.get_item_in_hand()
if item_in_hold == null:
if player_item == null:

32
scripts/oven/oven.gd Normal file
View File

@ -0,0 +1,32 @@
extends Spatial
const StateIdle = preload("res://scripts/oven/state/idle.gd")
const StateCooking = preload("res://scripts/oven/state/cooking.gd")
const StateHoldingItem = preload("res://scripts/oven/state/holding_item.gd")
export var cook_time: float = 2.0
var state = null
func _ready():
$cook_timer.wait_time = cook_time
state = StateIdle.new()
state.ctx = self
state.enter_from(null)
print("hydroponics_station: NULL -> ", state.NAME)
func change_state(new_state):
print("hydroponics_station: ", state.NAME, " -> ", new_state.NAME)
new_state.ctx = self
state.exit_to(new_state)
new_state.enter_from(state)
state = new_state
func _on_coin_machine_coin_requirement_met(player):
state.on_coin_machine_coin_requirement_met(player)
func _on_cook_timer_timeout():
state.on_cook_timer_timeout()
func _on_item_holder_item_changed(item):
state.on_item_holder_item_changed(item)

View File

@ -0,0 +1,33 @@
extends Reference
const NAME = "cooking"
const cooked_yam = preload("res://item_types/cooked_yam.tres")
var ctx = null
var mat: SpatialMaterial = SpatialMaterial.new()
func _init():
mat.albedo_color = Color.red
func enter_from(state):
ctx.get_node("coin_machine").enabled = false
ctx.get_node("%item_holder").add_enabled = false
ctx.get_node("%item_holder").remove_enabled = false
ctx.get_node("cook_timer").start()
ctx.get_node("%coil").set_surface_material(0, mat)
func exit_to(state):
ctx.get_node("%coil").set_surface_material(0, null)
func on_coin_machine_coin_requirement_met(player):
assert(false, "coin machine should be disabled while growing")
func on_cook_timer_timeout():
var item_holder = ctx.get_node("%item_holder")
item_holder.destroy_item()
item_holder.spawn_item(cooked_yam)
ctx.change_state(ctx.StateHoldingItem.new())
func on_item_holder_item_changed(item):
assert(item == null || item.item_type == cooked_yam)

View File

@ -0,0 +1,35 @@
extends Reference
const NAME = "holding_item"
const raw_yam = preload("res://item_types/raw_yam.tres")
var ctx = null
func _init():
pass
func enter_from(state):
if ctx.get_node("%item_holder").item_in_hold.item_type == raw_yam:
ctx.get_node("coin_machine").enabled = true
ctx.get_node("%item_holder").add_enabled = false
ctx.get_node("%item_holder").remove_enabled = false
else:
ctx.get_node("coin_machine").enabled = false
ctx.get_node("%item_holder").add_enabled = true
ctx.get_node("%item_holder").remove_enabled = true
func exit_to(state):
pass
func on_coin_machine_coin_requirement_met(player):
if ctx.get_node("%item_holder").item_in_hold.item_type == raw_yam:
ctx.change_state(ctx.StateCooking.new())
func on_cook_timer_timeout():
assert(false)
func on_item_holder_item_changed(item):
if item == null:
ctx.change_state(ctx.StateIdle.new())
else:
ctx.change_state(ctx.StateHoldingItem.new())

View File

@ -0,0 +1,26 @@
extends Reference
const NAME = "idle"
var ctx = null
func _init():
pass
func enter_from(state):
ctx.get_node("coin_machine").enabled = false
ctx.get_node("%item_holder").add_enabled = true
ctx.get_node("%item_holder").remove_enabled = false # not possible
func exit_to(state):
pass
func on_coin_machine_coin_requirement_met(player):
assert(false, "coin machine should be disabled while idle")
func on_cook_timer_timeout():
assert(false, "cook timer shouldn't trigger while idle")
func on_item_holder_item_changed(item):
assert(item != null, "there should be no item to remove while idle")
ctx.change_state(ctx.StateHoldingItem.new())