void Update()
 {
     WorldName     = InputWorldName.text;
     GenRandomSeed = InputRandSeedBool.isOn;
     int.TryParse(InputSeed.text, out WorldSeed);
     int.TryParse(InputWorldSize.text, out WorldSize);
     if (WorldSize % 16 != 0)
     {
         WorldSize = closestNumber(WorldSize, 16);
     }
     ChunkSize       = 16;
     LandmassGenType = (LandmassGenMethod)InputLandmassGenType.value;
     BiomeGenType    = (BiomeGenMethod)InputBiomeGenType.value;
     int.TryParse(InputResourceFillPercent.text, out ResourceFillPercent);
     int.TryParse(InputCellSmoothCycles.text, out CellSmoothCycles);
     CellFillPercent = 55;
     CellThreshold   = 4;
     int.TryParse(InputLandmassPerlinScale.text, out LandmassPerlinScale);
     float.TryParse(InputLandmassPerlinAreaDivision.text, out LandmassPerlinAreaDivision);
     BiomeDistortionMethod = (global::BiomeDistortionMethod)InputBiomeDistortionMethod.value;
     int.TryParse(InputBiomePerlinScale.text, out BiomePerlinScale);
     float.TryParse(InputBiomePerlinAreaDivision.text, out BiomePerlinAreaDivision);
     BiomeDistortionCellThreshold = 4;
     int.TryParse(InputBiomeSmoothCycles.text, out BiomeSmoothCycles);
 }
Example #2
0
    //Reading generator data from uh, places.
    public void ReadGenConfig()
    {
        GameResourcesFolder = Application.persistentDataPath;
        GameModsFolder      = GameResourcesFolder + "/mods/";
        GameSavesFolder     = GameResourcesFolder + "/saves/";

        if (Directory.Exists(GameSavesFolder))
        {
            if (File.Exists(GameSavesFolder + "gen_config.json"))
            {
                string GenConfigJson = File.ReadAllText(GameSavesFolder + "gen_config.json");
                GenConfigClass = JsonUtility.FromJson <SaveGenConfig>(GenConfigJson);
                if (GenConfigClass.LoadExisting)
                {
                    WorldName    = GenConfigClass.WorldName;
                    LoadExisting = true;
                }
                else
                {
                    WorldName                    = GenConfigClass.WorldName;
                    LoadExisting                 = false;
                    GenRandomSeed                = GenConfigClass.GenRandomSeed;
                    WorldSeed                    = GenConfigClass.WorldSeed;
                    WorldSize                    = GenConfigClass.WorldSize;
                    ChunkSize                    = GenConfigClass.ChunkSize;
                    LandmassGenType              = GenConfigClass.LandmassGenType;
                    BiomeGenType                 = GenConfigClass.BiomeGenType;
                    ResourceFillPercent          = GenConfigClass.ResourceFillPercent;
                    CellSmoothCycles             = GenConfigClass.CellSmoothCycles;
                    CellFillPercent              = GenConfigClass.CellFillPercent;
                    CellThreshold                = GenConfigClass.CellThreshold;
                    LandmassPerlinScale          = GenConfigClass.LandmassPerlinScale;
                    LandmassPerlinAreaDivision   = GenConfigClass.LandmassPerlinAreaDivision;
                    DistortionMapMethod          = GenConfigClass.BiomeDistortionMethod;
                    BiomesPerlinScale            = GenConfigClass.BiomePerlinScale;
                    BiomesPerlinAreaDivision     = GenConfigClass.BiomePerlinAreaDivision;
                    BiomeDistortionCellThreshold = GenConfigClass.BiomeDistortionCellThreshold;
                    BiomeSmoothCycles            = GenConfigClass.BiomeSmoothCycles;
                }
                File.Delete(GameSavesFolder + "gen_config.json");
            }
            else
            {
                Debug.Log("Did not find gen config; Rolling with editor values.");
            }
        }
        else
        {
            Debug.Log("Did not find Game Saves Folder.");
        }
    }
Example #3
0
    public void LoadWorld()
    {
        if (File.Exists(WorldFolder + "info_" + WorldName + ".json"))
        {
            string InfoJsonLoad = File.ReadAllText(WorldFolder + "info_" + WorldName + ".json");
            WorldDataInfoSaveObject = JsonUtility.FromJson <SaveWorldDataInfo>(InfoJsonLoad);
            LandmassGenType         = WorldDataInfoSaveObject.LandmassGenMethod;
            BiomeGenType            = WorldDataInfoSaveObject.BiomeGenMethod;
            DistortionMapMethod     = WorldDataInfoSaveObject.BiomeDistortionMethod;
            Debug.Log("World Info Json Loaded Successfully! World Marked As Valid!");
        }
        else
        {
            Debug.LogError("Missing World Info Json File! World is Invalid!");
            Debug.Break();
        }

        if (File.Exists(WorldDataFolder + "gen_" + WorldName + ".json"))
        {
            string GenJsonLoad = File.ReadAllText(WorldDataFolder + "gen_" + WorldName + ".json");
            WorldDataGenSaveObject = JsonUtility.FromJson <SaveWorldDataGen>(GenJsonLoad);
            WorldSize         = WorldDataGenSaveObject.WorldSize;
            WorldSeed         = WorldDataGenSaveObject.WorldSeed;
            ChunkSize         = WorldDataGenSaveObject.ChunkSize;
            WorldResourceGrid = new BiomeResourceEntry[WorldSize, WorldSize];
            for (int x = 0; x < WorldSize; x++)
            {
                for (int y = 0; y < WorldSize; y++)
                {
                    WorldResourceGrid[x, y] = WorldDataGenSaveObject.WorldResourcesSerialised[x + (y * WorldSize)];
                }
            }
            HeatMapGrid = new float[WorldSize, WorldSize];
            for (int x = 0; x < WorldSize; x++)
            {
                for (int y = 0; y < WorldSize; y++)
                {
                    HeatMapGrid[x, y] = WorldDataGenSaveObject.WorldHeatMap[x + (y * WorldSize)];
                }
            }
            Debug.Log("World Gen Json Loaded Successfully!");
        }
        else
        {
            Debug.LogError("Missing World Gen Json File! World is Invalid!");
            Debug.Break();
        }

        if (File.Exists(WorldDataFolder + "run_" + WorldName + ".json"))
        {
            string RunJsonLoad = File.ReadAllText(WorldDataFolder + "run_" + WorldName + ".json");
            WorldDataRunSaveObject    = JsonUtility.FromJson <SaveWorldDataRun>(RunJsonLoad);
            Player.transform.position = new Vector3(WorldDataRunSaveObject.PlayerCoordX, WorldDataRunSaveObject.PlayerCoordY);

            Debug.Log("World Run Json Loaded Successfully!");
        }
        else
        {
            Debug.LogError("Missing World Run Json File! World is Invalid!");
            Debug.Break();
        }

        if (WorldSize % 16 == 0)
        {
            WorldOffset = WorldSize / 2;
        }
        else
        {
            //im just lazy now so, there you go:
            WorldSize   = 1024;
            WorldOffset = 512;
            //TODO: fill this in later with proper math
        }

        LandmassGrid   = new int[WorldSize, WorldSize];
        ChunkStateGrid = new int[WorldSize / ChunkSize, WorldSize / ChunkSize];
        WorldTileGrid  = new RuleTile[WorldSize, WorldSize];

        DisplayMap = new Texture2D(WorldSize, WorldSize);

        //Making sure that the biome list has correct ids:
        for (int b = 0; b < worldBiomes.Count; b++)
        {
            worldBiomes[b].biomeID = b;
        }

        if (File.Exists(WorldMapFolder + "map_landmass.png") && File.Exists(WorldMapFolder + "map_biomes.png") && File.Exists(WorldMapFolder + "map_minimap_bg.png"))
        {
            byte[] bytes_Landmass;
            byte[] bytes_Biomes;
            byte[] bytes_MinimapBG;
            bytes_Landmass  = File.ReadAllBytes(WorldMapFolder + "map_landmass.png");
            bytes_Biomes    = File.ReadAllBytes(WorldMapFolder + "map_biomes.png");
            bytes_MinimapBG = File.ReadAllBytes(WorldMapFolder + "map_minimap_bg.png");

            LandmassMap       = new Texture2D(2, 2);
            BiomesMap         = new Texture2D(2, 2);
            MinimapBackground = new Texture2D(2, 2);

            LandmassMap.LoadImage(bytes_Landmass);
            BiomesMap.LoadImage(bytes_Biomes);
            MinimapBackground.LoadImage(bytes_MinimapBG);

            LandmassMap.filterMode       = FilterMode.Point;
            BiomesMap.filterMode         = FilterMode.Point;
            MinimapBackground.filterMode = FilterMode.Point;

            for (int x = 0; x < WorldSize; x++)
            {
                for (int y = 0; y < WorldSize; y++)
                {
                    if (LandmassMap.GetPixel(x, y) == Color.black)
                    {
                        LandmassGrid[x, y] = 1;
                    }
                    else
                    {
                        LandmassGrid[x, y] = 0;
                    }
                }
            }

            UIMapDisplay.GetComponent <SpriteRenderer>().sprite = Sprite.Create(DisplayMap, new Rect(0.0f, 0.0f, WorldSize, WorldSize), new Vector2(0.5f, 0.5f), 100.0f);

            Debug.Log("World Run Json Loaded Successfully!");
        }
        else
        {
            Debug.LogError("Missing World Run Json File! World is Invalid!");
            Debug.Break();
        }


        MapChunksToWorld();

        IsWorldComplete = true;
    }