From: Jakob Cornell Date: Sat, 22 Jun 2019 23:13:46 +0000 (-0500) Subject: API changes and initial save file processing X-Git-Url: https://jcornell.net/gitweb/gitweb.cgi?a=commitdiff_plain;h=f3a362531ffadeff2eb6fe80589b85f32dac2289;p=zoombinis-solve.git API changes and initial save file processing --- diff --git a/common.py b/common.py index 8195c0a..f618b16 100644 --- a/common.py +++ b/common.py @@ -5,15 +5,15 @@ class Zoombini: pass # marker class class Hair(Property): - PINK = 'pink'; GREEN = 'green'; TUFT = 'tuft'; SPIKY = 'spiky'; FLAT = 'flat' + SHAGGY = 'shaggy'; PONYTAIL = 'ponytail'; FLAT_TOP = 'flat top'; TUFT = 'tuft'; HAT = 'hat'; class Eyes(Property): - ONE = 'one'; WIDE = 'wide'; SLEEPY = 'sleepy'; SHADES = 'shades'; GLASSES = 'glasses' + WIDE = 'wide'; ONE = 'one'; SLEEPY = 'sleepy'; GLASSES = 'glasses'; SUNGLASSES = 'sunglasses'; class Nose(Property): - RED = 'red'; ORANGE = 'orange'; GREEN = 'green'; BLUE = 'blue'; PURPLE = 'purple' + GREEN = 'green'; ORANGE = 'orange'; RED = 'red'; PURPLE = 'purple'; BLUE = 'blue'; class Feet(Property): - SHOES = 'shoes'; PROPELLER = 'propeller'; SPRING = 'spring'; WHEELS = 'wheels'; SKATES = 'skates' + SHOES = 'shoes'; BLADES = 'blades'; SPRING = 'spring'; WHEELS = 'wheels'; PROPELLER = 'propeller' - PROPERTIES = frozenset([Hair, Eyes, Nose, Feet]) + PROPERTIES = [Hair, Eyes, Nose, Feet] def __init__(self, attrs): assert ( @@ -23,8 +23,8 @@ class Zoombini: self.by_prop = {type(attr): attr for attr in attrs} self.attrs = frozenset(attrs) - def __str__(self): - return str({type(a).__name__: a.value for a in self.attrs}) + def __repr__(self): + return '({})'.format('/'.join(self.by_prop[p].value for p in Zoombini.PROPERTIES)) ALL_ATTRS = frozenset(attr for prop in Zoombini.PROPERTIES for attr in prop) diff --git a/savefiles/get_troupe.py b/savefiles/get_troupe.py new file mode 100644 index 0000000..75697ee --- /dev/null +++ b/savefiles/get_troupe.py @@ -0,0 +1,20 @@ +import sys +import pickle + +from zoombinis import common + +file_name = sys.argv[1] + +def from_bytes(bytes_): + attrs = {list(prop)[byte - 1] for (prop, byte) in zip(common.Zoombini.PROPERTIES, bytes_[:4])} + return common.Zoombini(attrs) + +def get_zoombinis(): + with open(file_name, 'rb') as f: + if sys.argv[2] == 'LastFull': + f.seek(45226) + return {from_bytes(f.read(20)) for _ in range(16)} + else: + raise ValueError("Invalid selector: {}".format(sys.argv[2])) + +pickle.dump(get_zoombinis(), sys.stdout.buffer) diff --git a/troupe.py b/troupe.py index b79b62d..eb62033 100644 --- a/troupe.py +++ b/troupe.py @@ -7,34 +7,34 @@ Z = Zoombini def get_options(type_): return '/'.join(variant.value for variant in type_) -zs = [] -try: - while True: - template = "\tchoose {} ({}): " - print(template.format('hair', get_options(Z.Hair)), file = sys.stderr, end = '') - hair = input() - print(template.format('eyes', get_options(Z.Eyes)), file = sys.stderr, end = '') - eyes = input() - print(template.format('nose', get_options(Z.Nose)), file = sys.stderr, end = '') - nose = input() - print(template.format('feet', get_options(Z.Feet)), file = sys.stderr, end = '') - feet = input() +def get_interactive(): + zs = [] + try: + while True: + template = "\tchoose {} ({}): " + print(template.format('hair', get_options(Z.Hair)), file = sys.stderr, end = '') + hair = input() + print(template.format('eyes', get_options(Z.Eyes)), file = sys.stderr, end = '') + eyes = input() + print(template.format('nose', get_options(Z.Nose)), file = sys.stderr, end = '') + nose = input() + print(template.format('feet', get_options(Z.Feet)), file = sys.stderr, end = '') + feet = input() - try: - zs.append( - Zoombini({ - Z.Hair[hair.upper()], - Z.Eyes[eyes.upper()], - Z.Nose[nose.upper()], - Z.Feet[feet.upper()], - }) - ) - except KeyError: - print("not added!", file = sys.stderr) - else: - print("added", file = sys.stderr) -except EOFError: - pass + try: + zs.append( + Zoombini({ + Z.Hair[hair.upper()], + Z.Eyes[eyes.upper()], + Z.Nose[nose.upper()], + Z.Feet[feet.upper()], + }) + ) + except KeyError: + print("not added!", file = sys.stderr) + else: + print("added", file = sys.stderr) + except EOFError: + return zs -pickle.dump(zs, sys.stdout.buffer) -print() +pickle.dump(get_interactive(), sys.stdout.buffer)