Beispiel #1
0
    private void RefreshDisplay()
    {
        Godot.File file = new Godot.File();
        file.Open(this.SaveLocation, File.ModeFlags.Read);
        if (file.IsOpen())
        {
            this.HasSaveData = true;
        }
        else
        {
            this.HasSaveData = false;
        }
        file.Close();

        if (this.HasSaveData)
        {
            this._loadButton.Text = String.Format("Save Slot {0} - (data)", this.SlotNumber);
            var modified     = file.GetModifiedTime(this.SaveLocation);
            var modifiedDate = DateTimeOffset.FromUnixTimeSeconds((long)modified).ToLocalTime().ToString("yyyy-MM-dd");
            this._lastPlayedLabel.Text = String.Format("Last Played: {0}", modifiedDate);
            this._clearButton.Disabled = false;
        }
        else
        {
            this._loadButton.Text      = String.Format("Save Slot {0} - (empty)", this.SlotNumber);
            this._lastPlayedLabel.Text = "Last Played: never";
            this._clearButton.Disabled = true;
        }
    }
Beispiel #2
0
    public void save_state_to_file(Godot.File file)
    {
        if (story == null)
        {
            PushNullStoryError();
            return;
        }

        if (file.IsOpen())
        {
            file.StoreString(get_state());
        }
    }
Beispiel #3
0
    public void load_state_from_file(Godot.File file)
    {
        if (story == null)
        {
            PushNullStoryError();
            return;
        }

        if (!file.IsOpen())
        {
            return;
        }

        file.Seek(0);
        if (file.GetLen() > 0)
        {
            story.state.LoadJson(file.GetAsText());
        }
    }
Beispiel #4
0
    private static void WriteDataToSaveFile(string target, string justInfo, string serialized, string tempScreenshot)
    {
        using (var file = new File())
        {
            file.Open(target, File.ModeFlags.Write);
            using (Stream gzoStream = new GZipOutputStream(new GodotFileStream(file)))
            {
                using (var tar = new TarOutputStream(gzoStream))
                {
                    OutputEntry(tar, SAVE_INFO_JSON, Encoding.UTF8.GetBytes(justInfo));

                    if (tempScreenshot != null)
                    {
                        byte[] data = null;

                        using (var reader = new File())
                        {
                            reader.Open(tempScreenshot, File.ModeFlags.Read);

                            if (!reader.IsOpen())
                            {
                                GD.PrintErr("Failed to open temp screenshot for writing to save");
                            }
                            else
                            {
                                data = reader.GetBuffer((int)reader.GetLen());
                            }
                        }

                        if (data != null && data.Length > 0)
                        {
                            OutputEntry(tar, SAVE_SCREENSHOT, data);
                        }
                    }

                    OutputEntry(tar, SAVE_SAVE_JSON, Encoding.UTF8.GetBytes(serialized));
                }
            }
        }
    }
Beispiel #5
0
    private static (string infoStr, string saveStr, byte[] screenshot) LoadDataFromFile(string file, bool info,
                                                                                        bool save, bool screenshot)
    {
        string infoStr = null;
        string saveStr = null;

        byte[] screenshotData = null;

        // Used for early stop in reading
        int itemsToRead = 0;

        if (info)
        {
            ++itemsToRead;
        }

        if (save)
        {
            ++itemsToRead;
        }

        if (screenshot)
        {
            ++itemsToRead;
        }

        if (itemsToRead < 1)
        {
            throw new ArgumentException("no things to load specified from save");
        }

        using (var reader = new File())
        {
            reader.Open(file, File.ModeFlags.Read);
            if (!reader.IsOpen())
            {
                throw new ArgumentException("couldn't open the file for reading");
            }

            using (var stream = new GodotFileStream(reader))
            {
                using (Stream gzoStream = new GZipInputStream(stream))
                {
                    using (var tar = new TarInputStream(gzoStream))
                    {
                        TarEntry tarEntry;
                        while ((tarEntry = tar.GetNextEntry()) != null)
                        {
                            if (tarEntry.IsDirectory)
                            {
                                continue;
                            }

                            if (tarEntry.Name == SAVE_INFO_JSON)
                            {
                                if (!info)
                                {
                                    continue;
                                }

                                infoStr = ReadStringEntry(tar, (int)tarEntry.Size);
                                --itemsToRead;
                            }
                            else if (tarEntry.Name == SAVE_SAVE_JSON)
                            {
                                if (!save)
                                {
                                    continue;
                                }

                                saveStr = ReadStringEntry(tar, (int)tarEntry.Size);
                                --itemsToRead;
                            }
                            else if (tarEntry.Name == SAVE_SCREENSHOT)
                            {
                                if (!screenshot)
                                {
                                    continue;
                                }

                                screenshotData = ReadBytesEntry(tar, (int)tarEntry.Size);
                                --itemsToRead;
                            }
                            else
                            {
                                GD.PrintErr("Unknown file in save: ", tarEntry.Name);
                            }

                            // Early quit if we already got as many things as we want
                            if (itemsToRead <= 0)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }

        return(infoStr, saveStr, screenshotData);
    }
Beispiel #6
0
        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)),
                    });
                }
            }
        }