aboutsummaryrefslogtreecommitdiff
path: root/client/map/tiles/tile.gd
blob: 7cf7be9bfa947e80ecc6a01e09ebd68732681953 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Hurry Curry! - a game about cooking
# Copyright (C) 2025 Hurry Curry! contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
class_name Tile
extends Node3D

var base = Node3D.new()
var base_mesh
var item: Item = null
var item_base: Node3D

enum Facing {
	NEG_Y = 0,
	NEG_X = 1,
	Y = 2,
	X = 3,
}

func _init(ctx: TileFactory.TileCC):
	base.name = "Base"
	base.position += Vector3(0.5, 0, 0.5)
	add_child(base)
	self.name = str(ctx.position)
	var item_base_ = Node3D.new()
	# this method is supposed to be overriden
	@warning_ignore("static_called_on_instance")
	item_base_.position = interact_target()
	item_base_.name = "ItemBase"
	base.add_child(item_base_)
	item_base = item_base_
	base_mesh = get_base_mesh()
	if base_mesh != null:
		var m: Node3D = base_mesh
		m.position += Vector3(0.5, 0, 0.5)
		add_child(m)

func turn_facing(facing: Facing):
	base.rotation.y = facing * 0.5 * PI + PI

# defines where items go when interacting
static func interact_target() -> Vector3:
	return Vector3(0, 0, 0)

# actions when interacting, e.g. animations
func interact():
	pass

func progress(position_: float, speed: float, warn: bool, _acting_player):
	if item != null:
		item.progress(position_, speed, warn)

func finish():
	if item != null:
		item.finish()

func put_item(i: Item):
	if item != null:
		push_error("already holding an item")
	set_item(i)

func pass_to(tile: Tile):
	var i = take_item()
	if tile.item != null:
		push_error("target is already holding an item")
	tile.set_item(i)

func set_item(i: Item):
	if item != null: item.remove()
	item = i
	if i != null: i.owned_by = item_base

func take_item() -> Item:
	var i = item
	item = null
	return i

func get_base_mesh():
	return null