diff options
author | Treeki <treeki@gmail.com> | 2012-07-25 14:11:19 +0200 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2012-07-25 14:11:19 +0200 |
commit | e0aebec63011cbcb676caa92948e25c62fd6c17b (patch) | |
tree | d23461dd544b6fb6d914406436aadbef5ab08468 /src | |
parent | faaa82bd81f24fc897a5d0ae912381413625ddeb (diff) | |
download | koopatlas-freeform-unlocks.tar.gz koopatlas-freeform-unlocks.zip |
exporting of unlockable paths donefreeform-unlocks
Diffstat (limited to '')
-rw-r--r-- | src/exporter.py | 37 | ||||
-rw-r--r-- | src/mapdata.py | 6 | ||||
-rw-r--r-- | src/unlock.py | 8 |
3 files changed, 36 insertions, 15 deletions
diff --git a/src/exporter.py b/src/exporter.py index c4bb410..2f99a56 100644 --- a/src/exporter.py +++ b/src/exporter.py @@ -210,6 +210,7 @@ class KPMapExporter: if isinstance(eLayer, self.TileLayerExporter): data += u32.pack(0) + data += u32.pack(0xFF000000) # tileset name tileset = '/Maps/Texture/%s.bin' % layer.tileset @@ -228,6 +229,7 @@ class KPMapExporter: elif isinstance(eLayer, self.DoodadLayerExporter): data += u32.pack(1) + data += u32.pack(0xFF000000) # doodad list try: @@ -262,13 +264,14 @@ class KPMapExporter: elif isinstance(eLayer, self.PathLayerExporter): data += u32.pack(2) + data += zero32 # before we do anything, build the list of secret levels # we'll need that levelsWithSecrets = set() for path in layer.paths: - if hasattr(path, 'unlockSpec'): + if hasattr(path, 'unlockSpec') and path.unlockSpec is not None: self._checkSpecForSecrets(path.unlockSpec, levelsWithSecrets) # lists @@ -337,8 +340,8 @@ class KPMapExporter: if node.level: level1, level2 = node.level hasSecret = (1 if ((level1,level2) in levelsWithSecrets) else 0) - # i i b b b b: node type, Extra pointer, world, level, hasSecret, padding - data += struct.pack('>iibbbb', 2, 0, level1, level2, hasSecret, 0) + # i i i b b b b: node type, isNew, Extra pointer, world, level, hasSecret, padding + data += struct.pack('>iiibbbb', 2, 0, 0, level1, level2, hasSecret, 0) elif node.mapChange: data += u32.pack(3) # node type @@ -347,15 +350,17 @@ class KPMapExporter: requiredFixUps.append((len(data)+4, destMap)) stringsToAdd.add(destMap) - # i i b b b b: Extra pointer, dest map, map ID, foreign ID, transition, padding - data += struct.pack('>iibbbb', 0, 0, node.mapID, node.foreignID, node.transition, 0) + # i i i b b b b: isNew, Extra pointer, dest map, map ID, foreign ID, transition, padding + data += struct.pack('>iiibbbb', 0, 0, 0, node.mapID, node.foreignID, node.transition, 0) else: data += u32.pack(1) # node type - data += u32.pack(0) # Extra pointer + data += zero32 # isNew + data += zero32 # Extra pointer else: - data += u32.pack(0) # node type - data += u32.pack(0) # Extra pointer + data += zero32 # node type + data += zero32 # isNew + data += zero32 # Extra pointer pathIndices = {} @@ -376,7 +381,11 @@ class KPMapExporter: data += (zero32 * 4) - data += struct.pack('>bbbbfi', 1, 0, 0, 0, path.movementSpeed, path.animation) + available = 0 + if (not hasattr(path, 'unlockSpec')) or path.unlockSpec is None: + available = 3 + + data += struct.pack('>bbbbfi', available, 0, 0, 0, path.movementSpeed, path.animation) # now that we're almost done... pack the strings for string in stringsToAdd: @@ -416,6 +425,8 @@ class KPMapExporter: # first off, build a map of unlocks unlockLists = {} + + from unlock import stringifyUnlockData for path in self.map.pathLayer.paths: if not hasattr(path, 'unlockSpec'): @@ -424,6 +435,10 @@ class KPMapExporter: if spec is None: continue + # we stringify it first because the specs become lists when + # imported from the kpmap (not tuples) and those can't be + # used as dict keys + spec = stringifyUnlockData(spec) try: lst = unlockLists[spec] except KeyError: @@ -432,10 +447,10 @@ class KPMapExporter: lst.append(path) # now produce the thing - from unlock import packUnlockSpec + from unlock import parseUnlockText, packUnlockSpec for spec, lst in unlockLists.iteritems(): - data += packUnlockSpec(spec) + data += packUnlockSpec(parseUnlockText(spec)) data += chr(len(lst)) for p in lst: data += u16.pack(pathIndices[p]) diff --git a/src/mapdata.py b/src/mapdata.py index 0332280..d175046 100644 --- a/src/mapdata.py +++ b/src/mapdata.py @@ -464,6 +464,10 @@ class KPPath(object): # self.linkedLayer = mapObj.derefLayer(src['linkedLayer']) def __init__(self, startNode=None, endNode=None, cloneFrom=None): + # this is placed before the null ctor in case we load an old + # kpmap that didn't have unlockSpec + self.unlockSpec = None # always unlocked, by default + if startNode is None and endNode is None: # null ctor, ignore this # we're probably loaded from a file, so trust @@ -476,8 +480,6 @@ class KPPath(object): startNode.exits.append(self) endNode.exits.append(self) - self.unlockSpec = None # always unlocked, by default - if cloneFrom is None: self.animation = 0 else: diff --git a/src/unlock.py b/src/unlock.py index 446cd0a..cf3e6fd 100644 --- a/src/unlock.py +++ b/src/unlock.py @@ -11,6 +11,8 @@ def parseUnlockText(text): parsed = _parseUnlockBit(text.lower()) if parsed == ('always',): return None + else: + return parsed def _parseUnlockBit(text): # blank criterion @@ -110,7 +112,7 @@ def stringifyUnlockData(data): return (' %s ' % kind).join(map(lambda x: '(%s)' % stringifyUnlockData(x), data[1])) -def packUnlockSpec(spec): +def packUnlockSpec(data): kind = data[0] if kind == 'always': @@ -119,7 +121,7 @@ def packUnlockSpec(spec): elif kind == 'level': k, world, level, secret = data - one = (1 << 6) | (0x10 if secret else 0) | (worldNumber - 1) + one = (1 << 6) | (0x10 if secret else 0) | (world - 1) return chr(one) + chr(level - 1) @@ -198,6 +200,8 @@ class KPUnlockSpecDialog(QtGui.QDialog): self.layout.addWidget(self.statusLabel) self.layout.addWidget(self.buttons) self.setLayout(self.layout) + + self.spec = None def setSpec(self, spec): self.textBox.setText(stringifyUnlockData(spec)) |