summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/wargame/source/utils/export.py
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/wargame/source/utils/export.py')
-rwxr-xr-xmacros/latex/contrib/wargame/source/utils/export.py226
1 files changed, 208 insertions, 18 deletions
diff --git a/macros/latex/contrib/wargame/source/utils/export.py b/macros/latex/contrib/wargame/source/utils/export.py
index b60cbb0fc5..d62c9e5f77 100755
--- a/macros/latex/contrib/wargame/source/utils/export.py
+++ b/macros/latex/contrib/wargame/source/utils/export.py
@@ -287,6 +287,31 @@ def get_game(doc):
return doc.getElementsByTagName('VASSAL.build.GameModule')[0]
# --------------------------------------------------------------------
+def get_globalproperties(doc,one=True):
+ return get_asone(doc,MODULE+'properties.GlobalProperties',one)
+
+# --------------------------------------------------------------------
+def get_globalproperty(doc,asdict=True):
+ '''A little confusing - this returns a dictionary'''
+ return get_asdict(doc,MODULE+'properties.GlobalProperty','name',asdict)
+
+# --------------------------------------------------------------------
+def get_turntrack(doc,asdict=True):
+ return get_asdict(doc,MODULE+'turn.TurnTracker','name',asdict)
+
+# --------------------------------------------------------------------
+def get_turncounter(doc,asdict=True):
+ return get_asdict(doc,MODULE+'turn.CounterTurnLevel','property',asdict)
+
+# --------------------------------------------------------------------
+def get_turnlist(doc,asdict=True):
+ return get_asdict(doc,MODULE+'turn.ListTurnLevel','property',asdict)
+
+# --------------------------------------------------------------------
+def get_turnhotkey(doc,asdict=True):
+ return get_asdict(doc,MODULE+'turn.TurnGlobalHotkey','hotkey',asdict)
+
+# --------------------------------------------------------------------
def get_documentation(doc,one=True):
return get_asone(doc,MODULE+'Documentation',one)
@@ -356,6 +381,10 @@ def get_pieces(doc,asdict=True):
return get_asdict(doc,WIDGET+'PieceSlot','entryName',asdict)
# --------------------------------------------------------------------
+def get_prototypecontainer(doc,one=True):
+ return get_asone(doc,MODULE+'PrototypesContainer',one)
+
+# --------------------------------------------------------------------
def get_prototypes(doc,asdict=True):
return get_asdict(doc,MODULE+'PrototypeDefinition', 'name',asdict)
@@ -444,9 +473,14 @@ def dicts_to_piece(traits):
# ====================================================================
-# Key encoding
+# Key encoding
+SHIFT = 65
CTRL = 130
ALT = 520
+CTRL_SHIFT = CTRL+SHIFT
+ALT_SHIFT = ALT+SHIFT
+NONE = '\ue004'
+NONE_MOD = 0
def key(let,mod=CTRL):
'''Encode a key sequence
@@ -510,10 +544,143 @@ def add_basiccommandencoder(root,doc):
return add_node(root,doc,MODULE+'BasicCommandEncoder')
# --------------------------------------------------------------------
-def add_globalproperties(root,elem):
- return add_node(root,elem,MODULE+'properties.GlobalProperties')
+def add_globalproperties(root,elem,*props,**named):
+ gp = add_node(root,elem,MODULE+'properties.GlobalProperties')
+ # Add elements where each is a dict with _at least_
+ # "{'name':NAME, 'initialValue':VALUE}"
+ for p in props:
+ add_globalproperty(root,gp,**p)
+ # Add elements where each is a named dict with _at least_
+ # "{'initialValue':VALUE}"
+ for n, p in named:
+ add_globalproperty(root,gp,name=n,**p)
+
+ return gp
+
# --------------------------------------------------------------------
+def add_globalproperty(root,elem,name,initialValue,
+ isNumeric = False,
+ min = "null",
+ max = "null",
+ wrap = False,
+ description = ""):
+ return add_node(root,elem,MODULE+'properties.GlobalProperty',
+ name = name,
+ initialValue = initialValue,
+ isNumeric = isNumeric,
+ min = min,
+ max = max,
+ wrap = wrap,
+ description = description)
+
+# --------------------------------------------------------------------
+def add_turntrack(root, elem, name,
+ buttonText = 'Turn',
+ hotkey = '',
+ icon = '',
+ length = -1,
+ lengthStyle = 'Maximum',
+ nexthotkey = key('T',ALT),
+ plusButtonSize = 22,
+ prevhotkey = key('T',ALT_SHIFT),
+ reportFormat = '<$PlayerId$> Turn updated from $oldTurn$ to $newTurn$',
+ turnButtonHeight = 22,
+ turnFormat = None,
+ counter = None,
+ phases = None):
+
+ levels = (counter if counter is not None else
+ phases if phases is not None else None)
+ if levels is not None:
+ lvl = 1
+ lvls = [f'$level{lvl}$']
+ sub = levels
+ while True:
+ sub = sub.get('counter',sub.get('phases',None))
+ if sub is None:
+ break
+ lvl += 1
+ lvls.append(f'$level{lvl}$')
+
+ turnFormat = ' '.join(lvls)
+
+ if turnFormat is None:
+ turnFormat = '$level1$ $level2$ $level3$ $level4$'
+
+ t = add_node(root, elem, MODULE+'turn.TurnTracker',
+ name = name,
+ buttonText = buttonText,
+ hotkey = hotkey,
+ icon = icon,
+ length = length,
+ lengthStyle = lengthStyle,
+ nexthotkey = nexthotkey,
+ plusButtonSize = plusButtonSize,
+ prevhotkey = prevhotkey,
+ reportFormat = reportFormat,
+ turnButtonHeight = turnButtonHeight,
+ turnFormat = turnFormat)
+
+ add_turnlevel(root, t, counter=counter, phases=phases)
+
+ return t
+
+# --------------------------------------------------------------------
+def add_turnlevel(root,parent,counter=None,phases=None):
+ f,s = ((add_turncounter,counter) if counter is not None else
+ (add_turnlist,phases) if phases is not None else (None,None))
+ if f is None: return parent
+
+ subcounter = s.pop('counter',None)
+ subphases = s.pop('phases',None)
+
+ sub = f(root,parent,**s)
+
+ return add_turnlevel(root,sub,counter=subcounter,phases=subphases)
+
+# --------------------------------------------------------------------
+def add_turncounter(root,elem,property,
+ incr = 1,
+ loop = False,
+ loopLimit = -1,
+ turnFormat = "$value$"):
+ c = add_node(root,elem,MODULE+"turn.CounterTurnLevel",
+ property = property,
+ incr = incr,
+ loop = loop,
+ loopLimit = loopLimit,
+ turnFormat = turnFormat)
+ return c
+
+# --------------------------------------------------------------------
+def add_turnlist(root,elem,property,names,
+ configFirst = False,
+ configList = False,
+ turnFormat = '$value$'):
+ c = add_node(root,elem,MODULE+"turn.ListTurnLevel",
+ property = property,
+ list = ','.join([str(p) for p in names]),
+ configFirst = configFirst,
+ configList = configList,
+ turnFormat = turnFormat)
+ return c
+
+# --------------------------------------------------------------------
+def add_turnhotkey(root,elem,
+ hotkey,
+ match = '{phase=="first"}',
+ reportFormat = '{PlayerName}',
+ name = ''):
+ return add_node(root,elem,MODULE+'turn.TurnGlobalHotkey',
+ hotkey = hotkey,
+ match = match,
+ reportFormat = reportFormat,
+ name = name)
+
+
+
+# --------------------------------------------------------------------
def add_translatable(root,elem):
return add_node(root,elem,MODULE+'properties.GlobalTranslatableMessages')
@@ -888,7 +1055,7 @@ def add_squarenumbering(root,grid,
# --------------------------------------------------------------------
def add_regiongrid(root,zone,snapto=True,fontsize=9,visible=True):
- print(f'Make region grid visible: {visible}')
+ # print(f'Make region grid visible: {visible}')
return add_node(root,zone,PICKER+'board.RegionGrid',
fontsize = fontsize,
snapto = snapto,
@@ -916,8 +1083,8 @@ def get_region_piece(root,grid,name,alsoPiece=True,piece=None,verbose=False):
# Find the piece by searching from the top of the tree
piece = get_pieces(root,root).get(name,None)
- if piece is None:
- print(list(get_pieces(root,root).keys()))
+ # if piece is None:
+ # print(list(get_pieces(root,root).keys()))
if verbose:
print(f' Possible piece for region {name}: {piece}')
return piece, map
@@ -965,7 +1132,7 @@ def add_region(root,grid,name,originx,originy,gpid,
if verbose:
print(f' Add piece {name} to region')
_, gpid = add_atstart(root,map,name,piece,
- location = name,
+ location = nam,
useGridLocation = True,
owningBoard = map.getAttribute('mapName'),
x = 0,
@@ -1310,6 +1477,7 @@ def add_prototype(root,elem,name,code,description=''):
name = name,
description = description)
add_text(root,d,code)
+ return d
# --------------------------------------------------------------------
def add_piecewindow(root,elem,name,
@@ -1694,7 +1862,7 @@ def delete_trait(name = 'Delete', key = key('D')):
# --------------------------------------------------------------------
def sendto_trait(mapName,
boardName,
- name = 'Eliminate',
+ name = '',
key = key('E'),
restoreName = 'Restore',
restoreKey = key('R'),
@@ -1704,7 +1872,7 @@ def sendto_trait(mapName,
yidx = 0,
xoff = 1,
yoff = 1,
- description = 'Eliminate this unit',
+ description = '',
destination = 'L',
zone = '',
region = '',
@@ -1857,6 +2025,15 @@ def add_proto(typ,state):
return add_piece(typ,state)
+# --------------------------------------------------------------------
+def add_proto_code(decs):
+ typs = [d[0] for d in decs]
+ stts = [d[1] for d in decs]
+ typ = enc_parts(*typs)
+ stt = enc_parts(*stts)
+
+ return add_proto(typ,stt)
+
# ====================================================================
#
# Below specific to the export app
@@ -1960,12 +2137,13 @@ def proto_body(family):
cmd : str
The command to add the piece
'''
- # Dummy image
+ # Dummy image
decs = [ report_trait(key('E'),key('R'),key('M')),
moved_trait(),
trail_trait(),
delete_trait(),
- sendto_trait('DeadMap',family+' pool'),
+ sendto_trait('DeadMap',family+' pool','Eliminate',key('E'),
+ 'Restore',key('R'),description="Eliminate unit"),
mark_trait('Faction',family),
basic_trait('','','') ]
typs = [d[0] for d in decs]
@@ -1974,7 +2152,8 @@ def proto_body(family):
stt = enc_parts(*stts)
return add_proto(typ,stt)
-
+
+
# --------------------------------------------------------------------
def add_splash(root,doc,categories,title='',verbose=False):
'''Add an about page
@@ -2486,8 +2665,8 @@ def get_picture_info(picture,name,width,height,verbose):
return HEX_WIDTH,HEX_HEIGHT,1,1,False,f
# Get picture bounding box
- pll = picture['lower left']
- pur = picture['upper right']
+ tll = picture['lower left']
+ tur = picture['upper right']
# Get picture transformation
pa = picture['xx']
pb = picture['xy']
@@ -2497,11 +2676,10 @@ def get_picture_info(picture,name,width,height,verbose):
pdx = picture['dx']
pdy = picture['dy']
# Define picture global transformation
- #pr = lambda x,y: (pa * x + pb * y, pc * x + pd * y)
pr = lambda x,y: (pa * x + pc * y, pb * x + pd * y)
# Globally transform (rotate) picture bounding box
- pll = pr(*pll)
- pur = pr(*pur)
+ pll = pr(*tll)
+ pur = pr(*tur)
# Calculate widht, height, and scaling factors
pw = pur[0] - pll[0]
ph = pur[1] - pll[1]
@@ -3203,6 +3381,16 @@ def create_build(info,
centerOnMove = 'Use Preferences Setting',
nonOwnerUnmaskable = 'Use Preferences Setting',
playerIdFormat = '$playerName$')
+ # Add global properties
+ gp = add_globalproperties(root,game)
+ # Add a turn tracker
+ tt = add_turntrack(root,game,'Turn',counter={
+ 'property': 'Turn',
+ 'phases': {
+ 'property': 'Phase',
+ 'names': sides }})
+ add_globalproperty(root,gp,'TurnTracker.defaultDocked',True)
+
# Add all pieces to the module (including prototypes)
gpid = add_counters(root,game,categories,
unittypes,echelons,commands,verbose)
@@ -3330,7 +3518,9 @@ def create_vmod(vmodname,
# Store the name of the image file in catalogue
i['filename'] = i['name'].replace(' ','_') + '.png'
- vmod.writestr('images/'+i['filename'],i['img'])
+ imgfn = 'images/'+i['filename']
+ if imgfn not in vmod.namelist():
+ vmod.writestr(imgfn,i['img'])
# Categorize - assume counter
typ = i.get('category','counter')