Buildings and levels for the floor map, and make every identifier searchable
This commit is contained in:
@@ -196,7 +196,10 @@ def _walk_related_for_position(asset, visited, depth):
|
||||
n_mapx = getattr(neighbor, 'mapx', None)
|
||||
n_mapy = getattr(neighbor, 'mapy', None)
|
||||
if n_mapx is not None and n_mapy is not None:
|
||||
return (n_mapx, n_mapy)
|
||||
# The neighbour's LEVEL travels with its coordinates. Returning the
|
||||
# pair alone would leave the caller drawing a machine's position on
|
||||
# whatever level the PC that borrowed it happens to claim.
|
||||
return (n_mapx, n_mapy, getattr(neighbor, 'levelid', None))
|
||||
|
||||
recursed = _walk_related_for_position(neighbor, visited, depth + 1)
|
||||
if recursed is not None:
|
||||
@@ -214,18 +217,28 @@ def resolve_asset_position(asset) -> Optional[Dict[str, Any]]:
|
||||
3. Asset's location coords (asset.location.mapx, .mapy)
|
||||
4. None (asset is unplaced, rendered in a tray)
|
||||
|
||||
Returns a dict {'mapx', 'mapy', 'positionsource'} where positionsource
|
||||
is one of 'self', 'related', 'location'. Returns None when no priority
|
||||
yields coordinates.
|
||||
Returns a dict {'mapx', 'mapy', 'levelid', 'positionsource'} where
|
||||
positionsource is one of 'self', 'related', 'location'. Returns None when no
|
||||
priority yields coordinates.
|
||||
|
||||
LEVELID COMES FROM WHICHEVER SOURCE SUPPLIED THE COORDINATES, not from the
|
||||
asset (ADR-017). A PC with no position of its own that inherits from the
|
||||
machine it controls is at the MACHINE's coordinates on the MACHINE's level;
|
||||
using the PC's own level - which may be null, or may be a different building
|
||||
entirely - would draw those coordinates on the wrong drawing, and the result
|
||||
looks entirely reasonable.
|
||||
"""
|
||||
mapx = getattr(asset, 'mapx', None)
|
||||
mapy = getattr(asset, 'mapy', None)
|
||||
if mapx is not None and mapy is not None:
|
||||
return {'mapx': mapx, 'mapy': mapy, 'positionsource': 'self'}
|
||||
return {'mapx': mapx, 'mapy': mapy,
|
||||
'levelid': getattr(asset, 'levelid', None),
|
||||
'positionsource': 'self'}
|
||||
|
||||
related = _walk_related_for_position(asset, set(), 0)
|
||||
if related is not None:
|
||||
return {'mapx': related[0], 'mapy': related[1], 'positionsource': 'related'}
|
||||
return {'mapx': related[0], 'mapy': related[1], 'levelid': related[2],
|
||||
'positionsource': 'related'}
|
||||
|
||||
location = getattr(asset, 'location', None)
|
||||
if location is not None:
|
||||
@@ -235,6 +248,7 @@ def resolve_asset_position(asset) -> Optional[Dict[str, Any]]:
|
||||
return {
|
||||
'mapx': loc_mapx,
|
||||
'mapy': loc_mapy,
|
||||
'levelid': getattr(location, 'levelid', None),
|
||||
'positionsource': 'location',
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user