mirror of
https://github.com/veekun/pokedex.git
synced 2024-08-20 18:16:34 +00:00
Fix frozenset proxy, implement ribbons setter
This commit is contained in:
parent
8590c51c7c
commit
14ea7a0adf
1 changed files with 21 additions and 3 deletions
|
@ -47,10 +47,14 @@ def struct_frozenset_proxy(name):
|
||||||
bitstruct = getattr(self.structure, name)
|
bitstruct = getattr(self.structure, name)
|
||||||
return frozenset(k for k, v in bitstruct.items() if v)
|
return frozenset(k for k, v in bitstruct.items() if v)
|
||||||
|
|
||||||
def setter(self, value):
|
def setter(self, new_set):
|
||||||
|
new_set = set(new_set)
|
||||||
struct = getattr(self.structure, name)
|
struct = getattr(self.structure, name)
|
||||||
for key in struct:
|
for key in struct:
|
||||||
setattr(struct, key, key in value)
|
setattr(struct, key, key in new_set)
|
||||||
|
new_set.discard(key)
|
||||||
|
if new_set:
|
||||||
|
raise ValueError('Unknown values: {0}'.format(', '.join(ribbons)))
|
||||||
del self.blob
|
del self.blob
|
||||||
|
|
||||||
return property(getter, setter)
|
return property(getter, setter)
|
||||||
|
@ -449,6 +453,8 @@ class SaveFilePokemon(object):
|
||||||
if 'egg received' in dct:
|
if 'egg received' in dct:
|
||||||
self.date_egg_received = datetime.datetime.strptime(
|
self.date_egg_received = datetime.datetime.strptime(
|
||||||
dct['egg received'], '%Y-%m-%d').date()
|
dct['egg received'], '%Y-%m-%d').date()
|
||||||
|
if 'ribbons' in dct:
|
||||||
|
self.ribbons = (r.replace(' ', '_') for r in dct['ribbons'])
|
||||||
if 'moves' in dct:
|
if 'moves' in dct:
|
||||||
pp_reset_indices = []
|
pp_reset_indices = []
|
||||||
for i, movedict in enumerate(dct['moves']):
|
for i, movedict in enumerate(dct['moves']):
|
||||||
|
@ -785,7 +791,19 @@ class SaveFilePokemon(object):
|
||||||
self.sinnoh_ribbons |
|
self.sinnoh_ribbons |
|
||||||
self.hoenn_ribbons |
|
self.hoenn_ribbons |
|
||||||
self.sinnoh_contest_ribbons)
|
self.sinnoh_contest_ribbons)
|
||||||
# XXX: ribbons setter
|
|
||||||
|
@ribbons.setter
|
||||||
|
def ribbons(self, ribbons):
|
||||||
|
ribbons = set(ribbons)
|
||||||
|
for ribbonset_name in (
|
||||||
|
'sinnoh_ribbons', 'hoenn_ribbons', 'sinnoh_contest_ribbons'):
|
||||||
|
ribbonset = self.structure[ribbonset_name]
|
||||||
|
print ribbonset
|
||||||
|
for ribbon_name in ribbonset:
|
||||||
|
ribbonset[ribbon_name] = (ribbon_name in ribbons)
|
||||||
|
ribbons.discard(ribbon_name)
|
||||||
|
if ribbons:
|
||||||
|
raise ValueError('Unknown ribbons: {0}'.format(', '.join(ribbons)))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def nickname(self):
|
def nickname(self):
|
||||||
|
|
Loading…
Reference in a new issue