/// <summary> /// Returns loader that can load the level into editing mode, where players are just placeholders. /// </summary> /// <param name="levelRep">Presentation of the level for the user.</param> /// <param name="storedLevel">Stored serialized state of the level.</param> /// <param name="parentProgress">Progress watcher for the parent process.</param> /// <param name="loadingSubsectionSize">Size of this loading process as a part of the parent process.</param> /// <returns>Loader that can load the level into editing mode.</returns> public static ILevelLoader GetLoaderForEditing(LevelRep levelRep, StLevel storedLevel, IProgressEventWatcher parentProgress = null, double loadingSubsectionSize = 100) { return(new SavedLevelEditorLoader(levelRep, storedLevel, parentProgress, loadingSubsectionSize)); }
public override XElement SaveAsPrototype() { if (RunningLevel == null) { throw new InvalidOperationException("Level was not loaded, so there is nothing to save"); } Stream saveFile = null; try { StLevel storedLevel = RunningLevel.Save(); saveFile = GamePack.App.Files.OpenDynamicFileInPackage(SavePath, FileMode.Create, FileAccess.Write, GamePack); storedLevel.WriteTo(saveFile); } catch (Exception e) { Urho.IO.Log.Write(LogLevel.Error, $"Level saving to {SavePath} failed with: {e.Message}"); throw; } finally { saveFile?.Dispose(); } return(ToXml()); }
/// <summary> /// Returns loader that can load the level into playing mode. /// </summary> /// <param name="levelRep">Presentation of the level for the user.</param> /// <param name="storedLevel">Stored serialized state of the level.</param> /// <param name="players">Data to initialize the players.</param> /// <param name="customSettings">Data to initialize the level logic instance plugin.</param> /// <param name="parentProgress">Progress watcher for the parent process.</param> /// <param name="loadingSubsectionSize">Size of this loading process as a part of the parent process.</param> /// <returns>Loader that can load the level into playing mode.</returns> public static ILevelLoader GetLoaderForPlaying(LevelRep levelRep, StLevel storedLevel, PlayerSpecification players, LevelLogicCustomSettings customSettings, IProgressEventWatcher parentProgress = null, double loadingSubsectionSize = 100) { return(new SavedLevelPlayingLoader(levelRep, storedLevel, players, customSettings, parentProgress, loadingSubsectionSize)); }
public override ILevelLoader GetLoaderForPlaying(PlayerSpecification players, LevelLogicCustomSettings customSettings, IProgressEventWatcher parentProgress = null, double subsectionSize = 100) { if (savedLevel == null) { savedLevel = GetSaveFromDynamicPath(savedLevelPath, GamePack.App.Files); } var loader = LevelManager.GetLoaderForPlaying(Context, savedLevel, players, customSettings, parentProgress, subsectionSize); loader.Finished += (notifier) => { savedLevel = null; Context.state = new Playing(Context, this, loader.Level); }; return(loader); }
/// <summary> /// Saves the level into an instance of <see cref="StLevel"/> for serialization. /// </summary> /// <returns>Level state stored in instance of <see cref="StLevel"/> for serialization.</returns> public StLevel Save() { StLevel level = new StLevel() { LevelName = LevelRep.Name, Map = this.Map.Save(), PackageName = PackageManager.ActivePackage.Name, Plugin = new StLevelPlugin() }; level.Plugin = new StLevelPlugin { TypeID = LevelRep.LevelLogicType.ID, Data = new PluginData() }; try { Plugin?.SaveState(new PluginDataWrapper(level.Plugin.Data, this)); } catch (Exception e) { //NOTE: Maybe add cap to prevent message flood string message = $"Saving level plugin data failed with Exception: {e.Message}"; Urho.IO.Log.Write(LogLevel.Error, message); throw new SavingException(message, e); } //Saving exception can be thrown during the enumerations level.Units.AddRange(from unit in units.Values select unit.Save()); level.Buildings.AddRange(from building in buildings.Values select building.Save()); level.Projectiles.AddRange(from projectile in projectiles.Values select projectile.Save()); level.Players = new StPlayers { HumanPlayerID = HumanPlayer.ID, NeutralPlayerID = NeutralPlayer.ID }; level.Players.Players.AddRange(from player in players.Values select player.Save()); return(level); }
/// <summary> /// Creates a loader that loads saved level into a playing mode. /// </summary> /// <param name="levelRep">Presentation part of the level.</param> /// <param name="storedLevel">Saved level.</param> /// <param name="players">Data for player initialization.</param> /// <param name="customSettings">Data for level logic initialization.</param> /// <param name="parentProgress">Progress watcher for the parent process.</param> /// <param name="loadingSubsectionSize">Size of this loading process as a part of the parent process.</param> public SavedLevelPlayingLoader(LevelRep levelRep, StLevel storedLevel, PlayerSpecification players, LevelLogicCustomSettings customSettings, IProgressEventWatcher parentProgress = null, double loadingSubsectionSize = 100) : base(levelRep, storedLevel, false, parentProgress, loadingSubsectionSize) { this.players = players; this.customSettings = customSettings; if ((players == PlayerSpecification.LoadFromSavedGame) != (customSettings == LevelLogicCustomSettings.LoadFromSavedGame)) { throw new ArgumentException("Argument mismatch, one argument is loaded from save and the other is not"); } }
public LoadedSaved(LevelRep context, string savedLevelPath, StLevel savedLevel) : base(context) { this.savedLevelPath = savedLevelPath; this.savedLevel = savedLevel; }
/// <summary> /// Creates a loader that loads the saved level for editing. /// </summary> /// <param name="levelRep">Presentation part of the level.</param> /// <param name="storedLevel">Saved level.</param> /// <param name="parentProgress">Progress watcher for the parent process.</param> /// <param name="loadingSubsectionSize">Size of this loading process as a part of the parent process.</param> public SavedLevelEditorLoader(LevelRep levelRep, StLevel storedLevel, IProgressEventWatcher parentProgress = null, double loadingSubsectionSize = 100) : base(levelRep, storedLevel, true, parentProgress, loadingSubsectionSize) { }
/// <summary> /// Creates a loader that loads the level saved in the <paramref name="storedLevel"/> to mode based on <paramref name="editorMode"/>. /// </summary> /// <param name="levelRep">Presentation part of the level.</param> /// <param name="storedLevel">Saved level.</param> /// <param name="editorMode">If the level should be loaded to editor mode or playing mode.</param> /// <param name="parentProgress">Progress watcher for the parent process.</param> /// <param name="loadingSubsectionSize">Size of this loading process as a part of the parent process.</param> protected SavedLevelLoader(LevelRep levelRep, StLevel storedLevel, bool editorMode, IProgressEventWatcher parentProgress, double loadingSubsectionSize) : base(levelRep, editorMode, parentProgress, loadingSubsectionSize) { this.StoredLevel = storedLevel; }