Mercurial > parpg-source
annotate systems/container.py @ 16:5c587a0d9ad7
Added clause when the containable should just be added to end of the list
author | KarstenBock@gmx.net |
---|---|
date | Mon, 01 Aug 2011 08:44:31 +0200 |
parents | a9019d0ac5f8 |
children | 702ee8e475df |
rev | line source |
---|---|
14 | 1 # This program is free software: you can redistribute it and/or modify |
2 # it under the terms of the GNU General Public License as published by | |
3 # the Free Software Foundation, either version 3 of the License, or | |
4 # (at your option) any later version. | |
5 # | |
6 # This program is distributed in the hope that it will be useful, | |
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9 # GNU General Public License for more details. | |
10 # | |
11 # You should have received a copy of the GNU General Public License | |
12 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
13 | |
14 from parpg.grease import System | |
15 from parpg.components import container | |
16 | |
17 class Container(System): | |
18 """System that controls changes to containers""" | |
19 | |
20 def __init__(self, drag_container, | |
21 container_component="container", | |
22 containable_component="containable" | |
23 ): | |
24 """Constructor""" | |
25 self.drag_container = drag_container | |
26 self.container_component = container_component | |
27 self.containable_component = containable_component | |
28 self.on_bulk_to_big = [] | |
29 | |
30 def step(self, dt): | |
31 """Perform changes to containers and items""" | |
32 assert self.world is not None, "Cannot run with no world set" | |
33 for containable in self.world.components.join( | |
34 self.containable_component | |
35 ): | |
36 if containable.new_container: | |
37 new_container = containable.new_container | |
38 new_slot = containable.new_slot | |
39 bulk_add = containable.bulk | |
40 if new_slot >= 0 and new_slot < len(new_container.children): | |
41 bulk_add -= new_container.children[new_slot].bulk | |
42 elif new_slot >= len(new_container.children): | |
43 new_slot = -1 | |
44 bulk = get_bulk(new_container) + bulk_add | |
45 if bulk < new_container.max_bulk: | |
46 if new_slot >= 0: | |
47 new_container.children.insert(new_slot + 1, containable) | |
48 containable.current_container = new_container | |
49 old_containable = new_container.children.pop(new_slot) | |
50 old_containable.current_container = drag_container | |
16
5c587a0d9ad7
Added clause when the containable should just be added to end of the list
KarstenBock@gmx.net
parents:
14
diff
changeset
|
51 drag_container.children.append(old_containable) |
5c587a0d9ad7
Added clause when the containable should just be added to end of the list
KarstenBock@gmx.net
parents:
14
diff
changeset
|
52 else: |
5c587a0d9ad7
Added clause when the containable should just be added to end of the list
KarstenBock@gmx.net
parents:
14
diff
changeset
|
53 new_container.append(containable) |
5c587a0d9ad7
Added clause when the containable should just be added to end of the list
KarstenBock@gmx.net
parents:
14
diff
changeset
|
54 containable.current_container = new_container |
14 | 55 else: |
56 for listener in self.on_bulk_to_big: | |
57 listener(bulk, new_container.max_bulk) | |
58 | |
59 |