diff --git a/vasl_templates/webapp/static/vassal.js b/vasl_templates/webapp/static/vassal.js index 1451381..9d4fc82 100644 --- a/vasl_templates/webapp/static/vassal.js +++ b/vasl_templates/webapp/static/vassal.js @@ -72,8 +72,10 @@ function _show_label_report_msg( report ) buf.push( "" ) ; 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 ) ; diff --git a/vasl_templates/webapp/vassal.py b/vasl_templates/webapp/vassal.py index 89444d8..02d1d0e 100644 --- a/vasl_templates/webapp/vassal.py +++ b/vasl_templates/webapp/vassal.py @@ -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( "{}
{}
".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 diff --git a/vassal-shim/release/vassal-shim.jar b/vassal-shim/release/vassal-shim.jar index ffd038f..8054b53 100644 Binary files a/vassal-shim/release/vassal-shim.jar and b/vassal-shim/release/vassal-shim.jar differ diff --git a/vassal-shim/src/vassal_shim/ReportNode.java b/vassal-shim/src/vassal_shim/ReportNode.java index 4d772d8..0ab467c 100644 --- a/vassal-shim/src/vassal_shim/ReportNode.java +++ b/vassal-shim/src/vassal_shim/ReportNode.java @@ -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 ) { diff --git a/vassal-shim/src/vassal_shim/VassalShim.java b/vassal-shim/src/vassal_shim/VassalShim.java index f3f1713..0fade33 100644 --- a/vassal-shim/src/vassal_shim/VassalShim.java +++ b/vassal-shim/src/vassal_shim/VassalShim.java @@ -377,7 +377,7 @@ public class VassalShim { // initialize Map< String, ArrayList > labelReport = new HashMap>() ; - for ( String key: new String[]{"created","updated","deleted","unchanged"} ) + for ( String key: new String[]{"created","updated","deleted","unchanged","failed"} ) labelReport.put( key, new ArrayList() ) ; // 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 ;