summaryrefslogtreecommitdiff
path: root/src/exporter.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/exporter.py111
1 files changed, 51 insertions, 60 deletions
diff --git a/src/exporter.py b/src/exporter.py
index f39497f..c4bb410 100644
--- a/src/exporter.py
+++ b/src/exporter.py
@@ -201,22 +201,6 @@ class KPMapExporter:
requiredFixUps.append((len(data), layer))
data += zero32
- # map all paths to unlock info
- unlockInfo = {}
-
- for node in self.map.pathLayer.nodes:
- if not node.level: continue
-
- checked = set()
- affected = []
- self._findUnlocksForNode(node, checked, affected)
-
- level1, level2 = node.level
-
- for item, secret in affected:
- unlockInfo[item] = (level1, level2, secret)
-
-
# now build the layers
for eLayer in self.layers:
layer = eLayer.layer
@@ -279,6 +263,14 @@ class KPMapExporter:
elif isinstance(eLayer, self.PathLayerExporter):
data += u32.pack(2)
+ # 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'):
+ self._checkSpecForSecrets(path.unlockSpec, levelsWithSecrets)
+
# lists
current = len(data)
nodeArray = current + 16
@@ -344,8 +336,9 @@ class KPMapExporter:
if node.isStop():
if node.level:
level1, level2 = node.level
- # i i b b b b: node type, Extra pointer, world, level, padding (hasSecret?), padding
- data += struct.pack('>iibbbb', 2, 0, level1, level2, 0, 0)
+ 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)
elif node.mapChange:
data += u32.pack(3) # node type
@@ -364,7 +357,10 @@ class KPMapExporter:
data += u32.pack(0) # node type
data += u32.pack(0) # Extra pointer
- for path in layer.paths:
+ pathIndices = {}
+
+ for i, path in enumerate(layer.paths):
+ pathIndices[path] = i
offsets[path] = len(data)
start = path._startNodeRef()
@@ -380,13 +376,7 @@ class KPMapExporter:
data += (zero32 * 4)
- try:
- unlockL1, unlockL2, isSecret = unlockInfo[path]
- unlockType = (2 if isSecret else 1)
- except KeyError:
- unlockL1, unlockL2, unlockType = 0, 0, 0
-
- data += struct.pack('>bbbbfi', unlockType, unlockL1, unlockL2, 1, path.movementSpeed, path.animation)
+ data += struct.pack('>bbbbfi', 1, 0, 0, 0, path.movementSpeed, path.animation)
# now that we're almost done... pack the strings
for string in stringsToAdd:
@@ -423,11 +413,32 @@ class KPMapExporter:
# at the end comes the unlock bytecode
offsets['UnlockBytecode'] = len(data)
- unlockBytecode = ''
- # note: subtract 1 from the world and level number when saving
- # note: also limit world to 1-10 in the parser
- # note: enforce maximum term limit (64)
- # note: block recursion too much
+
+ # first off, build a map of unlocks
+ unlockLists = {}
+
+ for path in self.map.pathLayer.paths:
+ if not hasattr(path, 'unlockSpec'):
+ continue
+ spec = path.unlockSpec
+ if spec is None:
+ continue
+
+ try:
+ lst = unlockLists[spec]
+ except KeyError:
+ lst = []
+ unlockLists[spec] = lst
+ lst.append(path)
+
+ # now produce the thing
+ from unlock import packUnlockSpec
+
+ for spec, lst in unlockLists.iteritems():
+ data += packUnlockSpec(spec)
+ data += chr(len(lst))
+ for p in lst:
+ data += u16.pack(pathIndices[p])
# to finish up, correct every offset
for offset, target in requiredFixUps:
@@ -439,36 +450,16 @@ class KPMapExporter:
ANIM_CURVES = ['Linear', 'Sinusoidial', 'Cosinoidial']
ANIM_TYPES = ['X Position', 'Y Position', 'Angle', 'X Scale', 'Y Scale', 'Opacity']
+ def _checkSpecForSecrets(self, spec, levelSet):
+ kind = spec[0]
- def _findUnlocksForNode(self, node, checked, affected, isFirstBranch=True, secret=None):
- if node in checked: return
-
- checked.add(node)
-
- for path in node.exits:
- if path not in checked:
- checked.add(path)
- self._findUnlocksForPath(path, node, checked, affected, isFirstBranch, secret)
-
-
- def _findUnlocksForPath(self, path, sourceNode, checked, affected, isFirstBranch, secret=None):
- start, end = path._startNodeRef(), path._endNodeRef()
- if start == sourceNode:
- destNode = end
- if isFirstBranch and path.unlocks != 1:
- return
- else:
- destNode = start
- if isFirstBranch and path.unlocks != 2:
- return
-
- if secret is None:
- secret = path.secret
- affected.append((path, secret))
-
- if not destNode.isStop():
- self._findUnlocksForNode(destNode, checked, affected, False, secret)
-
+ if kind == 'level':
+ k, one, two, secret = spec
+ if secret:
+ levelSet.add((one, two))
+ elif kind == 'and' or kind == 'or':
+ for term in spec[1]:
+ self._checkSpecForSecrets(term, levelSet)
def _buildGXTexObjRGB5A3(self, width, height, imgOffset):
# Format: RGB5A3 (5)