package electrosphere.entity.scene;

import electrosphere.game.server.world.ServerWorldData;
import electrosphere.server.datacell.GriddedDataCellManager;
import electrosphere.server.fluid.generation.DefaultFluidGenerator;
import electrosphere.server.fluid.manager.ServerFluidManager;
import electrosphere.server.terrain.generation.OverworldChunkGenerator;
import electrosphere.server.terrain.manager.ServerTerrainManager;
import electrosphere.util.FileUtils;

/**
 * Generates scene files where appropriate (ie, if playing the procedurally generated level)
 */
public class SceneGenerator {
    
    /**
     * Creates a scene file for the procedurally generated gamemode
     * @param gridSize The size of the terrain grid of the scene
     * @return The scene file
     */
    public static SceneFile createProceduralSceneFile(String saveName){
        //base file stuff
        SceneFile file = SceneFile.createSceneFile();
        //realm descriptor stuff
        file.realmDescriptor.type = RealmDescriptor.REALM_DESCRIPTOR_PROCEDURAL;
        file.realmDescriptor.griddedRealmSize = GriddedDataCellManager.MAX_GRID_SIZE;
        file.createSaveInstance = true; //won't have a predefined scene to load, so must create one in the save
        file.loadAllCells = false; // do not load all cells on init

        //create terrain
        ServerWorldData serverWorldData = ServerWorldData.createGriddedRealmWorldData(2000);
        ServerTerrainManager serverTerrainManager = new ServerTerrainManager(serverWorldData, 0, new OverworldChunkGenerator());
        serverTerrainManager.generate();
        serverTerrainManager.save(saveName);
        //create world.json
        FileUtils.serializeObjectToSavePath(saveName, "./world.json", serverWorldData);
        //create mock fluid sim manager
        ServerFluidManager serverFluidManager = new ServerFluidManager(serverWorldData, serverTerrainManager, 0, new DefaultFluidGenerator());
        serverFluidManager.save(saveName);
        
        return file;
    }

}
