Example #1
0
        public static EditorFile FromJson(string json, PlayerEditorShape playeShape, CreateEditorShapeDelegate newShapeAction, CreateEditorTargetShapeDelegate newTargetAction,
                                          CreateEditorBlockerShapeDelegate newBlockerAction, int currentVersion)
        {
            var dict        = JsonConvert.DeserializeObject <Dictionary <SaveFileFields, string> >(json);
            var fileVersion = int.Parse(dict[SaveFileFields.EditorVersion]);
            //TODO: uncomment, when new version is released, and compatibility fix is needed
            //if (fileVersion < currentVersion)
            //{

            //}
            var result = new EditorFile(dict[SaveFileFields.LevelName], playeShape, fileVersion);

            result.PlayerEditorShape.SetSavedState(JsonConvert.DeserializeObject <ObjectSaveState>(dict[SaveFileFields.PlayerShape]));

            var freeShapesList = JsonConvert.DeserializeObject <List <ObjectSaveState> >(dict[SaveFileFields.FreeShapesList]);

            foreach (var freeSerialized in freeShapesList)
            {
                var newShape = newShapeAction((int)freeSerialized.StartingShapeType);
                newShape.SetSavedState(freeSerialized);
                result.FreeShapes.Add(newShape);
            }

            var targetSerializedList = JsonConvert.DeserializeObject <List <ObjectSaveState> >(dict[SaveFileFields.TargetShapes]);

            foreach (var targetSerialized in targetSerializedList)
            {
                var newShape = newTargetAction((int)targetSerialized.StartingShapeType);
                newShape.SetSavedState(targetSerialized);
                result.TargetShapes.Add(newShape);
            }
            var blockerSerializedList = JsonConvert.DeserializeObject <List <ObjectSaveState> >(dict[SaveFileFields.BlockerShapes]);

            foreach (var blockerSerialized in blockerSerializedList)
            {
                var newShape = newBlockerAction((int)blockerSerialized.StartingShapeType);
                newShape.SetSavedState(blockerSerialized);
                result.BlockerShapes.Add(newShape);
            }

            return(result);
        }
Example #2
0
        public void SaveTempLevelData(EditorFile file)
        {
            var fileName = _levelsSaveLocation + Path.DirectorySeparatorChar + _tempLevelFilename + _levelFileExt;

            File.WriteAllText(fileName, file.Serialize());
        }