Skip to content

Commit 49b19a7

Browse files
committed
Merge branch 'master' into menu
2 parents ccacd57 + 0d8e157 commit 49b19a7

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

Defold/scripts/customer.script.script

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,60 @@ end
66

77
function delete_items(items)
88
if items then
9-
for _, id in pairs(items) do
10-
go.delete(id)
9+
for _, v in pairs(items) do
10+
go.delete(v.id)
1111
end
1212
end
1313
end
1414

1515
function update_item_positions(items)
1616
if items then
1717
local position = go.get_position();
18-
for pos, id in pairs(items) do
19-
msg.post(id, "Game State", {x = position.x, y = position.y - (pos-1) * 20})
18+
for k,v in pairs(items) do
19+
msg.post(v.id, "Game State", {x = position.x, y = position.y - (v.pos-1) * 20})
2020
end
2121
end
2222
end
2323

24+
function update_item_text(items,wants)
25+
for k,v in pairs(items) do
26+
if wants[k] then
27+
msg.post(v.id, "Game State", { amount = wants[k], item = k})
28+
else
29+
msg.post(v.id, "Game State", {amount = 0})
30+
end
31+
end
32+
end
33+
34+
function add_item(self, type, ammount)
35+
local position = go.get_position();
36+
created_id = factory.create("#order_factory", vmath.vector3(position.x , position.y- self.item_count * 20,0.1), vmath.quat(),{},1)
37+
if created_id then
38+
self.order = true
39+
msg.post(created_id, "Game State", {item = type, amount = ammount})
40+
self.item_count = self.item_count + 1
41+
self.items[type] = { id = created_id , pos = self.item_count}
42+
end
43+
end
44+
2445
function on_message(self, message_id, message, sender)
2546
if message.sprite_id then
2647
sprite.play_flipbook("#sprite",hash("Customer_".. message.sprite_id))
2748
end
49+
50+
if message.order and self.order then
51+
update_item_text(self.items,message.order)
52+
end
53+
if message.order and not self.order then
54+
--delete_items(self.items)
55+
for k, v in pairs(message.order) do
56+
if k ~= '__keys' then
57+
add_item(self, k, v)
58+
end
59+
end
60+
self.item_count = 1
61+
add_item(self, "Money", 0)
62+
end
2863
if message.y then
2964
local position = go.get_position();
3065
position.y = message.y;
@@ -41,23 +76,6 @@ function on_message(self, message_id, message, sender)
4176
if message.type then
4277
--sprite.play_flipbook("#sprite",hash(message.type))
4378
end
44-
if message.order and not self.order then
45-
--delete_items(self.items)
46-
for k, v in pairs(message.order) do
47-
if k ~= '__keys' then
48-
local position = go.get_position();
49-
created_id = factory.create("#order_factory", vmath.vector3(position.x , position.y- self.item_count * 20,0.1), vmath.quat(),{},1)
50-
if created_id then
51-
self.order = true
52-
msg.post(created_id, "Game State", {item = k, amount = v})
53-
table.insert(self.items, created_id)
54-
self.item_count = self.item_count +1
55-
end
56-
57-
end
58-
end
59-
end
60-
6179
end
6280

6381

Defold/scripts/order_item.script

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ function on_message(self, message_id, message, sender)
77
--sprite.play_flipbook("#sprite",hash(message.item))
88
end
99
if message.amount then
10-
label.set_text("#label", message.amount .. "x " .. message.item)
10+
if (message.amount == 0) then
11+
label.set_text("#label", "")
12+
else
13+
label.set_text("#label", message.amount .. "x " .. message.item)
14+
end
1115
end
1216

1317
if message.x then

Defold/scripts/player.script

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ function on_input(self, action_id, action)
3737
msg.post(game_controller, "drop");
3838
elseif action_id == hash("use") then
3939
msg.post(game_controller, "use");
40-
print('use')
4140
elseif action_id == hash("refill") then --just for testing
4241
msg.post(game_controller, "refill", {item = "all"});
4342
end

0 commit comments

Comments
 (0)