blob: a37221a6b592d67c8c487b69c5e77afb5aabbd42 (
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
|
extends Object
const Wrld = preload("res://world.tscn")
const Items = preload("res://scripts/items.gd")
var items = null
func _init():
self.items = Items.new()
func build(where):
var w = Wrld.instance()
w.set_scale(Vector3(0.02, 0.02, 0.02))
w.set_translation(where)
return w
func can_combine(materials):
var has_solid = false
var has_gas = false
for id in materials:
var category = self.items.category(id)
if category == "solid":
has_solid = true
if category == "gas":
has_gas = true
return has_solid and has_gas
func combine(where, materials):
var w = build(where)
var mass = 0
var volume = 0
var color = Color(0.3,0.3,0.3)
var gas_mass = 0
var gas_volume = 0
var gas_color = Color(0.5,0.5,0.6,0.4)
var cost = 0
for mat in materials:
var item = self.items.get(mat)
var category = self.items.category(mat)
if category == "solid":
mass += item.data["mass"]
volume += item.data["volume"]
var s = item.data["color"]
color = color.blend(Color(s))
if category == "gas":
gas_mass += item.data["mass"]
gas_volume += item.data["volume"]
var s = item.data["color"]
gas_color = gas_color.blend(Color(s))
cost += item.data["cost"]
w.materials = materials
w.mass = mass
w.volume = volume
w.color = color
w.gas_mass = gas_mass
w.gas_volume = gas_volume
w.gas_color = gas_color
w.total_mass = mass + gas_mass
w.total_volume = volume + gas_volume
w.cost = cost
w.call_deferred("build")
return w
|