public static List <ITerrainDef> BuildArray(string modName, string path) { var rslt = new List <ITerrainDef>(); var scriptDirPath = path + scriptPath; LOG.INFO("Check Terrains path:" + scriptDirPath); foreach (TerrainType type in Enum.GetValues(typeof(TerrainType))) { var scriptFilePath = scriptDirPath + type.ToString().ToLower() + ".json"; LOG.INFO("Load Terrains script:" + scriptFilePath); var pngDirPath = path + imagePath + type.ToString(); var pngFilePaths = SystemIO.FileSystem.Directory.EnumerateFiles(pngDirPath, "*.png"); if (pngFilePaths.Count() == 0) { throw new Exception(); } foreach (var pngFilePath in pngFilePaths) { LOG.INFO("Load Terrains png:" + pngFilePath); rslt.Add(Build(modName, type, scriptFilePath, pngFilePath)); } } LOG.INFO("Builded Terrains count:" + rslt.Count); return(rslt); }
public static MapData build(MapBuildType mapType, int maxDist, Dictionary <TerrainType, Dictionary <string, ITerrainDef> > terrainDefs) { var terrainDict = new Dictionary <TerrainType, ITerrainDef>(); var map = new MapData(maxDist); BuildPlain(ref map, terrainDefs[TerrainType.PLAIN].Values); BuildRiver(ref map); var Type2Percent = calcPercent(mapType); BuildMount(ref map, Type2Percent[TerrainType.MOUNT], terrainDefs[TerrainType.MOUNT].Values); BuildHill(ref map, Type2Percent[TerrainType.HILL], terrainDefs[TerrainType.HILL].Values); BuildLake(ref map, Type2Percent[TerrainType.LAKE], terrainDefs[TerrainType.LAKE].Values); BuildMarsh(ref map, terrainDefs[TerrainType.MARSH].Values); ////BuildForest(ref map, 0.1); //BuildRiver(ref map); LOG.INFO("build" + map.ToString()); return(map); }
public IMod Build(string path) { LOG.INFO("Build MOD : " + path); var mod = new Mod(); mod.path = path; mod.terrainDefs = TerrainDef.Builder.BuildArray(mod.name, path); return(mod); }
private static ITerrainDef Build(string modName, TerrainType type, string scriptFilePath, string pngFilePath) { TerrainDef rslt = new TerrainDef(); rslt.modName = modName; rslt.type = type; var json = JObject.Parse(SystemIO.FileSystem.File.ReadAllText(scriptFilePath)); //rslt.occur = new Occur(); rslt.code = SystemIO.FileSystem.Path.GetFileNameWithoutExtension(pngFilePath); rslt.path = pngFilePath; rslt.detectDifficulty = (int)json["detect_difficulty"]; LOG.INFO($"Build TerrainDef, type:{rslt.type} code:{rslt.code} path:{rslt.path}"); //foreach (var elem in json["occur"] as JObject) //{ // rslt.occur.nearBuff.Add($"{modName}_{elem.Key}".ToUpper(), elem.Value.ToObject<double>()); //} return(rslt); }