Ejemplo n.º 1
0
    public void OnFinishLoading(MicrobeStage stage)
    {
        ApplyPropertiesFromSave(stage);

        RespawnEntitiesFromSave(stage);

        CreatePatchManagerIfNeeded();

        UpdatePatchSettings(true);

        StartMusic();
    }
Ejemplo n.º 2
0
    /// <summary>
    ///   Auto save the game (if enabled in settings)
    /// </summary>
    public static void AutoSave(MicrobeStage state)
    {
        if (!Settings.Instance.AutoSaveEnabled)
        {
            return;
        }

        InternalSaveHelper(SaveInformation.SaveType.AutoSave, MainGameState.MicrobeStage, save =>
        {
            save.SavedProperties = state.CurrentGame;
            save.MicrobeStage    = state;
        }, () => state);
    }
Ejemplo n.º 3
0
    private void ApplyPropertiesFromSave(MicrobeStage savedMicrobeStage)
    {
        SaveApplyHelper.CopyJSONSavedPropertiesAndFields(this, savedMicrobeStage, new List <string>()
        {
            "spawner",
            "Player",
            "Camera",
            "Clouds",
        });

        spawner.ApplyPropertiesFromSave(savedMicrobeStage.spawner);
        Clouds.ApplyPropertiesFromSave(savedMicrobeStage.Clouds);
        Camera.ApplyPropertiesFromSave(savedMicrobeStage.Camera);
    }
Ejemplo n.º 4
0
 public void Init(MicrobeStage stage)
 {
     this.stage = stage;
 }
Ejemplo n.º 5
0
 public override void _Ready()
 {
     stage = (MicrobeStage)GetParent();
 }
Ejemplo n.º 6
0
    public void Init(MicrobeStage stage)
    {
        this.stage = stage;

        OnEnterStageTransition();
    }
Ejemplo n.º 7
0
 public override void _Ready()
 {
     // Not the cleanest that the parent has to be MicrobeState type...
     stage = (MicrobeStage)GetParent();
 }
Ejemplo n.º 8
0
    private void RespawnEntitiesFromSave(MicrobeStage savedMicrobeStage)
    {
        if (savedMicrobeStage.Player != null && !savedMicrobeStage.Player.Dead)
        {
            SpawnPlayer();
            Player.ApplyPropertiesFromSave(savedMicrobeStage.Player);
        }

        if (savedGameEntities == null)
        {
            GD.PrintErr("Saved microbe stage contains no entities to load");
            return;
        }

        var microbeScene = SpawnHelpers.LoadMicrobeScene();
        var chunkScene   = SpawnHelpers.LoadChunkScene();
        var agentScene   = SpawnHelpers.LoadAgentScene();

        // This only should be used for things that get overridden anyway from the saved properties
        var random = new Random();

        foreach (var thing in savedGameEntities)
        {
            // Skip the player as it was already loaded
            if (thing == savedMicrobeStage.Player)
            {
                continue;
            }

            switch (thing)
            {
            case Microbe casted:
            {
                var spawned = SpawnHelpers.SpawnMicrobe(casted.Species, Vector3.Zero, rootOfDynamicallySpawned,
                                                        microbeScene, !casted.IsPlayerMicrobe, Clouds, CurrentGame);
                spawned.ApplyPropertiesFromSave(casted);
                break;
            }

            case FloatingChunk casted:
            {
                var spawned = SpawnHelpers.SpawnChunk(casted.CreateChunkConfigurationFromThis(),
                                                      casted.Translation, rootOfDynamicallySpawned, chunkScene, Clouds, random);
                spawned.ApplyPropertiesFromSave(casted);
                break;
            }

            case AgentProjectile casted:
            {
                var spawned = SpawnHelpers.SpawnAgent(casted.Properties, casted.Amount, casted.TimeToLiveRemaining,
                                                      casted.Translation, Vector3.Forward, rootOfDynamicallySpawned, agentScene, null);
                spawned.ApplyPropertiesFromSave(casted);

                // TODO: mapping from old microbe to recreated microbe to set emitter here
                break;
            }

            default:
                GD.PrintErr("Unknown entity type to load from save: ", thing.GetType());
                break;
            }
        }

        // Clear this to make saving again work
        savedGameEntities = null;
    }