Skip to content

Commit

Permalink
support Map patches in code, call Actor::Finalize after reading all
Browse files Browse the repository at this point in the history
  • Loading branch information
Die4Ever committed Jun 12, 2023
1 parent 4200e5c commit 43b6d16
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
21 changes: 12 additions & 9 deletions MapLibs/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ def Finalize(self, mult_coords):# TODO: more checks in finalize
for i in self.IterProps('Location', 'BasePos', 'SavedPos', 'OldLocation'):
self.lines[i] = self.ProcLoc(self.lines[i], mult_coords)

self._Finalize(mult_coords)

def _Finalize(self, mult_coords):
pass

def GetLoc(self, line:str) -> tuple:
match = loc.match(line)
Expand Down Expand Up @@ -585,7 +589,6 @@ def _Read(self, file, mult_coords:tuple|None):
self.props[prop.group(2)] = len(self.lines)
self.lines.append(line)
if stripped == 'End Actor':
self.Finalize(mult_coords)
return
line:str = file.readline()

Expand All @@ -597,8 +600,8 @@ def ReadBrush(self, line:str, file, mult_coords) -> str:


class OldBrush(Actor): # well this was a big waste of time? lol
def Finalize(self, mult_coords):# TODO: more checks in finalize
super().Finalize(mult_coords)
def _Finalize(self, mult_coords):# TODO: more checks in finalize
super()._Finalize(mult_coords)
if type(self) == OldBrush:
self.MirrorVerts(mult_coords)

Expand Down Expand Up @@ -744,8 +747,8 @@ def ReadPolygon(self, line:str, file, mult_coords) -> None:


class Brush(OldBrush):
def Finalize(self, mult_coords):
super().Finalize(mult_coords)
def _Finalize(self, mult_coords):
super()._Finalize(mult_coords)

# check if this is a portal
for p in self.polylist:
Expand Down Expand Up @@ -788,17 +791,17 @@ def FixScale(self, line:str, mult_coords) -> str:


class Mover(Brush):
def Finalize(self, mult_coords):
super().Finalize(mult_coords)
def _Finalize(self, mult_coords):
super()._Finalize(mult_coords)

for (prop, i) in self.props.items():
if prop.startswith('KeyPos('):
self.lines[i] = self.ProcLoc(self.lines[i], mult_coords) # idk if this needs to be ProcLoc or ProcLocRot, will need to find an example


class DeusExLevelInfo(Actor):
def Finalize(self, mult_coords):
super().Finalize(mult_coords)
def _Read(self, file, mult_coords:tuple|None):
super()._Read(file, mult_coords)
i = self.GetPropIdx('MapName')
if i and self.parent:
match = prop_regex.match(self.lines[i])
Expand Down
13 changes: 13 additions & 0 deletions MapLibs/t3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ def Read(self, filepath:Path):
with open(filepath, 'r') as file:
self._Read(file)

self.before_finalize()
for a in self.actors:
a.Finalize(self.mult_coords)
self.after_finalize()


def before_finalize(self):
pass # can check self.name and manipulate the self.actornames dictionary

def after_finalize(self):
pass


def _Read(self, file):
line = file.readline().strip()
assert line == 'Begin Map'
Expand Down
2 changes: 2 additions & 0 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def test_read_brush(self):
actor:Brush = CreateActor(None, brushfile.readline())
self.assertEqual(actor.classname, 'Brush')
actor.Read(brushfile, None)
actor.Finalize(None)

self.assertEqual(actor.lines[0], 'Begin Actor Class=Brush Name=Brush49')
self.assertEqual(actor.lines[1], ' Begin Brush Name=Model14')
Expand All @@ -157,6 +158,7 @@ def test_read_actor(self):
self.assertEqual(actor.classname, 'Jock')
self.assertFalse(isinstance(actor, Brush))
actor.Read(actorfile, None)
actor.Finalize(None)

self.assertEqual(actorfile.readline(), 'Begin Actor Class=AmbientSound Name=AmbientSound0')

Expand Down

0 comments on commit 43b6d16

Please sign in to comment.