Handle VASSAL crashing when updating scenarios.

master
Pacman Ghost 4 years ago
parent 964d7d38d6
commit e7ebe53718
  1. 6
      vasl_templates/webapp/static/vassal.js
  2. 11
      vasl_templates/webapp/vassal.py
  3. BIN
      vassal-shim/release/vassal-shim.jar
  4. 11
      vassal-shim/src/vassal_shim/ReportNode.java
  5. 55
      vassal-shim/src/vassal_shim/VassalShim.java

@ -72,8 +72,10 @@ function _show_label_report_msg( report )
buf.push( "</ul>" ) ;
var msg = buf.join( "" ) ;
// show the message
if ( report.labels_deleted > 0 )
// show the summary and any error messages
for ( i=0 ; i < report.errors.length ; ++i )
showErrorMsg( report.errors[i] ) ;
if ( report.labels_deleted > 0 || report.errors.length > 0 )
showWarningMsg( msg ) ;
else
showInfoMsg( msg ) ;

@ -95,6 +95,12 @@ def update_vsav(): #pylint: disable=too-many-statements,too-many-locals
logger.info( "Updated the VSAV file OK: elapsed=%.3fs", time.time()-start_time )
# NOTE: We adjust the recommended save filename to encourage users to not overwrite the original file :-/
vsav_filename = os.path.split( vsav_filename )[1]
errors = []
for fail in report["failed"]:
if fail.get("message"):
errors.append( "{} <div class='pre'> {} </div>".format( fail["caption"], fail["message"] ) )
else:
errors.append( fail["caption"] )
return jsonify( {
"vsav_data": base64.b64encode(vsav_data).decode( "utf-8" ),
"filename": vsav_filename,
@ -104,6 +110,7 @@ def update_vsav(): #pylint: disable=too-many-statements,too-many-locals
"labels_updated": len(report["updated"]),
"labels_deleted": len(report["deleted"]),
"labels_unchanged": len(report["unchanged"]),
"errors": errors,
},
} )
@ -182,6 +189,10 @@ def _parse_label_report( fname ):
nodes.append( { "id": node.attrib["id"] } )
if "x" in node.attrib and "y" in node.attrib:
nodes[-1]["pos"] = ( node.attrib["x"], node.attrib["y"] )
if "caption" in node.attrib:
nodes[-1]["caption"] = node.attrib["caption"]
if node.text:
nodes[-1]["message"] = node.text
report[ action.tag ] = nodes
return report

@ -10,6 +10,17 @@ public class ReportNode
String snippetId ;
Point labelPos ;
String caption ;
String msg ;
public ReportNode( String snippetId, Point labelPos, String caption, String msg )
{
// initialize the ReportNode
this.snippetId = snippetId ;
this.labelPos = labelPos ;
this.caption = caption ;
this.msg = msg ;
}
public ReportNode( String snippetId, Point labelPos )
{

@ -377,7 +377,7 @@ public class VassalShim
{
// initialize
Map< String, ArrayList<ReportNode> > labelReport = new HashMap<String,ArrayList<ReportNode>>() ;
for ( String key: new String[]{"created","updated","deleted","unchanged"} )
for ( String key: new String[]{"created","updated","deleted","unchanged","failed"} )
labelReport.put( key, new ArrayList<ReportNode>() ) ;
// process each snippet
@ -419,8 +419,16 @@ public class VassalShim
logger.info( "- Updating label: {}", snippetId ) ;
logger.debug( " - curr state: " + Utils.printableString(currState) ) ;
logger.debug( " - new state: " + Utils.printableString(newState) ) ;
labelFields.gamePiece().setState( newState ) ;
labelReport.get( "updated" ).add( new ReportNode( snippetId, null ) ) ;
try {
labelFields.gamePiece().setState( newState ) ;
labelReport.get( "updated" ).add( new ReportNode( snippetId, null ) ) ;
} catch( Exception ex ) {
String msg = "ERROR: Couldn't update label '" + snippetId + "'" ;
logger.warn( msg, ex ) ;
labelReport.get( "failed" ).add(
new ReportNode( snippetId, null, msg, ex.getMessage() )
) ;
}
}
iter.remove() ;
}
@ -433,8 +441,16 @@ public class VassalShim
logger.info( "- Deleting label: {}", snippetId ) ;
GamePieceLabelFields labelFields = ourLabels.get( snippetId ) ;
RemovePiece cmd = new RemovePiece( labelFields.gamePiece() ) ;
cmd.execute() ;
labelReport.get( "deleted" ).add( new ReportNode( snippetId, null ) ) ;
try {
cmd.execute() ;
labelReport.get( "deleted" ).add( new ReportNode( snippetId, null ) ) ;
} catch( Exception ex ) {
String msg = "ERROR: Couldn't delete label '" + snippetId + "'" ;
logger.warn( msg, ex ) ;
labelReport.get( "failed" ).add(
new ReportNode( snippetId, null, msg, ex.getMessage() )
) ;
}
}
// We now want to create new labels for any snippets left that haven't already been processed.
@ -630,14 +646,22 @@ public class VassalShim
String defaultLabelText1 = config.getProperty( "DEFAULT_LABEL_TEXT1", "Label" ) ;
String defaultLabelText2 = config.getProperty( "DEFAULT_LABEL_TEXT2", "no background" ) ;
String snippetContent = snippet.content.replace( "\n", " " ) ;
gamePiece.setState(
gamePiece.getState().replace( "\t"+defaultUserName+"\\", "\tvasl-templates\\" )
.replace( "\t"+defaultLabelText1+"\\", "\t" + snippetContent + "\\" )
.replace( "\t"+defaultLabelText2+"\\", "\t\\" )
.replace( "\tnull;0;0", "\tMap0;" + makeVassalCoordString(pos,snippet) )
) ;
GameModule.getGameModule().getGameState().addPiece( gamePiece ) ;
labelReport.get( "created" ).add( new ReportNode( snippetId, pos ) ) ;
try {
gamePiece.setState(
gamePiece.getState().replace( "\t"+defaultUserName+"\\", "\tvasl-templates\\" )
.replace( "\t"+defaultLabelText1+"\\", "\t" + snippetContent + "\\" )
.replace( "\t"+defaultLabelText2+"\\", "\t\\" )
.replace( "\tnull;0;0", "\tMap0;" + makeVassalCoordString(pos,snippet) )
) ;
GameModule.getGameModule().getGameState().addPiece( gamePiece ) ;
labelReport.get( "created" ).add( new ReportNode( snippetId, pos ) ) ;
} catch( Exception ex ) {
String msg = "ERROR: Couldn't create label '" + snippetId + "'" ;
logger.warn( msg, ex ) ;
labelReport.get( "failed" ).add(
new ReportNode( snippetId, null, msg, ex.getMessage() )
) ;
}
}
return labelReport ;
@ -716,6 +740,11 @@ public class VassalShim
reportNodeElem.setAttribute( "x", Integer.toString( reportNode.labelPos.x ) ) ;
reportNodeElem.setAttribute( "y", Integer.toString( reportNode.labelPos.y ) ) ;
}
if ( reportNode.caption != null ) {
reportNodeElem.setAttribute( "caption", reportNode.caption ) ;
if ( reportNode.msg != null )
reportNodeElem.setTextContent( reportNode.msg ) ;
}
elem.appendChild( reportNodeElem ) ;
if ( ! key.equals( "unchanged" ) )
wasModified = true ;

Loading…
Cancel
Save