public void GetWorldItems() { string[] WorldLocations = Directory.GetDirectories(GameSavesFolder); string[] WorldNames = Directory.GetDirectories(GameSavesFolder); for (int i = 0; i < WorldLocations.Length; i++) { WorldNames[i] = WorldLocations[i].Replace(GameSavesFolder, ""); } for (int i = 0; i < WorldNames.Length; i++) { if (File.Exists(WorldLocations + "/info" + WorldNames[i] + ".json")) { string WorldInfoJson = File.ReadAllText(WorldLocations + "/info" + WorldNames[i] + ".json"); WorldDataInfoSaveObject = JsonUtility.FromJson <SaveWorldDataInfo>(WorldInfoJson); WorldItems.Add(new MainMenuWorldItem(WorldNames[i], WorldDataInfoSaveObject.WorldVersion, WorldDataInfoSaveObject.CreationDate, WorldDataInfoSaveObject.LastOpenedDate)); } } foreach (var item in WorldItems) { GameObject WorldItem = Instantiate(WorldEntry, ScrollViewContentBox.transform); WorldItemObjects.Add(WorldItem); WorldItem.name = item.WorldName; TMP_Text WorldItemDispName = WorldItem.transform.Find("WorldName").GetComponent <TMP_Text>(); TMP_Text WorldItemDispWorldVersion = WorldItem.transform.Find("WorldVersion").GetComponent <TMP_Text>(); TMP_Text WorldItemDispCreationDate = WorldItem.transform.Find("DateOfCreation").GetComponent <TMP_Text>(); TMP_Text WorldItemDispLastOpenedDate = WorldItem.transform.Find("LastOpenedDate").GetComponent <TMP_Text>(); WorldItemDispName.text = item.WorldName; WorldItemDispWorldVersion.text = item.WorldVersion; WorldItemDispCreationDate.text = item.CreationDate; WorldItemDispLastOpenedDate.text = item.LastOpenedDate; } }
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; }