Changeset 155 in tmcsimulator-scriptbuilder for trunk/src/scriptbuilder/structures/SimulationScript.java


Ignore:
Timestamp:
11/20/2019 03:22:38 PM (6 years ago)
Author:
sdanthin
Message:

units.xml moved to Incidents folder

File:
1 edited

Legend:

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

    r145 r155  
    55import java.io.File; 
    66import java.io.FileWriter; 
     7import java.io.IOException; 
    78import java.util.ArrayList; 
    89import java.util.List; 
     
    1213import scriptbuilder.structures.ScriptIncident.IncidentFocusedEvent; 
    1314import scriptbuilder.structures.ScriptIncident.SliceChangedEvent; 
     15import scriptbuilder.structures.events.*; 
    1416import scriptbuilder.structures.units.Unit; 
     17import java.nio.file.Path; 
     18import java.nio.file.Paths; 
     19import java.util.TreeMap; 
    1520 
    1621/** 
     
    256261            ex.printStackTrace(); 
    257262        } 
     263        try 
     264        { 
     265            createAudioDirectory(Paths.get(f.getCanonicalPath()).getParent()); 
     266        } 
     267        catch(IOException ex) 
     268        { 
     269            System.err.println("there was a problem creating the audio directories."); 
     270        } 
     271         
     272         
    258273        saved = true; 
    259274    } 
    260  
     275    private void createAudioDirectory(Path path){ 
     276        File f = new File(path.toString()+"/audio"); 
     277        if(!f.exists()) 
     278        { 
     279            f.mkdir(); 
     280            //scan through to see what is already there and then make changes accordingly. 
     281        } 
     282        for(ScriptIncident i : incidents) 
     283        { 
     284            if(i!=null) 
     285            { 
     286                String name = ((Integer) i.number).toString(); 
     287                File incidentFolder = new File(path.toString()+"/audio/"+name); 
     288                if(incidentFolder.exists()) 
     289                { 
     290                    //check to see if there are already files for the given incidents 
     291                    //not sure how the ordering of the files should be. 
     292                    //check to see if folder needs filling 
     293                }else 
     294                { 
     295 
     296                    //create an incidentfolder since one does not already exist 
     297                    incidentFolder.mkdir(); 
     298                    int fileCount = 1; 
     299                    for(TimeSlice slice : i.getSlices()) 
     300                    { 
     301                        for(I_ScriptEvent event : slice.events) 
     302                        { 
     303                            if(event.getScriptEventType().equals(ScriptEvent.ScriptEventType.CHP_RADIO_EVENT)) 
     304                            { 
     305                                //if the event is a chp radio event 
     306                                //then add the dummy file to the subdirectory created 
     307                                CHPRadioEvent radioEvent = (CHPRadioEvent) event; 
     308                                 
     309                                String output = radioEvent.toScriptFile(); 
     310                                 
     311                                File newAudioScript = new File(path.toString()+"/audio/"+name+"/"+name+fileCount+".txt"); 
     312                                 
     313                                fileCount++; 
     314                                try 
     315                                { 
     316                                    newAudioScript.createNewFile(); 
     317                                    BufferedWriter bw = new BufferedWriter(new FileWriter(newAudioScript)); 
     318                                    bw.write(output); 
     319                                    bw.flush(); 
     320                                    bw.close(); 
     321                                }catch(Exception e) 
     322                                { 
     323                                    System.err.println("there was a problem creating your text files"); 
     324                                } 
     325 
     326                            } 
     327                        } 
     328                    } 
     329 
     330                } 
     331            } 
     332 
     333             
     334        } 
     335         
     336         
     337    } 
    261338    @Override 
    262339    public String toXML() 
Note: See TracChangeset for help on using the changeset viewer.