示例#1
0
 public ChunkSpawner(ChunkConfiguration chunkType, CompoundCloudSystem cloudSystem)
 {
     this.chunkType   = chunkType;
     this.cloudSystem = cloudSystem;
     chunkScene       = SpawnHelpers.LoadChunkScene();
 }
示例#2
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;
    }