-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TreeDecoration.gd
83 lines (75 loc) · 2.8 KB
/
TreeDecoration.gd
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
@tool
extends StaticBody2D
enum COLOR {
ORANGE,
BLUE,
BONZAI,
STATUE
}
const TREE_SPRITES := {
COLOR.ORANGE: [
preload("res://sprites/misc/trees/orange/puzzle_1.png"),
preload("res://sprites/misc/trees/orange/puzzle_2.png"),
preload("res://sprites/misc/trees/orange/puzzle_3.png"),
preload("res://sprites/misc/trees/orange/puzzle_4.png"),
preload("res://sprites/misc/trees/orange/puzzle_5.png"),
preload("res://sprites/misc/trees/orange/tree_6.png"),
preload("res://sprites/misc/trees/orange/tree_7.png"),
preload("res://sprites/misc/trees/orange/tree_8.png"),
preload("res://sprites/misc/trees/orange/tree_9.png"),
preload("res://sprites/misc/trees/orange/tree_10.png"),
preload("res://sprites/misc/trees/orange/tree_11.png"),
preload("res://sprites/misc/trees/orange/tree_12.png"),
preload("res://sprites/misc/trees/orange/tree_13.png"),
preload("res://sprites/misc/trees/orange/tree_14.png"),
preload("res://sprites/misc/trees/orange/tree_15.png"),
preload("res://sprites/misc/trees/orange/tree_16.png"),
preload("res://sprites/misc/trees/orange/tree_17.png"),
preload("res://sprites/misc/trees/orange/tree_18.png"),
preload("res://sprites/misc/trees/orange/tree_19.png"),
preload("res://sprites/misc/trees/orange/tree_20.png"),
preload("res://sprites/misc/trees/orange/tree_21.png"),
preload("res://sprites/misc/trees/orange/tree_22.png"),
preload("res://sprites/misc/trees/orange/tree_23.png"),
preload("res://sprites/misc/trees/orange/tree_24.png"),
preload("res://sprites/misc/trees/orange/tree_25.png"),
],
COLOR.BLUE: [
preload("res://sprites/misc/trees/blue/tree_1.png"),
preload("res://sprites/misc/trees/blue/tree_2.png"),
preload("res://sprites/misc/trees/blue/tree_3.png"),
preload("res://sprites/misc/trees/blue/tree_4.png"),
],
COLOR.BONZAI: [
preload("res://sprites/misc/trees/orange/bonzai_1.png"),
],
COLOR.STATUE: [
preload("res://sprites/misc/statue2.png"),
preload("res://sprites/misc/first.png"),
preload("res://sprites/misc/second.png"),
preload("res://sprites/misc/latter.png"),
]
}
@export var species: COLOR = COLOR.ORANGE
@export var force_id := -1
@export var flip := false
func _ready() -> void:
set_style()
func _process(_delta: float) -> void:
if Engine.is_editor_hint():
set_style()
else:
set_process(false)
func set_style():
var id_to_use := force_id
var flip_to_use := flip
if id_to_use <= -1:
id_to_use = hash(global_position)%TREE_SPRITES[species].size()
if hash(global_position)%2 == 0:
flip_to_use = true
else:
flip_to_use = false
$Sprite2D.texture = TREE_SPRITES[species][id_to_use]
$Sprite2D.offset.y = - $Sprite2D.texture.get_height() / 2.0 + 5.0
$Sprite2D/VisibleOnScreenEnabler2D.rect.position.y = - $Sprite2D.texture.get_height()
$Sprite2D.flip_h = flip_to_use