public TrafficFile(string fileName) { using (var stf = new STFReader(fileName, false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("traffic_definition", () => { TrafficDefinition = new ServiceTraffic(stf); }), }); }
private void ReadFile(string filePath) { using (STFReader stf = new STFReader(filePath, false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("tr_sms", () => { Tr_SMS = new Tr_SMS(stf); }), }); }
public CabViewFile(string basePath, string fileName) { using (STFReader stf = new STFReader(Path.GetFullPath(Path.Combine(basePath, fileName)), false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("tr_cabviewfile", () => { stf.MustMatchBlockStart(); stf.ParseBlock(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("position", () => { Locations.Add(stf.ReadVector3Block(STFReader.Units.None, new Vector3())); }), new STFReader.TokenProcessor("direction", () => { Directions.Add(stf.ReadVector3Block(STFReader.Units.None, new Vector3())); }), new STFReader.TokenProcessor("cabviewfile", () => { string cvfileName = stf.ReadStringBlock(null); string path = Path.Combine(basePath, Path.GetDirectoryName(cvfileName)); string name = Path.GetFileName(cvfileName); // Use *Frnt1024.ace if available if (!Path.GetFileNameWithoutExtension(cvfileName).EndsWith("1024", StringComparison.OrdinalIgnoreCase)) { string name1024 = Path.GetFileNameWithoutExtension(cvfileName) + "1024" + Path.GetExtension(cvfileName); if (File.Exists(Path.Combine(path, name1024))) { name = name1024; } } Views2D.Add(Path.Combine(path, name)); ViewsNight.Add(Path.Combine(path, "NIGHT", name)); ViewsLight.Add(Path.Combine(path, "CABLIGHT", name)); }), new STFReader.TokenProcessor("cabviewcontrols", () => { CabViewControls = new CabViewControls(stf, basePath); }), }); }), }); }
/// <summary> /// Constructor from file /// </summary> /// <param name="filenamewithpath">Full file name of the .rdb file</param> public RoadDatabaseFile(string filenamewithpath) { using (STFReader stf = new STFReader(filenamewithpath, false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("trackdb", () => { RoadTrackDB = new RoadTrackDB(stf); }), }); }
public TrafficFile(string filePath) { using (var stf = new STFReader(filePath, false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("traffic_definition", () => { TrafficDefinition = new Traffic_Traffic_Definition(stf); }), }); }
public RouteFile(string filename) { string dir = Path.GetDirectoryName(filename); string file = Path.GetFileName(filename); string orFile = dir + @"\openrails\" + file; if (File.Exists(orFile)) { filename = orFile; } try { using (STFReader stf = new STFReader(filename, false)) { stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("tr_routefile", () => { Tr_RouteFile = new Tr_RouteFile(stf); }), new STFReader.TokenProcessor("_OpenRails", () => { ORTRKData = new ORTRKData(stf); }), }); //TODO This should be changed to STFException.TraceError() with defaults values created if (Tr_RouteFile == null) { throw new STFException(stf, "Missing Tr_RouteFile"); } } } finally { if (ORTRKData == null) { ORTRKData = new ORTRKData(); } } }
public SoundManagmentFile(string fileName) { using (STFReader stf = new STFReader(fileName, false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("tr_sms", () => { ParseTrackSms(stf); }), }); }
public CameraConfigurationFile(string filename) { using (STFReader stf = new STFReader(filename, false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("camera", () => { Cameras.Add(new Camera(stf)); }), }); }
public RouteFile(string fileName) { string dir = Path.GetDirectoryName(fileName); string file = Path.GetFileName(fileName); string orFile = Path.Combine(dir, "openrails", file); if (File.Exists(orFile)) { fileName = orFile; } try { using (STFReader stf = new STFReader(fileName, false)) { stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("tr_routefile", () => { Route = new Route(stf); }), new STFReader.TokenProcessor("_OpenRails", () => { TrackData = new ORTrackData(stf); }), }); if (Route == null) { throw new STFException(stf, "Missing Tr_RouteFile"); } } } finally { if (TrackData == null) { TrackData = new ORTrackData(); } } }
public CabViewControls CabViewControls; // Controls in CAB - by GeorgeS public CabViewFile(string filePath, string basePath) { using (STFReader stf = new STFReader(filePath, false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("tr_cabviewfile", () => { stf.MustMatch("("); stf.ParseBlock(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("position", () => { Locations.Add(stf.ReadVector3Block(STFReader.UNITS.None, new Vector3())); }), new STFReader.TokenProcessor("direction", () => { Directions.Add(stf.ReadVector3Block(STFReader.UNITS.None, new Vector3())); }), new STFReader.TokenProcessor("cabviewfile", () => { var fileName = stf.ReadStringBlock(null); var path = Path.Combine(basePath, Path.GetDirectoryName(fileName)); var name = Path.GetFileName(fileName); // Use *Frnt1024.ace if available string s = name; string[] nameParts = s.Split('.'); string name1024 = nameParts[0] + "1024." + nameParts[1]; var tstFileName1024 = Path.Combine(path, name1024); if (File.Exists(tstFileName1024)) { name = name1024; } TwoDViews.Add(Path.Combine(path, name)); NightViews.Add(Path.Combine(path, Path.Combine("NIGHT", name))); LightViews.Add(Path.Combine(path, Path.Combine("CABLIGHT", name))); }), new STFReader.TokenProcessor("cabviewcontrols", () => { CabViewControls = new CabViewControls(stf, basePath); }), }); }), }); }
/// <summary> /// Constructor from file /// </summary> /// <param name="filenamewithpath">Full file name of the .rdb file</param> public TrackDatabaseFile(string fileName) { using (STFReader stf = new STFReader(fileName, false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("trackdb", () => { TrackDB = new TrackDB(stf); }), }); }
public ConsistFile(string fileName) { using (STFReader stf = new STFReader(fileName, false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("train", () => { Train = new TrainSet(stf); }), }); Name = Train.Name; }
public ConsistFile(string filePath) { using (var stf = new STFReader(filePath, false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("train", () => { Train = new Train_Config(stf); }), }); Name = Train.TrainCfg.Name; }
public ShapeDescriptorFile(string filename) { using (STFReader stf = new STFReader(filename, false)) { stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("shape", ()=>{ shape = new SDShape(stf); }), }); //TODO This should be changed to STFException.TraceError() with defaults values created if (shape == null) throw new STFException(stf, "Missing shape statement"); } }
public ActivityFile(string fileName) { using (STFReader stf = new STFReader(fileName, false)) { stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("tr_activity", () => { Activity = new Activity(stf); }), }); if (Activity == null) { STFException.TraceWarning(stf, "Missing Tr_Activity statement"); } } }
public WagonFile(string fileName) { Name = Path.GetFileNameWithoutExtension(fileName); using (var stf = new STFReader(fileName, false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("wagon", () => { stf.ReadString(); stf.ParseBlock(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("name", () => { Name = stf.ReadStringBlock(null); }), }); }), }); }
public ORActivitySettingsFile(string fileName) { using (STFReader stf = new STFReader(fileName, false)) { bool tokenPresent = false; stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("tr_activity", () => { tokenPresent = true; ParseORActivitySettings(stf); }), }); if (!tokenPresent) { STFException.TraceWarning(stf, "Missing Tr_Activity statement"); } } }
public ServiceFile(string fileName) { using (STFReader stf = new STFReader(fileName, false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("service_definition", () => { stf.MustMatchBlockStart(); stf.ParseBlock(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("serial", () => { Serial = stf.ReadIntBlock(null); }), new STFReader.TokenProcessor("name", () => { Name = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("train_config", () => { TrainConfig = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("pathid", () => { PathId = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("maxwheelacceleration", () => { MaxWheelAcceleration = stf.ReadFloatBlock(STFReader.Units.Any, null); }), new STFReader.TokenProcessor("efficiency", () => { Efficiency = stf.ReadFloatBlock(STFReader.Units.Any, null); }), new STFReader.TokenProcessor("timetable", () => { TimeTable = new TimeTable(stf); }), }); }), }); }
public EngineFile(string fileName) { Name = Path.GetFileNameWithoutExtension(fileName); using (var stf = new STFReader(fileName, false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("engine", () => { stf.ReadString(); stf.ParseBlock(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("name", () => { Name = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("description", () => { Description = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("cabview", () => { CabViewFile = stf.ReadStringBlock(null); }), }); }), }); }
public void AddRouteTSectionDatFile(string pathNameExt) { using (STFReader stf = new STFReader(pathNameExt, false)) { if (stf.SimisSignature != "SIMISA@@@@@@@@@@JINX0T0t______") { Trace.TraceWarning("Skipped invalid TSECTION.DAT in route folder"); return; } stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("tracksections", () => { TrackSections.AddRouteTrackSections(stf); }), new STFReader.TokenProcessor("sectionidx", () => { TSectionIdx = new TSectionIdx(stf); }), // todo read in SectionIdx part of RouteTSectionDat }); } }
static SortedList <double, string> GetList(Simulator simulator, char type) { string ending = "*.eng"; if (type == 'w') { ending = "*.wag"; } string[] filePaths = Directory.GetFiles(simulator.BasePath + "\\trains\\trainset", ending, SearchOption.AllDirectories); string temp; List <string> allEngines = new List <string>(); SortedList <double, string> carList = new SortedList <double, string>(); for (var i = 0; i < filePaths.Length; i++) { int index = filePaths[i].LastIndexOf("\\trains\\trainset\\"); temp = filePaths[i].Substring(index + 17); if (!temp.Contains("\\")) { continue; } allEngines.Add(temp); } foreach (string name in allEngines) { double len = 0.0f; Microsoft.Xna.Framework.Vector3 def = new Microsoft.Xna.Framework.Vector3(); try { using (var stf = new STFReader(simulator.BasePath + "\\trains\\trainset\\" + name, false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("wagon", () => { stf.ReadString(); stf.ParseBlock(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("size", () => { def = stf.ReadVector3Block(STFReader.UNITS.Distance, def); }), }); }), }); len = def.Z; carList.Add(len + MPManager.Random.NextDouble() / 10.0f, name); } catch { } } return(carList); }
public void Read(string wsfilename, TrItem[] trItems) { if (File.Exists(wsfilename)) { Trace.Write("$"); using (STFReader stf = new STFReader(wsfilename, false)) { stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("tr_worldsoundfile", () => { TR_WorldSoundFile = new TR_WorldSoundFile(stf, trItems); }), }); if (TR_WorldSoundFile == null) { STFException.TraceWarning(stf, "Missing TR_WorldSoundFile statement"); } } } }
/// <summary> /// Constructor from file /// </summary> /// <param name="filenamewithpath">Full file name of the sigcfg.dat file</param> /// <param name="ORTSMode">Read file in ORTSMode (set NumClearAhead_ORTS only)</param> public SignalConfigurationFile(string filenamewithpath, bool ORTSMode) { ScriptPath = Path.GetDirectoryName(filenamewithpath); using (STFReader stf = new STFReader(filenamewithpath, false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("lighttextures", () => { LightTextures = ReadLightTextures(stf); }), new STFReader.TokenProcessor("lightstab", () => { LightsTable = ReadLightsTable(stf); }), new STFReader.TokenProcessor("signaltypes", () => { SignalTypes = ReadSignalTypes(stf, ORTSMode); }), new STFReader.TokenProcessor("signalshapes", () => { SignalShapes = ReadSignalShapes(stf); }), new STFReader.TokenProcessor("scriptfiles", () => { ScriptFiles = ReadScriptFiles(stf); }), }); Initialize <Dictionary <string, LightTexture>, IDictionary <string, LightTexture> >(ref LightTextures, "LightTextures", filenamewithpath); Initialize <Dictionary <string, LightTableEntry>, IDictionary <string, LightTableEntry> >(ref LightsTable, "LightsTab", filenamewithpath); Initialize <Dictionary <string, SignalType>, IDictionary <string, SignalType> >(ref SignalTypes, "SignalTypes", filenamewithpath); Initialize <Dictionary <string, SignalShape>, IDictionary <string, SignalShape> >(ref SignalShapes, "SignalShapes", filenamewithpath); Initialize <List <string>, IList <string> >(ref ScriptFiles, "ScriptFiles", filenamewithpath); }
/// <summary> /// Open a PAT file, parse it and store it /// </summary> /// <param name="fileName">path to the PAT file, including full path and extension</param> public PathFile(string fileName) { try { using (STFReader stf = new STFReader(fileName, false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("trackpdps", () => { stf.MustMatchBlockStart(); stf.ParseBlock(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("trackpdp", () => { DataPoints.Add(new PathDataPoint(stf)); }), }); }), new STFReader.TokenProcessor("trackpath", () => { stf.MustMatchBlockStart(); stf.ParseBlock(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("trpathname", () => { PathID = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("name", () => { Name = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("trpathflags", () => { Flags = (PathFlags)stf.ReadHexBlock(null); }), new STFReader.TokenProcessor("trpathstart", () => { Start = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("trpathend", () => { End = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("trpathnodes", () => { stf.MustMatchBlockStart(); int count = stf.ReadInt(null); stf.ParseBlock(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("trpathnode", () => { if (--count < 0) { STFException.TraceWarning(stf, "Skipped extra TrPathNodes"); } else { PathNodes.Add(new PathNode(stf)); } }), }); if (count > 0) { STFException.TraceWarning(stf, count + " missing TrPathNodes(s)"); } }), }); }), }); } catch (Exception error) { Trace.TraceWarning(error.Message); } }
public TrackSectionsFile(string filePath) { using (STFReader stf = new STFReader(filePath, false)) { stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("tracksections", () => { TrackSections = new TrackSections(stf); }), new STFReader.TokenProcessor("trackshapes", () => { TrackShapes = new TrackShapes(stf); }), }); //TODO This should be changed to STFException.TraceError() with defaults values created if (TrackSections == null) { throw new STFException(stf, "Missing TrackSections"); } if (TrackShapes == null) { throw new STFException(stf, "Missing TrackShapes"); } } }
public HazardFile(string fileName) { try { using (STFReader stf = new STFReader(fileName, false)) { stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("tr_worldfile", () => { Hazard = new Hazard(stf); }), }); //TODO This should be changed to STFException.TraceError() with defaults values created if (Hazard == null) { throw new STFException(stf, "Missing Tr_WorldFile"); } } } finally { } }
/// <summary> /// Constructor from file /// </summary> /// <param name="fileName">Full file name of the sigcfg.dat file</param> /// <param name="orMode">Read file in OR Mode (set NumClearAhead_ORTS only)</param> public SignalConfigurationFile(string fileName, bool orMode) { ScriptPath = Path.GetDirectoryName(fileName); OrSignalTypes.Reset(); // preset OR function types and related MSTS function types for default types OrSignalTypes.Instance.FunctionTypes.AddRange(EnumExtension.GetNames <SignalFunction>()); if (orMode) { using (STFReader stf = new STFReader(fileName, false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("lighttextures", () => { LightTextures = ReadLightTextures(stf); }), new STFReader.TokenProcessor("lightstab", () => { LightsTable = ReadLightsTable(stf); }), new STFReader.TokenProcessor("ortssignalfunctions", () => { ReadOrtsSignalFunctionTypes(stf); }), new STFReader.TokenProcessor("ortsnormalsubtypes", () => { ReadOrtsNormalSubtypes(stf); }), new STFReader.TokenProcessor("signaltypes", () => { SignalTypes = ReadSignalTypes(stf, orMode); }), new STFReader.TokenProcessor("signalshapes", () => { SignalShapes = ReadSignalShapes(stf); }), new STFReader.TokenProcessor("scriptfiles", () => { ScriptFiles = ReadScriptFiles(stf); }), }); } else { using (STFReader stf = new STFReader(fileName, false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("lighttextures", () => { LightTextures = ReadLightTextures(stf); }), new STFReader.TokenProcessor("lightstab", () => { LightsTable = ReadLightsTable(stf); }), new STFReader.TokenProcessor("signaltypes", () => { SignalTypes = ReadSignalTypes(stf, orMode); }), new STFReader.TokenProcessor("signalshapes", () => { SignalShapes = ReadSignalShapes(stf); }), new STFReader.TokenProcessor("scriptfiles", () => { ScriptFiles = ReadScriptFiles(stf); }), }); } LightTextures = CheckAndInitialize(LightTextures, nameof(LightTextures), fileName); LightsTable = CheckAndInitialize(LightsTable, nameof(LightsTable), fileName); SignalTypes = CheckAndInitialize(SignalTypes, nameof(SignalTypes), fileName); SignalShapes = CheckAndInitialize(SignalShapes, nameof(SignalShapes), fileName); ScriptFiles = CheckAndInitialize(ScriptFiles, nameof(ScriptFiles), fileName); }
public EnvironmentFile(string filePath) { using (STFReader stf = new STFReader(filePath, false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("world", () => { stf.MustMatch("("); stf.ParseBlock(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("world_water", () => { stf.MustMatch("("); stf.ParseBlock(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("world_water_wave_height", () => { WaterWaveHeight = stf.ReadFloatBlock(STFReader.UNITS.Distance, null); }), new STFReader.TokenProcessor("world_water_wave_speed", () => { WaterWaveSpeed = stf.ReadFloatBlock(STFReader.UNITS.Speed, null); }), new STFReader.TokenProcessor("world_water_layers", () => { ParseWaterLayers(stf); }), }); }), }); }), }); using (STFReader stf = new STFReader(filePath, false)) stf.ParseFile(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("world", () => { stf.MustMatch("("); stf.ParseBlock(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("world_sky", () => { stf.MustMatch("("); stf.ParseBlock(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("worldskynlayers_behind_satellites", () => { WorldSkynLayers = stf.ReadFloatBlock(STFReader.UNITS.Any, null); }), new STFReader.TokenProcessor("world_sky_layers", () => { ParseSkyLayers(stf); }), new STFReader.TokenProcessor("world_sky_satellites", () => { ParseWorldSkySatellites(stf); }), }); }), }); }), }); }