public override void _Ready() { IOpl imfOpl = new WoodyEmulatorOpl(OplType.Opl2); AddChild(ImfOplPlayer = new OplPlayer() { Opl = imfOpl, MusicPlayer = new ImfPlayer() { Opl = imfOpl, }, }); IOpl idAdlOpl = new WoodyEmulatorOpl(OplType.Opl2); AddChild(IdAdlOplPlayer = new OplPlayer() { Opl = idAdlOpl, MusicPlayer = new IdAdlPlayer() { Opl = idAdlOpl, }, }); string imfFile = "SEARCHN_MUS.imf"; if (!System.IO.File.Exists(imfFile)) { throw new FileNotFoundException(); } else { using (FileStream imfStream = new FileStream(imfFile, FileMode.Open)) ((ImfPlayer)ImfOplPlayer.MusicPlayer).Imf = Imf.ReadImf(imfStream); } string idAdlFile = "GETAMMOSND.adl"; if (!System.IO.File.Exists(idAdlFile)) { throw new FileNotFoundException(); } else { using (FileStream idAdlStream = new FileStream(idAdlFile, FileMode.Open)) Adl = new Adl(idAdlStream); } }
public static void Load(string folder, XElement xml) { Clear(); XML = xml; if (XML.Element("VSwap") != null) { VSwap = VSwap.Load(folder, XML); } if (XML.Element("Maps") != null) { Maps = GameMap.Load(folder, XML); } if (XML.Element("Audio") != null) { AudioT = AudioT.Load(folder, XML); } if (XML.Element("VgaGraph") != null) { VgaGraph = VgaGraph.Load(folder, XML); } Walls = XML.Element("VSwap")?.Element("Walls")?.Elements("Wall").Select(e => ushort.Parse(e.Attribute("Number").Value)).ToArray(); Doors = XML.Element("VSwap")?.Element("Walls")?.Elements("Door")?.Select(e => ushort.Parse(e.Attribute("Number").Value))?.ToArray(); Elevators = XML.Element("VSwap")?.Element("Walls")?.Elements("Elevator")?.Select(e => ushort.Parse(e.Attribute("Number").Value))?.ToArray(); PushWalls = PushWall?.Select(e => ushort.Parse(e.Attribute("Number").Value))?.ToArray(); States.Clear(); foreach (XElement xState in XML?.Element("VSwap")?.Element("Objects")?.Elements("State") ?? Enumerable.Empty <XElement>()) { States.Add(xState.Attribute("Name").Value, new State(xState)); } foreach (State state in States.Values) { if (state.XML.Attribute("Next")?.Value is string next) { state.Next = States[next]; } } Turns.Clear(); foreach (XElement xTurn in XML?.Element("VSwap")?.Element("Objects")?.Elements("Turn") ?? Enumerable.Empty <XElement>()) { Turns.Add((ushort)(int)xTurn.Attribute("Number"), Direction8.From(xTurn.Attribute("Direction"))); } EndStrings = XML?.Element("VgaGraph")?.Element("Menus")?.Elements("EndString")?.Select(a => a.Value)?.ToArray() ?? new string[] { "Sure you want to quit? Y/N" }; if (ushort.TryParse(XML?.Element("VSwap")?.Element("Walls")?.Attribute("FloorCodeFirst")?.Value, out ushort floorCodeFirst)) { FloorCodeFirst = floorCodeFirst; } if (ushort.TryParse(XML?.Element("VSwap")?.Element("Walls")?.Attribute("FloorCodeLast")?.Value, out ushort floorCodeLast)) { FloorCodes = (ushort)(1 + floorCodeLast - FloorCodeFirst); } // Load "extra" IMF/WLF files not included in AudioT Godot.File file = new Godot.File(); foreach (XElement songXML in XML.Element("Audio").Elements("Imf")?.Where(e => e.Attribute("File") is XAttribute)) { if (file.Open(songXML.Attribute("File").Value, Godot.File.ModeFlags.Read) == Godot.Error.Ok && file.IsOpen()) { byte[] bytes = file.GetBuffer((int)file.GetLen()); file.Close(); AudioT.Songs.Add(songXML?.Attribute("Name")?.Value, new Song() { Name = songXML?.Attribute("Name")?.Value, Bytes = bytes, Imf = Imf.ReadImf(new MemoryStream(bytes)), }); } } }