-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodels.py
executable file
·844 lines (696 loc) · 26.1 KB
/
models.py
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
import base64
import os
import zlib
from kivy.app import App
from sqlalchemy import create_engine, Column, Integer, String, ForeignKey
from sqlalchemy.ext.mutable import Mutable
from sqlalchemy.orm import sessionmaker, relationship
from sqlalchemy.ext.declarative import declarative_base
from genericpath import exists
import sys
import struct
from xml.etree import ElementTree
from rect import Rect
from kivy.uix.image import Image
from sqlalchemy.types import PickleType
import heapq
from sqlalchemy.orm.session import object_session
Base = declarative_base()
MAP_PATH = os.path.join(os.path.dirname(__file__), 'maps/')
if not exists(MAP_PATH):
os.mkdir(MAP_PATH) # If the directory doesn't exist, create it before returning the path
class MutableDict(Mutable, dict):
@classmethod
def coerce(cls, key, value):
if not isinstance(value, MutableDict):
if isinstance(value, dict):
return MutableDict(value)
return Mutable.coerce(key, value)
else:
return value
def __delitem(self, key):
dict.__delitem__(self, key)
self.changed()
def __setitem__(self, key, value):
dict.__setitem__(self, key, value)
self.changed()
def __getstate__(self):
return dict(self)
def __setstate__(self, state):
self.update(self)
class Model(Base):
"""Base model class that includes CRUD convenience methods."""
__abstract__ = True
@classmethod
def create(cls, **kwargs):
"""Create a new record and save it the database."""
# print(kwargs)
instance = cls(**kwargs)
return instance.save()
def update(self, commit=True, **kwargs):
"""Update specific fields of a record."""
for attr, value in kwargs.iteritems():
setattr(self, attr, value)
return commit and self.save() or self
def save(self, commit=True):
"""Save the record."""
db = object_session(self)
db.add(self)
if commit:
db.commit()
return self
def delete(self, commit=True, *args, **kwargs):
"""Remove the record from the database."""
db = object_session(self)
db.add(self)
db.delete(self)
return commit and db.commit()
@property
def data(self):
dict_ = {}
for key in self.__mapper__.c.keys():
dict_[key] = getattr(self, key)
return dict_
class Item(Model):
__tablename__ = 'item'
id = Column(Integer, primary_key=True)
name = Column(String(64))
type = Column(String(64))
image = Column(String(64))
category = Column(Integer)
identification_level = Column(Integer)
internal_value = Column(Integer)
required_equip = Column(Integer)
class GameFlag(Model):
__tablename__ = 'game_flags'
name = Column(String(64), primary_key=True)
value = Column(String(64))
class TileMap(Model):
# switch the tilemap xml loading to have that data in db sometime in future. For now, read from tmx files.
__tablename__ = 'maps'
id = Column(Integer, primary_key=True)
file_name = Column(String(32))
full_name = Column(String(64))
height = Column(Integer)
width = Column(Integer)
fog_of_war = Column(MutableDict.as_mutable(PickleType))
objects = relationship('MapObject')
def resize_view(self, x, y):
self.view_w = x
self.view_h = y
def recenter(self, w, h):
self.view_w, self.view_h = (w, h) # viewport size
self.viewport = Rect(*(self.view_x, self.view_y) + (self.view_w, self.view_h))
def load(self, viewport_size=(100, 100), viewport_origin=(0, 0)):
print('loading tilemap db object now')
filename = 'maps/{}'.format(self.file_name)
self.properties = {}
self.layers = Layers()
self.tilesets = Tilesets()
self.fx, self.fy = 0, 0 # viewport focus point
self.view_w, self.view_h = viewport_size # viewport size
self.view_x, self.view_y = viewport_origin # viewport offset
self.viewport = Rect(*(viewport_origin + viewport_size))
with open(filename) as f:
xml = ElementTree.fromstring(f.read())
print('xml found')
# get most general map information and create a surface
self.tile_width = int(xml.attrib['tilewidth'])
self.tile_height = int(xml.attrib['tileheight'])
self.px_width = self.width * self.tile_width
self.px_height = self.height * self.tile_height
self.file_path = os.path.dirname(filename)
for tag in xml.findall('tileset'):
self.tilesets.add(Tileset.fromxml(tag, self))
print('tilesets loaded', self.tilesets)
for tag in xml.findall('layer'):
layer = Layer.fromxml(tag, self)
self.layers.add_named(layer, layer.name)
print('layers loaded', self.layers)
if not self.fog_of_war:
self.generate_fog()
self.save()
def save(self, commit=True):
# fog_of_war = self.fog_of_war
# self.fog_of_war = None
# self.fog_of_war = fog_of_war
super(TileMap, self).save(commit)
def generate_fog(self):
self.fog_of_war = dict()
for c in self.layers.by_name['below'].cells:
self.fog_of_war.update({c: True})
def update(self, dt, *args):
for layer in self.layers:
layer.update(dt, *args)
_old_focus = None
def force_focus(self, fx, fy):
"""Force the manager to focus on a point, regardless of any managed layer
visible boundaries.
"""
self.fx, self.fy = fx, fy
# get our view size
w = self.view_w
h = self.view_h
w2, h2 = w // 2, h // 2
# bottom-left corner of the viewport
x, y = fx - w2, fy - h2
self.viewport.x = x
self.viewport.y = y
self.childs_ox = x - self.view_x
self.childs_oy = y - self.view_y
self.set_view(x, y, w, h)
def set_view(self, x, y, w, h):
# for layer in self.layers:
# print(layer.name)
self.layers.by_name['below'].set_view(x, y, w, h, self.view_x, self.view_y)
def pixel_from_screen(self, x, y):
"""Look up the Layer-space pixel matching the screen-space pixel.
"""
vx, vy = self.childs_ox, self.childs_oy
return int(vx + x), int(vy + y)
def pixel_to_screen(self, x, y):
"""Look up the screen-space pixel matching the Layer-space pixel.
"""
screen_x = x - self.childs_ox
screen_y = y - self.childs_oy
return int(screen_x), int(screen_y)
def index_at(self, x, y):
"""Return the map index at the (screen-space) pixel position.
"""
sx, sy = self.pixel_from_screen(x, y)
return int(sx // self.tile_width), int(sy // self.tile_height)
def save_data(self):
for map_object in self.objects: # probably turn this into a save method instead?
map_object.save()
for object_property in map_object.properties:
self.db.add(object_property)
self.db.commit()
class MapObject(Model):
__tablename__ = 'mapobjects'
id = Column(Integer, primary_key=True)
map_id = Column(Integer, ForeignKey('maps.id'))
name = Column(String(64))
type = Column(String(32))
x = Column(Integer)
y = Column(Integer)
height = Column(Integer)
width = Column(Integer)
object_properties = relationship('MapObjectProperty')
map = relationship('TileMap')
@property
def properties(self):
dict_ = {}
for prop in self.object_properties:
dict_[prop.property] = prop.value
return dict_
def __repr__(self):
return '<Object %s,%s %s,%s>' % (self.x, self.y, self.width, self.height)
@classmethod
def query(cls, **kwargs):
query = App.get_running_app().db.query(cls)
if 'type' in kwargs:
query.filter(cls.type == kwargs['type'])
return query.all()
class MapObjectProperty(Model):
__tablename__ = 'mapobjectproperties'
id = Column(Integer, primary_key=True)
object_id = Column(Integer, ForeignKey('mapobjects.id'))
property = Column(String(64))
value = Column(String(1024)) #make this whatever the dialogue display's max for one panel is, probably less than 1024
class PriorityQueue:
def __init__(self):
self.elements = []
def empty(self):
return len(self.elements) == 0
def put(self, item, priority):
# priority is only living on the object to work around python3 comparison logic
item.priority = priority
heapq.heappush(self.elements, item)
def get(self):
return heapq.heappop(self.elements)
class GridWithWeights(object):
def __init__(self, layer):
self.layer = layer
self.weights = {}
def cost(self, from_node, to_node):
return self.weights.get(to_node, 1)
def heuristic(a, b):
(x1, y1) = a.x, a.y
(x2, y2) = b.x, b.y
return abs(x1 - x2) + abs(y1 - y2)
def reconstruct_path(came_from, start, goal):
current = goal
path = [current]
# print(came_from, start, goal)
while current != start:
current = came_from[current]
# print('iteration')
path.append(current)
path.reverse()
return path
class Tile(object):
def __init__(self, gid, texture, tileset):
self.gid = gid
self.texture = texture
self.tile_width = tileset.tile_width
self.tile_height = tileset.tile_height
self.properties = {}
def is_passable(self):
return True if 'wall' not in self.properties and 'water' not in self.properties else False
def loadxml(self, tag):
props = tag.find('properties')
if props is None:
return
for c in props.findall('property'):
# store additional properties.
name = c.attrib['name']
value = c.attrib['value']
# TODO hax
if value.isdigit():
value = int(value)
self.properties[name] = value
def __repr__(self):
return '<Tile %d>' % self.gid
class Tileset(object):
def __init__(self, name, tile_width, tile_height, firstgid, spacing=0, margin=0):
self.name = name
self.tile_width = tile_width
self.tile_height = tile_height
self.firstgid = firstgid
self.spacing = spacing
self.margin = margin
self.tiles = []
self.properties = {}
@classmethod
def fromxml(cls, tag, tilemap, firstgid=None):
if 'source' in tag.attrib:
firstgid = int(tag.attrib['firstgid'])
path = tag.attrib['source']
if not os.path.exists(path):
path = os.path.join(tilemap.file_path, path)
with open(path) as f:
tileset = ElementTree.fromstring(f.read())
return cls.fromxml(tileset, firstgid)
name = tag.attrib['name']
if firstgid is None:
firstgid = int(tag.attrib['firstgid'])
tile_width = int(tag.attrib['tilewidth'])
tile_height = int(tag.attrib['tileheight'])
spacing = int(tag.get('spacing', 0))
margin = int(tag.get('margin', 0))
tileset = cls(name, tile_width, tile_height, firstgid,
spacing, margin)
for c in tag.getchildren():
if c.tag == "image":
# create a tileset
tileset.add_image(tilemap.file_path, c.attrib['source'])
elif c.tag == 'tile':
gid = tileset.firstgid + int(c.attrib['id'])
tileset.get_tile(gid).loadxml(c)
return tileset
def add_image(self, base_path, file):
if not os.path.exists(file):
file = os.path.join(base_path, file)
texture = Image(source=file).texture
print('loading', file)
texture.mag_filter = 'nearest'
if texture is None:
sys.exit('failed to locate image file %r' % file)
id = self.firstgid
th = self.tile_height + self.spacing
tw = self.tile_width + self.spacing
for j in range(texture.height // th):
for i in range(texture.width // tw):
x = (i * tw) + self.margin
# convert the y coordinate to OpenGL (0 at bottom of texture)
y = texture.height - ((j + 1) * th)
tile = texture.get_region(x, y, self.tile_width, self.tile_height)
self.tiles.append(Tile(id, tile, self))
id += 1
def get_tile(self, gid):
return self.tiles[gid - self.firstgid]
class Tilesets(dict):
def add(self, tileset):
for i, tile in enumerate(tileset.tiles):
i += tileset.firstgid
self[i] = tile
class Cell(object):
"""Layers are made of Cells (or empty space).
Cells have some basic properties:
x, y - the cell's index in the layer
px, py - the cell's pixel position
left, right, top, bottom - the cell's pixel boundaries
Additionally the cell may have other properties which are accessed using
standard dictionary methods:
cell['property name']
You may assign a new value for a property to or even delete an existing
property from the cell - this will not affect the Tile or any other Cells
using the Cell's Tile.
"""
def __init__(self, layer, x, y, px, py, tile):
self.layer = layer
self.occupied = False
self.map_px = px
self.map_py = py
self.x, self.y = x, y
self.px, self.py = px, py
self.px_width, self.px_height = tile.tile_width, tile.tile_height
self.py = layer.px_height - py - tile.tile_height # corrected y positioning, I don't get why yet though...
self.size = self.px_width, self.px_height
self.tile = tile
self.bottomleft = (px, py)
self.left = px
self.right = px + self.px_width
self.bottom = py
self.top = py + self.px_height
self.center = (px + self.px_width // 2, py + self.px_height // 2)
self._added_properties = {}
self._deleted_properties = set()
self.priority = 0
# this is here only for python3 comparison for heapq push
def __lt__(self, other):
return self.priority < other.priority
def __repr__(self):
return '<Cell at %s %s>' % (self.x, self.y)
def __contains__(self, key):
if key in self._deleted_properties:
return False
return key in self._added_properties or key in self.tile.properties
def __getitem__(self, key):
if key in self._deleted_properties:
raise KeyError(key)
if key in self._added_properties:
return self._added_properties[key]
if key in self.tile.properties:
return self.tile.properties[key]
raise KeyError(key)
def __setitem__(self, key, value):
self._added_properties[key] = value
def __delitem__(self, key):
self._deleted_properties.add(key)
def intersects(self, other):
"""
Determine whether this Cell intersects with the other rect (which has
.x, .y, .width and .height attributes.)
"""
if self.px + self.px_width < other.x:
return False
if other.x + other.width < self.px:
return False
if self.py + self.px_height < other.y:
return False
if other.y + other.height < self.py:
return False
return True
class LayerIterator(object):
"""Iterates over all the cells in a layer in column,row order.
"""
def __init__(self, layer):
self.layer = layer
self.i, self.j = 0, 0
def __next__(self):
if self.i == self.layer.width:
self.j += 1
self.i = 0
if self.j == self.layer.height:
raise StopIteration()
value = self.layer[self.i, self.j]
self.i += 1
return value
def next(self):
if self.i == self.layer.width:
self.j += 1
self.i = 0
if self.j == self.layer.height:
raise StopIteration()
value = self.layer[self.i, self.j]
self.i += 1
return value
class Layer(object):
"""A 2d grid of Cells.
Layers have some basic properties:
width, height - the dimensions of the Layer in cells
tile_width, tile_height - the dimensions of each cell
px_width, px_height - the dimensions of the Layer in pixels
tilesets - the tilesets used in this Layer (a Tilesets instance)
properties - any properties set for this Layer
cells - a dict of all the Cell instances for this Layer, keyed off
(x, y) index.
Additionally you may look up a cell using direct item access:
layer[x, y] is layer.cells[x, y]
Note that empty cells will be set to None instead of a Cell instance.
"""
def __init__(self, name, visible, map):
self.name = name
self.visible = visible
self.position = (0, 0)
self.px_width = int(map.px_width)
self.px_height = int(map.px_height)
self.tile_width = int(map.tile_width)
self.tile_height = int(map.tile_height)
self.width = int(map.width)
self.height = int(map.height)
self.tilesets = map.tilesets
self.properties = {}
self.cells = {}
self.all_cells = []
self.walls = []
def __repr__(self):
return '<Layer "%s" at 0x%x>' % (self.name, id(self))
def __getitem__(self, pos):
return self.cells.get(pos)
def __setitem__(self, pos, tile):
x, y = pos
px = x * self.tile_width
py = y * self.tile_width
rev_y = self.px_height - py - self.tile_height // self.tile_height
cell = Cell(self, x, y, px, py, tile)
self.cells[(x, rev_y)] = cell
self.all_cells.append(cell)
if 'wall' in tile.properties:
self.walls.append(cell)
def __iter__(self):
return LayerIterator(self)
@classmethod
def fromxml(cls, tag, map):
# print(type(map))
layer = cls(tag.attrib['name'], int(tag.attrib.get('visible', 1)), map)
data = tag.find('data')
# print(ElementTree.tostring(data))
if data is None:
raise ValueError('layer %s does not contain <data>' % layer.name)
# print('layer data not none')
data = data.text.strip()
data = zlib.decompress(base64.b64decode(data))
data = struct.unpack('<%di' % (len(data) / 4,), data)
assert len(data) == layer.width * layer.height, "data len (%d) != width (%d) x height (%d)" % (
len(data), layer.width, layer.height)
for i, gid in enumerate(data):
if gid < 1: continue # not set
tile = map.tilesets[gid]
x = i % layer.width
y = i // layer.width
layer.cells[x, y] = Cell(layer, x, y, x * layer.tile_width, y * layer.tile_height, tile)
# print(layer.name, 'cells are now', layer.cells)
return layer
def update(self, dt, *args):
pass
def set_view(self, x, y, w, h, viewport_ox=0, viewport_oy=0):
self.view_x, self.view_y = x, y
self.view_w, self.view_h = w, h
x -= viewport_ox
y -= viewport_oy
self.position = (x, y)
def find(self, *properties):
"""Find all cells with the given properties set.
"""
r = []
for propname in properties:
for cell in self.cells.values():
if cell and propname in cell:
r.append(cell)
return r
def match(self, **properties):
"""Find all cells with the given properties set to the given values.
"""
r = []
for propname in properties:
for cell in self.cells.values():
if propname not in cell:
continue
if properties[propname] == cell[propname]:
r.append(cell)
return r
def collide(self, rect, propname):
"""Find all cells the rect is touching that have the indicated property
name set.
"""
r = []
for cell in self.get_in_region(rect.left, rect.bottom, rect.right,
rect.top):
if not cell.intersects(rect):
continue
if propname in cell:
r.append(cell)
return r
def get_in_region(self, x1, y1, x2, y2):
"""Return cells (in [column][row]) that are within the map-space
pixel bounds specified by the bottom-left (x1, y1) and top-right
(x2, y2) corners.
Return a list of Cell instances.
"""
i1 = max(0, x1 // self.tile_width)
j1 = max(0, y1 // self.tile_height)
i2 = min(self.width, x2 // self.tile_width + 1)
j2 = min(self.height, y2 // self.tile_height + 1)
return [self.cells[i, j]
for i in range(int(i1), int(i2))
for j in range(int(j1), int(j2))
if (i, j) in self.cells]
def get_tile(self, tx, ty):
return self.cells.get((tx, ty))
def get_at(self, x, y, y_offset=1, reverse_y=True):
# print('get at called')
"""Return the cell at the nominated (x, y) coordinate.
Return a Cell instance or None.
"""
i = x // self.tile_width
j = y // self.tile_height + y_offset
j = (self.height - j) if reverse_y else j
return self.cells.get((i, j))
def passable(self, cell):
return cell.tile.is_passable()
def in_bounds(self, cell):
return self.cells.get((cell.x, cell.y)) is not None
def occupied(self, cell):
return not cell.occupied
def get_neighbor_cells(self, cell):
# print(self.neighbors((cell.x, cell.y)))
if cell:
cells = [self.cells.get(n) for n in self.neighbors((cell.x, cell.y))]
# print('cells before filter', cells)
cells = filter(self.in_bounds, cells)
# print('cells after is passable', cells)
cells = filter(self.passable, cells)
# cells = filter(self.occupied, cells) I think this logic needs to be at the usage level, after results given
return cells
return []
def a_star_search(self, start, goal):
graph = GridWithWeights(self)
frontier = PriorityQueue()
frontier.put(start, 0)
came_from = dict()
cost_so_far = dict()
came_from[start] = None
cost_so_far[start] = 0
while not frontier.empty():
cell = frontier.get()
if cell == goal:
# print('cell is goal', start, goal)
break
for next_cell in self.get_neighbor_cells(cell):
new_cost = cost_so_far[cell] + graph.cost(cell, next_cell)
if next_cell not in cost_so_far or new_cost < cost_so_far[next_cell]:
cost_so_far[next_cell] = new_cost
priority = new_cost + heuristic(goal, next_cell)
frontier.put(next_cell, priority)
came_from[next_cell] = cell
if goal not in came_from:
print('could not reach goal based on get neighbor cell results', start, goal)
return [start, goal]
return reconstruct_path(came_from, start, goal)
def neighbors(self, index):
"""Return the indexes of the valid (ie. within the map) cardinal (ie.
North, South, East, West) neighbors of the nominated cell index.
Returns a list of 2-tuple indexes.
"""
i, j = index
n = []
if i < self.width - 1:
n.append((i + 1, j))
if i > 0:
n.append((i - 1, j))
if j < self.height - 1:
n.append((i, j + 1))
if j > 0:
n.append((i, j - 1))
return n
class SpriteLayer(object):
def __init__(self):
super(SpriteLayer, self).__init__()
self.visible = True
def set_view(self, x, y, w, h, viewport_ox=0, viewport_oy=0):
self.view_x, self.view_y = x, y
self.view_w, self.view_h = w, h
x -= viewport_ox
y -= viewport_oy
self.position = (x, y)
class Layers(list):
def __init__(self):
self.by_name = {}
def add_named(self, layer, name):
self.append(layer)
self.by_name[name] = layer
def __getitem__(self, item):
# print('getting layers by name', self.by_name)
if isinstance(item, int):
return self[item]
return self.by_name[item]
def load(filename, viewport):
return TileMap.load(filename, viewport)
# frequently used in almost all game states.
# class Skill(Model):
# id = Column(Integer, ForeignKey('characters.id'))
# character_id = Column
# name = Column
# base = Column
# value = Column
#
#
# class SkillSet(object):
# def __init__(self, character):
# for skill in character.skills:
# setattr(self, skill.name, skill)
#
#
# # come back to this one... does this just belong on the character model?
# # this would maybe be used for displaying the character sprite/paper doll with equipment, otherwise only during battle equations
# class EquipmentSet(object):
# head = None
# neck = None
# shoulders = None
# arms = None
# left_hand = None
# right_hand = None
# torso = None
# waist = None
# legs = None
# feet = None
#
# def __init__(self, container):
# for item in container:
# item_type = item.type
# setattr(self, item_type, item)
#
#
# class Character(Model):
# __tablename__ = 'characters'
# id = Column(Integer, primary_key=True)
# map_id = Column(Integer, ForeignKey('maps.id'))
# name = Column
# race = Column(String(16))
# gender = Column(String(8))
# soul_state = Column(String(8))
# soul_type = Column(String(16))
# inventory_id = Column(Integer, ForeignKey('containers.id'))
# inventory = relationship('Container', foreign_keys='Character.inventory_id')
# equipment_set_id = Column(Integer, ForeignKey('containers.id'))
# equipment_set = relationship('Container', foreign_keys='Character.inventory_id')
# attributes = relationship('Attribute')
# skills = relationship('Skill')
#
# def construct(self):
# self.skillset = SkillSet(self)
#
#
#