Skip to content

Commit

Permalink
Imagix/issue17 (#18)
Browse files Browse the repository at this point in the history
* Make object LoS blockers terrain blockers instead of hard walls
Fixes #17

* Change the default for object blockers
  • Loading branch information
Imagix committed Dec 25, 2021
1 parent cc9ede6 commit 3ac35ca
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -2,7 +2,7 @@
Utility to extract Fantasy Grounds Unity Line-of-sight and lighting files from a Univeral VTT file exported from Dungeondraft

This program works with Fantasy Grounds Unity v4.1 or higher as that is the version where dynamic lighting effects were added.
This was last used with Dungeondraft v1.0.2.1 Beta.
This was last used with Dungeondraft v1.0.2.4.

## Requirements

Expand Down Expand Up @@ -48,6 +48,7 @@ This file will cause the program to write the xml file directly out to joesmith'
| alllocaldd2vttfiles | If no files are specified, look for all .dd2vtt files in the current directory and convert them | False |
| force | Force overwrite destination files | False |
| jpgpath | Path where the .jpg file will be written | Current working directory |
| objectsareterrain | Use a terrain LoS blocker instead of wall blocker for objects | False |
| pngpath | Path where the .png file will be written | Current working directory |
| remove | Remove the source file after conversion | False |
| writejpg | Write the .jpg file | True |
Expand Down
45 changes: 43 additions & 2 deletions uvtt2fgu.py
Expand Up @@ -35,6 +35,7 @@ def __init__(self, configFile: str) -> None:
self.forceOverwrite = None
self.remove = None
self.alllocaldd2vttfiles = False
self.objectsAreTerrain = True

for section in config.sections():
self.xmlpath = config[section].get('xmlpath')
Expand All @@ -45,6 +46,7 @@ def __init__(self, configFile: str) -> None:
self.forceOverwrite = config[section].getboolean('force')
self.remove = config[section].getboolean('remove')
self.alllocaldd2vttfiles = config[section].getboolean('alllocaldd2vttfiles')
self.objectsAreTerrain = config[section].getboolean('objectsareterrain')

def configFilePath(self) -> Path:
myPlatform = platform.system()
Expand Down Expand Up @@ -157,6 +159,36 @@ def xmlElem(self, id) -> ET.Element:

return elem

class ObjectOccluder(Occluder):
'''Represents an Object Occluder'''
def __init__(self, objectsAreTerrain):
super().__init__()
self.objectsAreTerrain = objectsAreTerrain

def xmlElem(self, id) -> ET.Element:
'''Build up the XML representation of a wall'''
elem = self.xmlElemStart(id)

logging.debug(' Occluder(Object) {} {} points'.format(id, len(self.points)))
pointsElem = ET.Element('points')
pt = []
for point in self.points:
pt.append(str(point.x))
pt.append(str(point.y))
pointsElem.text = ','.join(pt)
elem.append(pointsElem)

if self.objectsAreTerrain:
elem.append(ET.Element('terrain'))
elem.append(ET.Element('hidden'))
elem.append(ET.Element('single_sided'))
elem.append(ET.Element('allow_move'))
elem.append(ET.Element('closed'))
elem.append(ET.Element('counterclockwise'))
elem.append(ET.Element('toggleable'))

return elem

class PortalOccluder(Occluder):
'''Represents a Portal occluder, could be a door or window'''
def __init__(self, rotation, widthAdj, lengthAdj):
Expand Down Expand Up @@ -268,6 +300,15 @@ def composeWall(self, los) -> Occluder:

return wall

def composeObject(self, los) -> Occluder:
'''Build up an Occluder representation of an object'''
object = self.ObjectOccluder(configData.objectsAreTerrain)

for coord in los:
object.addPoint(self.translatePoint(coord))

return object

def composePortal(self, portal) -> Occluder:
'''Build up an Occluder representation of one portal
Expand Down Expand Up @@ -301,7 +342,7 @@ def composeOccluders(self) -> ET.Element:

logging.debug(' {} object los elements'.format(len(objectsLoS)))
for los in objectsLoS:
occluders.append(self.composeWall(los))
occluders.append(self.composeObject(los))

# Next the portal elements, which may be doors or windows
logging.debug(' {} portal elements'.format(len(self.data['portals'])))
Expand Down Expand Up @@ -466,7 +507,7 @@ def init_argparse() -> argparse.ArgumentParser:
'-r', '--remove', help='Remove the input dd2vtt file after conversion'
)
parser.add_argument(
'-v', '--version', action='version', version=f'{parser.prog} version 1.3.0'
'-v', '--version', action='version', version=f'{parser.prog} version 1.4.0'
)
parser.add_argument('files', nargs='*',
help='Files to convert to .png + .xml for FGU')
Expand Down

0 comments on commit 3ac35ca

Please sign in to comment.