/// <summary> /// Serializes the data elements into the given file. /// </summary> /// <param name="destFile">The file where the scenario data shall be stored.</param> /// <remarks></remarks> public void WriteData(string destFile) { // Serialize data into buffer WriteData(); // Save buffer _buffer.Save(destFile); }
/// <summary> /// Schreibt die enthaltenen Daten in eine neue DAT-Datei. /// </summary> /// <param name="destFile">Die Datei, in die die Daten geschrieben werden sollen.</param> /// <remarks></remarks> public void WriteData(string destFile) { // Daten in Puffer schreiben WriteData(); // Puffer in Datei schreiben _buffer.Save(destFile); }
/// <summary> /// Speichert die enthaltene Bitmap in die angegebene Datei. /// </summary> /// <param name="filename">Die Datei, in die das Bild gespeichert werden soll.</param> /// <param name="writeFileHeader">Optional. Gibt an, ob der Dateiheader geschrieben werden oder direkt mit der BITMAPINFOHEADER-Struktur begonnen werden soll.</param> public void SaveToFile(string filename, bool writeFileHeader = true) { // Puffer-Objekt erstellen und Daten hineinschreiben RAMBuffer buffer = new RAMBuffer(); SaveToBuffer(buffer, writeFileHeader); // Als Datei speichern buffer.Save(filename); }
/*void func(Sail.SailType type, Civ civ, byte[] data) * { * SLPFile s = new SLPFile(new RAMBuffer(data)); * for(int f = 0; f < 90; ++f) * { * s._frameInformationHeaders[f].AnchorX = Sails[type].SailSlps[civ]._frameInformationHeaders[10 * ((f / 10) / 2) + (f % 10)].AnchorX; * s._frameInformationHeaders[f].AnchorY = Sails[type].SailSlps[civ]._frameInformationHeaders[10 * ((f / 10) / 2) + (f % 10)].AnchorY; * } * Sails[type].SailSlps[civ] = s; * }*/ /// <summary> /// Speichert die Schiffsdaten in der angegebenen Datei. /// </summary> /// <param name="filename">Die Zieldatei.</param> public void Save(string filename) { // Puffer erstellen RAMBuffer buffer = new RAMBuffer(); // Name schreiben buffer.WriteInteger(Name.Length); buffer.WriteString(Name); // Rumpf-SLP schreiben if (BaseSlp != null) { // SLP schreiben buffer.WriteByte(1); BaseSlp.writeData(); buffer.Write((RAMBuffer)BaseSlp.DataBuffer); } else { buffer.WriteByte(0); } // Schatten-SLP schreiben if (ShadowSlp != null) { // SLP schreiben buffer.WriteByte(1); ShadowSlp.writeData(); buffer.Write((RAMBuffer)ShadowSlp.DataBuffer); } else { buffer.WriteByte(0); } // Segel schreiben buffer.WriteByte((byte)Sails.Count); foreach (var currSail in Sails) { // Schreiben buffer.WriteByte((byte)currSail.Key); currSail.Value.WriteData(buffer); } // Invertierte Segel schreiben buffer.WriteByte((byte)InvertedSails.Count); foreach (var invSail in InvertedSails) { buffer.WriteByte((byte)invSail); } // Speichern buffer.Save(filename); }
private void _saveSimulationButton_Click(object sender, RoutedEventArgs e) { // Show dialog SaveFileDialog dialog = new SaveFileDialog { Filter = "Simulation files (*.balancingsim)|*.balancingsim", Title = "Save simulation..." }; if (!(dialog.ShowDialog() ?? false)) { return; } // Create buffer RAMBuffer buffer = new RAMBuffer(); // Write version buffer.WriteInteger(Version); // Write civ IDs buffer.WriteShort((short)(_civ1ComboBox.SelectedValue ?? (short)-1)); buffer.WriteShort((short)(_civ2ComboBox.SelectedValue ?? (short)-1)); // Run through techs and write IDs of checked ones var res1 = Researches1.Where(r => r.Checked).Select(r => r.Id).ToList(); buffer.WriteInteger(res1.Count); res1.ForEach(buffer.WriteShort); var res2 = Researches2.Where(r => r.Checked).Select(r => r.Id).ToList(); buffer.WriteInteger(res2.Count); res2.ForEach(buffer.WriteShort); // Write duels buffer.WriteInteger(Duels.Count); foreach (var duel in Duels) { buffer.WriteShort(duel.Id1); buffer.WriteShort(duel.Id2); } // Save try { buffer.Save(dialog.FileName); } catch (IOException ex) { // Error MessageBox.Show($"Unable to save simulation data: {ex.Message}"); } }
/// <summary> /// Export die enthaltenen SLPs in den gegebenen Ordner. /// Reihenfolge der Exports ist wichtig - bei Änderungen im TechTreeEditor-Plugin gegenprüfen! /// </summary> /// <param name="folder">Der Zielordner.</param> /// <param name="baseId">Die erste freie ID, zu der exportiert werden soll.</param> /// <param name="broadside">Gibt an, ob die Grafiken zusätzlich im Breitseitenmodus exportiert werden sollen.</param> /// <param name="enabledCivSets">Eine Liste mit den zu exportierenden Kultur-Grafiksets.</param> public void Export(string folder, int baseId, bool broadside, List <Civ> enabledCivSets) { // Die aktuell freie ID int currId = baseId; // Basispfad bauen string baseFileName = Path.Combine(folder, Name); // Der XML-Projektdatei-Code string xmlCode = ""; // Hilfsfunktion fürs Exportieren Action <SLPFile, string> exportSlp = (slp, suffix) => { // Exportstruktur anlegen DRSLibrary.DRSFile.ExternalFile extFile = new DRSLibrary.DRSFile.ExternalFile(); // Breitseitenmodus? SLPFile slpE = slp; if (broadside) { // Suffix erweitern suffix += " [B]"; // Neue SLP mit umkopierten Frames erzeugen slp.writeData(); RAMBuffer tmpBuffer = (RAMBuffer)slp.DataBuffer; tmpBuffer.Position = 0; slpE = new SLPFile(tmpBuffer); slpE._frameInformationHeaders.Clear(); slpE._frameInformationData.Clear(); // Drehrichtungen vorne bis links (-> links bis hinten) for (int i = 4; i <= 8; ++i) { // Alle Frames der Drehrichtung kopieren for (int f = i * (int)(slp.FrameCount / 9); f < (i + 1) * (int)(slp.FrameCount / 9); ++f) { // Header kopieren SLPFile.FrameInformationHeader fHead = new SLPFile.FrameInformationHeader(); fHead.AnchorX = slp._frameInformationHeaders[f].AnchorX; fHead.AnchorY = slp._frameInformationHeaders[f].AnchorY; fHead.Width = slp._frameInformationHeaders[f].Width; fHead.Height = slp._frameInformationHeaders[f].Height; fHead.Properties = slp._frameInformationHeaders[f].Properties; slpE._frameInformationHeaders.Add(fHead); // Daten kopieren SLPFile.FrameInformationData fData = new SLPFile.FrameInformationData(); fData.BinaryCommandTable = new List <SLPFile.BinaryCommand>(slp._frameInformationData[f].BinaryCommandTable); fData.BinaryRowEdge = slp._frameInformationData[f].BinaryRowEdge; fData.CommandTable = slp._frameInformationData[f].CommandTable; fData.CommandTableOffsets = new uint[slp._frameInformationData[f].CommandTableOffsets.Length]; fData.RowEdge = slp._frameInformationData[f].RowEdge; slpE._frameInformationData.Add(fData); } } // Drehrichtungen links links hinten bis hinten (-> hinten hinten rechts bis rechts) for (int i = 7; i >= 4; --i) { // Alle Frames der Drehrichtung spiegeln und kopieren for (int f = i * (int)(slp.FrameCount / 9); f < (i + 1) * (int)(slp.FrameCount / 9); ++f) { // Header kopieren SLPFile.FrameInformationHeader fHead = new SLPFile.FrameInformationHeader(); fHead.AnchorX = (int)slp._frameInformationHeaders[f].Width - slp._frameInformationHeaders[f].AnchorX; fHead.AnchorY = slp._frameInformationHeaders[f].AnchorY; fHead.Width = slp._frameInformationHeaders[f].Width; fHead.Height = slp._frameInformationHeaders[f].Height; fHead.Properties = slp._frameInformationHeaders[f].Properties; slpE._frameInformationHeaders.Add(fHead); // Daten spiegeln und kopieren SLPFile.FrameInformationData fData = new SLPFile.FrameInformationData(); fData.BinaryCommandTable = new List <SLPFile.BinaryCommand>(); fData.BinaryRowEdge = new SLPFile.BinaryRowedge[slp._frameInformationData[f].BinaryRowEdge.Length]; for (int bre = 0; bre < fData.BinaryRowEdge.Length; ++bre) { fData.BinaryRowEdge[bre] = new SLPFile.BinaryRowedge(slp._frameInformationData[f].BinaryRowEdge[bre]._right, slp._frameInformationData[f].BinaryRowEdge[bre]._left); } fData.RowEdge = new ushort[fHead.Height, 2]; for (int re = 0; re < fHead.Height; ++re) { fData.RowEdge[re, 0] = slp._frameInformationData[f].RowEdge[re, 1]; fData.RowEdge[re, 1] = slp._frameInformationData[f].RowEdge[re, 0]; } fData.CommandTable = new int[fHead.Height, fHead.Width]; for (int h = 0; h < fHead.Height; ++h) { for (int w = 0; w < fHead.Width; ++w) { fData.CommandTable[h, fHead.Width - w - 1] = slp._frameInformationData[f].CommandTable[h, w]; } } fData.CommandTableOffsets = new uint[slp._frameInformationData[f].CommandTableOffsets.Length]; slpE.CreateBinaryCommandTable(fData, (int)fHead.Width, (int)fHead.Height, slpE._settings); slpE._frameInformationData.Add(fData); } } } // SLP-Daten lesen und zuweisen slpE.writeData(); RAMBuffer slpBuffer = (RAMBuffer)slpE.DataBuffer; slpBuffer.Position = 0; extFile.Data = slpBuffer.ReadByteArray(slpBuffer.Length); // Metadaten festlegen extFile.DRSFile = "graphics"; extFile.FileID = (uint)(currId++); extFile.ResourceType = "slp"; // Exportdatei speichern extFile.ToBinary().Save(Path.Combine(folder, extFile.FileID + ".res")); // XML-Code generieren xmlCode += "<ResFile>" + extFile.FileID + ".res</ResFile>\r\n"; // SLP speichern if (!string.IsNullOrEmpty(suffix)) { slpBuffer.Save(baseFileName + " " + suffix + ".slp"); } else { slpBuffer.Save(baseFileName + ".slp"); } }; // Schatten und Rumpf exportieren if (ShadowSlp != null) { exportSlp(ShadowSlp, "(Schatten)"); } if (BaseSlp != null) { exportSlp(BaseSlp, ""); } // Hilfsfunktion für Segel-Export (Reihenfolge wichtig für ID-Vergabe) Action <Civ> exportCivSails = (civ) => { // Segel exportieren if (Sails[Sail.SailType.MainGo].Used) { exportSlp(Sails[Sail.SailType.MainGo].SailSlps[civ], "(" + Sail.SailTypeNames[Sail.SailType.MainGo] + ") [" + CivNames[civ] + "]"); } if (Sails[Sail.SailType.Small1].Used) { exportSlp(Sails[Sail.SailType.Small1].SailSlps[civ], "(" + Sail.SailTypeNames[Sail.SailType.Small1] + ") [" + CivNames[civ] + "]"); } if (Sails[Sail.SailType.Mid1].Used) { exportSlp(Sails[Sail.SailType.Mid1].SailSlps[civ], "(" + Sail.SailTypeNames[Sail.SailType.Mid1] + ") [" + CivNames[civ] + "]"); } if (Sails[Sail.SailType.Large1].Used) { exportSlp(Sails[Sail.SailType.Large1].SailSlps[civ], "(" + Sail.SailTypeNames[Sail.SailType.Large1] + ") [" + CivNames[civ] + "]"); } if (Sails[Sail.SailType.MainStop].Used) { exportSlp(Sails[Sail.SailType.MainStop].SailSlps[civ], "(" + Sail.SailTypeNames[Sail.SailType.MainStop] + ") [" + CivNames[civ] + "]"); } if (Sails[Sail.SailType.Large2].Used) { exportSlp(Sails[Sail.SailType.Large2].SailSlps[civ], "(" + Sail.SailTypeNames[Sail.SailType.Large2] + ") [" + CivNames[civ] + "]"); } if (Sails[Sail.SailType.Mid2].Used) { exportSlp(Sails[Sail.SailType.Mid2].SailSlps[civ], "(" + Sail.SailTypeNames[Sail.SailType.Mid2] + ") [" + CivNames[civ] + "]"); } if (Sails[Sail.SailType.Small2].Used) { exportSlp(Sails[Sail.SailType.Small2].SailSlps[civ], "(" + Sail.SailTypeNames[Sail.SailType.Small2] + ") [" + CivNames[civ] + "]"); } }; // Segel kulturweise exportieren foreach (Civ civSet in enabledCivSets) { exportCivSails(civSet); } // XML-Code speichern File.WriteAllText(Path.Combine(folder, "projectdata" + (broadside ? "_b" : "") + ".xml"), xmlCode); // Ggf. noch die Nicht-Breitseiten-Frames exportieren if (broadside) { Export(folder, currId, false, enabledCivSets); } }