14bf61d05d37eb1a1012496a1c1595dd1e471a99
[koperkapel.git] / koperkapel / gamelib / items.py
1 # Item utilities
2
3 from ..serums import default_serums
4 from ..weapons import default_weapons
5 from ..vehicles.base import Vehicle
6
7
8 def build_serum(item):
9     actor = default_serums.assemble(item["serum"])
10     return actor
11
12
13 def build_weapon(item):
14     actor = default_weapons.assemble(item["weapon"])
15     return actor
16
17 def build_vehicle(item):
18     actor = Vehicle.by_type(item["vehicle"]).get_avatar(dead=True)
19     return actor
20
21
22 ITEM_BUILDERS = {
23     "serum": build_serum,
24     "weapon": build_weapon,
25     "vehicle": build_vehicle,
26 }
27
28
29 def get_item(item):
30     item_type = item.pop("type")
31     game_pos = tuple(item.pop("pos"))
32     actor = ITEM_BUILDERS[item_type](item)
33     actor.item_type = item_type
34     actor.item_data = item
35     actor.game_pos = game_pos
36     actor.anchor = (0, 0)
37     return actor
38
39
40 def clone_old_item(item, **new_data):
41     new_item = {
42         "type": item.item_type,
43         "pos": item.game_pos,
44     }
45     new_item.update(item.item_data)
46     new_item.update(new_data)
47     return get_item(new_item)
48
49
50 def create_new_item(item_type, pos, **kwd):
51     new_item = {
52         "type": item_type,
53         "pos": pos,
54     }
55     new_item.update(kwd)
56     return get_item(new_item)