Changeset 30 in tmcsimulator-scriptbuilder for trunk/src/scriptbuilder/structures/TimeSlice.java


Ignore:
Timestamp:
08/02/2017 12:48:06 PM (9 years ago)
Author:
bmcguffin
Message:

Made TimeSlice?, ScriptIncident?, and SimulationScript? all implement I_XML_Writable. Simulationscript also now implements a saveScriptToFile() method.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/scriptbuilder/structures/TimeSlice.java

    r21 r30  
    88import java.util.TimeZone; 
    99import scriptbuilder.gui.ScriptBuilderGuiConstants; 
     10import scriptbuilder.structures.events.*; 
    1011import scriptbuilder.structures.events.I_ScriptEvent; 
    1112 
     
    194195 
    195196    /** 
    196      * Converts the contents of this timeslice to a correctly 
    197      * formatted <ScriptEvent> XML element. 
     197     * Converts the contents of this timeslice to a correctly formatted 
     198     * <ScriptEvent> XML element. 
    198199     * 
    199200     * @return XML conversion of this timeslice. 
     
    202203    public String toXML() 
    203204    { 
     205        ArrayList<I_ScriptEvent> eventsCopy = new ArrayList<I_ScriptEvent>(); 
     206 
     207        for (I_ScriptEvent e : events) 
     208        { 
     209            eventsCopy.add(e); 
     210        } 
     211 
    204212        System.out.println("Seconds:: " + seconds); 
    205213        String output = openTag(ELEMENT.SCRIPT_EVENT.tag); 
     
    212220        output += thisIncident.name + closeTag(ELEMENT.INCIDENT.tag); 
    213221 
    214         for (I_ScriptEvent ev : events) 
     222        output += openTag(ELEMENT.CAD_DATA.tag); 
     223        if (containsCADIncidentEvent()) 
     224        { 
     225            output += openTag(ELEMENT.CAD_INCIDENT_EVENT.tag); 
     226            for (I_ScriptEvent ev : eventsCopy) 
     227            { 
     228                if (ev instanceof I_XML_Writable && isCADIncidentEvent(ev)) 
     229                { 
     230                    I_XML_Writable ex = (I_XML_Writable) ev; 
     231                    output += ex.toXML(); 
     232                    eventsCopy.remove(ev); 
     233                } 
     234            } 
     235            output += closeTag(ELEMENT.CAD_INCIDENT_EVENT.tag); 
     236        } 
     237        output += closeTag(ELEMENT.CAD_DATA.tag); 
     238 
     239        for (I_ScriptEvent ev : eventsCopy) 
    215240        { 
    216241            if (ev instanceof I_XML_Writable) 
     
    242267        return "<" + s + "/>\n"; 
    243268    } 
     269 
     270    private boolean containsCADIncidentEvent() 
     271    { 
     272        for (I_ScriptEvent ev : events) 
     273        { 
     274            if (isCADIncidentEvent(ev)) 
     275            { 
     276                return true; 
     277            } 
     278        } 
     279        return false; 
     280    } 
     281 
     282    private boolean isCADIncidentEvent(I_ScriptEvent ev) 
     283    { 
     284        return ev instanceof AudioEvent || ev instanceof UnitEvent 
     285                || ev instanceof ParamicsEvent || ev instanceof TowEvent 
     286                || ev instanceof WitnessEvent; 
     287    } 
    244288} 
Note: See TracChangeset for help on using the changeset viewer.