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 (
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)
--- /dev/null
+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)
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)