Ejemplo n.º 1
0
        // Reads all records in SaveTree
        // Reader must be positioned at start of first RecordElement
        void ReadRecords(BinaryReader reader)
        {
            RecordDictionary.Clear();
            RootRecord = new SaveTreeBaseRecord();
            while (reader.BaseStream.Position < reader.BaseStream.Length)
            {
                // Read record length and skip empty records as they have no data
                int length = reader.ReadInt32();
                if (length <= 0)
                {
                    continue;
                }

                // Handle potential stream overflow (e.g. corrupt save, something went wrong)
                if (reader.BaseStream.Position + length >= reader.BaseStream.Length)
                {
                    break;
                }

                // Peek record type from RecordRoot so we can instantiate record class based on type
                RecordTypes type = PeekRecordType(reader);

                // Add record based on type
                SaveTreeBaseRecord record;
                switch (type)
                {
                case RecordTypes.Item:
                    record = new ItemRecord(reader, length);
                    break;

                case RecordTypes.Character:
                    record = new CharacterRecord(reader, length);
                    break;

                case RecordTypes.Spell:
                    record = new SpellRecord(reader, length);
                    break;

                case RecordTypes.Container:
                    record = new ContainerRecord(reader, length);
                    break;

                //case RecordTypes.Door:
                //    record = new SaveTreeBaseRecord(reader, length);    // Read then skip these records for now
                //    continue;
                //case RecordTypes.DungeonData:
                //    record = new SaveTreeBaseRecord(reader, length);    // Read then skip these records for now
                //    continue;
                default:
                    record = new SaveTreeBaseRecord(reader, length);
                    break;
                }
                AddRecord(record);
            }

            LinkChildren();
        }
        void DisplaySaveCharacterGUI()
        {
            if (currentSaveTree == null)
                return;

            // Get character record
            List<SaveTreeBaseRecord> records = currentSaveTree.FindRecords(RecordTypes.Character);
            if (records.Count != 1)
                return;

            characterRecord = (CharacterRecord)records[0];
            //CharacterSheet characterSheet = characterRecord.ToCharacterSheet();

            EditorGUILayout.Space();
            GUILayoutHelper.Horizontal(() =>
            {
                EditorGUILayout.LabelField(new GUIContent("Name"), GUILayout.Width(EditorGUIUtility.labelWidth - 4));
                EditorGUILayout.SelectableLabel(characterRecord.ParsedData.characterName, EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight));
            });
            GUILayoutHelper.Horizontal(() =>
            {
                EditorGUILayout.LabelField(new GUIContent("Gender"), GUILayout.Width(EditorGUIUtility.labelWidth - 4));
                EditorGUILayout.SelectableLabel(((int)characterRecord.ParsedData.gender).ToString(), EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight));
            });
            GUILayoutHelper.Horizontal(() =>
            {
                string health = string.Format("{0} / {1}", characterRecord.ParsedData.currentHealth, characterRecord.ParsedData.startingHealth);
                EditorGUILayout.LabelField(new GUIContent("Health"), GUILayout.Width(EditorGUIUtility.labelWidth - 4));
                EditorGUILayout.SelectableLabel(health, EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight));
            });
        }
Ejemplo n.º 3
0
        // Reads all records in SaveTree
        // Reader must be positioned at start of first RecordElement
        void ReadRecords(BinaryReader reader)
        {
            RecordDictionary.Clear();
            RootRecord = new SaveTreeBaseRecord();
            while (reader.BaseStream.Position < reader.BaseStream.Length)
            {
                // Read record length and skip empty records as they have no data
                int length = reader.ReadInt32();
                if (length <= 0)
                    continue;

                // Handle potential stream overflow (e.g. corrupt save, something went wrong)
                if (reader.BaseStream.Position + length >= reader.BaseStream.Length)
                    break;

                // Peek record type from RecordRoot so we can instantiate record class based on type
                RecordTypes type = PeekRecordType(reader);

                // Add record based on type
                SaveTreeBaseRecord record;
                switch (type)
                {
                    case RecordTypes.Item:
                        record = new ItemRecord(reader, length);
                        break;
                    case RecordTypes.Spell:
                        record = new SpellRecord(reader, length);
                        break;
                    case RecordTypes.Character:
                        record = new CharacterRecord(reader, length);
                        break;
                    //case RecordTypes.UnknownTownLink:
                    //    record = new SaveTreeBaseRecord(reader, length);    // Read then skip these records for now
                    //    continue;
                    //case RecordTypes.DungeonData:
                    //    record = new SaveTreeBaseRecord(reader, length);    // Read then skip these records for now
                    //    continue;
                    default:
                        record = new SaveTreeBaseRecord(reader, length);
                        break;
                }
                AddRecord(record);
            }

            LinkChildren();
        }