Changeset 145 in tmcsimulator-scriptbuilder for trunk/src/scriptbuilder/structures/SimulationScript.java
- Timestamp:
- 11/04/2019 08:14:32 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/scriptbuilder/structures/SimulationScript.java
r131 r145 21 21 * 22 22 * @author Bryan McGuffin <bmcguffi@calpoly.edu> 23 * @author Sebastien Danthinne <sdanthin@calpoly.edu> 23 24 * @version 2017/06/22 24 25 */ … … 61 62 * The units which participate in Unit events. 62 63 */ 63 public List<Unit> units; 64 public List<Unit> units; 64 65 65 66 //Somewhere in the code, something assumes that the list of incidents 66 67 //contains exactly 10 items. Until I can find and un-break that, this will do. 68 //todo: this incident fill count error 67 69 private final int INCIDENT_FILL_COUNT = 10; 68 70 … … 76 78 */ 77 79 private MyScriptHandler sh; 80 81 public boolean saved; 78 82 79 83 //TODO: Pretty much everything in this constructor is dummy data. … … 89 93 units = new ArrayList<Unit>(); 90 94 numberOfIncidents = 0; 95 saved = true; 91 96 92 97 //Backfill with null incidents … … 96 101 } 97 102 } 98 103 104 /** 105 * checks and sees if this object has the unit passed. 106 * @param unitID 107 * @return does this SimulationScript have unitnum? 108 */ 109 public boolean hasUnit(String unitID){ 110 boolean indicator = false; 111 if(units.size()!=0){ 112 for(Unit u : units){ 113 if(unitID.equals(u.UnitNum)){ 114 indicator = true; 115 } 116 } 117 } 118 119 return indicator; 120 } 121 /** 122 * creates a dummy unit that only has unit number 123 * @param unitNum 124 */ 125 public void addDummyUnit(String unitNum){ 126 Unit dummy = new Unit(); 127 dummy.UnitNum = unitNum; 128 units.add(dummy); 129 } 99 130 /** 100 131 * Update the script's observers. 101 * 132 * 102 133 */ 103 134 public void update() 104 135 { 105 136 // The script has changed, notify observers 137 //use to rewrite the save indicator 138 //System.out.println("Script changed"); 106 139 setChanged(); 107 140 notifyObservers(this); 108 } 141 saved = false; 142 143 144 } 145 109 146 110 147 /** … … 154 191 { 155 192 System.out.println("ERROR LOADING SCRIPT"); 193 ex.printStackTrace(); 194 } 195 System.out.println("H"); 196 for(Unit testUnit : units){ 197 System.out.println(testUnit.toXML()); 198 } 199 this.update(); 200 } 201 202 /** 203 * Load in an existing list of units from an XML file. 204 * @param f the file containing the units 205 */ 206 public void loadUnitsFromFile(File f){ 207 try 208 { 209 SAXParserFactory.newInstance().newSAXParser().parse(f, sh); 210 units.addAll(sh.getUnits()); 211 } 212 catch (Exception ex) 213 { 214 System.out.println("ERROR LOADING UNITS"); 156 215 ex.printStackTrace(); 157 216 } … … 197 256 ex.printStackTrace(); 198 257 } 258 saved = true; 199 259 } 200 260
Note: See TracChangeset
for help on using the changeset viewer.
