private void PrepareCommonFiles() { foreach (string dir in GetWorldPaths()) { string worldName = Path.GetFileName(dir); string commonPath = GetServerDataPath() + "/Worlds/" + worldName + "/Common/"; string mediaPath = commonPath + "Media/"; Directory.CreateDirectory(commonPath); // documentation File.Copy(GetDocuArchivePath(worldName), commonPath + "docs.zip", true); // images Directory.CreateDirectory(mediaPath); World world = SDKUtil.ReadJSONFileDirect <World>(dir + "/World.json"); if (!string.IsNullOrEmpty(world.coverImage)) { File.Copy(dir + "/Images/" + world.coverImage, mediaPath + world.coverImage, true); } if (world.chapters != null) { foreach (Chapter chapter in world.chapters) { if (!string.IsNullOrEmpty(chapter.coverImage)) { File.Copy(dir + "/Images/" + chapter.coverImage, mediaPath + chapter.coverImage, true); } } } } }
private World LoadWorld() { string[] paths = GetWorldPaths(); if (paths == null || paths.Length == 0) { EditorUtility.DisplayDialog("Error", "There are no worlds yet. Use the setup tool to create one.", "OK"); return(null); } if (paths.Length > 1) { EditorUtility.DisplayDialog("Error", "There is more than one world in the project. The constructor does not support multi-world projects yet.", "OK"); return(null); } string worldName = Path.GetFileName(paths[0]); string root = GetWorldsRoot() + "/" + worldName + "/"; World world = SDKUtil.ReadJSONFileDirect <World>(root + "World.json"); if (world == null) { EditorUtility.DisplayDialog("Error", $"World.json file for {worldName} seems corrupted and needs to be fixed first.", "OK"); return(null); } world.key = worldName; return(world); }
public static void CreateImageList() { string path = EditorUtility.OpenFolderPanel("Select Image Folder", "", ""); if (string.IsNullOrEmpty(path)) { return; } // read existing mod file if existent ModdingData md = new ModdingData(); string modFile = path + "/" + SDKUtil.MODFILE_NAME; if (File.Exists(modFile)) { md = SDKUtil.ReadJSONFileDirect <ModdingData>(modFile); } if (md.imageData == null) { md.imageData = new List <ImageData>(); } // gather images IEnumerable <string> files = DirectoryUtil.GetFiles(path, new[] { "*.png", "*.jpg" }); foreach (string file in files) { string fileName = Path.GetFileName(file); if (md.imageData.Any(id => id.imageLink == fileName)) { continue; } string name = Path.GetFileNameWithoutExtension(fileName); if (DateTime.TryParseExact(SDKUtil.MaxLength(name, 19), "yyyy-MM-dd HH.mm.ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTime)) { name = dateTime.ToLongDateString() + " " + dateTime.ToShortTimeString(); } md.imageData.Add(new ImageData(fileName, name)); } File.WriteAllText(modFile, SDKUtil.SerializeObject(md)); EditorUtility.DisplayDialog("Done", $"Found {md.imageData.Count} images. Check modding.json in target folder.", "OK"); }
private static bool UpdateWorldData(string worldName) { string root = GetWorldsRoot() + "/" + worldName + "/"; World world = SDKUtil.ReadJSONFileDirect <World>(root + "World.json"); if (world == null) { EditorUtility.DisplayDialog("Error", $"World.json file for {worldName} seems corrupted and needs to be fixed first.", "OK"); return(false); } string worldBasePath = Path.GetDirectoryName(AssetDatabase.GUIDToAssetPath(AssetDatabase.AssetPathToGUID(root + "World.json"))) + "/Pieces"; world.objectSpecs = new List <ObjectSpec>(); string[] assets = AssetDatabase.FindAssets("*", new[] { root + "Pieces" }); foreach (string asset in assets) { string assetPath = AssetDatabase.GUIDToAssetPath(asset); if (!assetPath.ToLower().EndsWith(".prefab")) { continue; } GameObject prefab = PrefabUtility.LoadPrefabContents(assetPath); if (prefab.TryGetComponent(out ExtendedAttributes ea)) { if (!ea.spec.IsDefault()) { string prefix = Path.GetDirectoryName(assetPath); if (prefix != null && prefix.Length > worldBasePath.Length) { prefix = prefix.Substring(worldBasePath.Length + 1) + "/"; prefix = prefix.Replace('\\', '/'); } else { prefix = ""; } string fileName = Path.GetFileNameWithoutExtension(assetPath); ea.spec.objectKey = prefix + fileName; world.objectSpecs.Add(ea.spec); } } if (prefab != null) { PrefabUtility.UnloadPrefabContents(prefab); } } // increase version if (string.IsNullOrEmpty(world.version)) { world.version = "0.0.1"; } else { if (Version.TryParse(world.version, out Version version)) { world.version = $"{version.Major}.{version.Minor}.{version.Build + 1}"; } else { world.version = "0.0.1"; Debug.LogError($"World.json of {worldName} contained an unreadable version. Resetting to {world.version}."); } } world.versionCode++; // write back world.NullifyEmpties(); File.WriteAllText(root + "World.json", SDKUtil.SerializeObject(world)); return(true); }
private void ManipulateWorld(string command) { World world = LoadWorld(); if (world == null) { return; } switch (command) { case "SetToCurrentVersion": PackageInfo pi = PackageInfo.FindForAssetPath("Packages/com.wetzold.travrsal.sdk/package.json"); if (pi != null) { world.minVersion = pi.version; EditorUtility.DisplayDialog("Success", $"Set minimum app version required to play the world to {pi.version}.", "OK"); } break; case "AddZone": if (string.IsNullOrEmpty(zoneName)) { return; } string root = GetWorldPaths()[0]; string path = $"{root}/Data/{zoneName}.tmx"; if (File.Exists(path)) { EditorUtility.DisplayDialog("Error", "A zone with that name already exists.", "OK"); return; } AssetDatabase.CopyAsset($"Packages/{SDKUtil.PACKAGE_NAME}/Editor/CopyTemplates/EmptyZone.copy", $"Assets/Worlds/{world.key}/Data/{zoneName}.tmx"); // two cases: either world explicitly lists files already or default is used with config.world mechanism if (world.worldData != null && world.worldData.Count > 0) { world.worldData.Add(new WorldDataReference(path, WorldDataReference.ImportType.TileMap)); } else { string mapFile = root + "/Data/Config.world"; TMWorld worldMap = SDKUtil.ReadJSONFileDirect <TMWorld>(mapFile); if (worldMap != null) { worldMap.maps = worldMap.maps.Append(new WorldMap(Path.GetFileName(path))); File.WriteAllText(mapFile, SDKUtil.SerializeObject(worldMap)); } else { EditorUtility.DisplayDialog("Error", $"Data/Config.world file for {world.key} does not exist. New zone was created but needs to be manually linked.", "OK"); } } zoneName = ""; AssetDatabase.Refresh(); break; case "AddVariable": if (string.IsNullOrEmpty(varName)) { return; } if (world.initialVariables == null) { world.initialVariables = new List <Variable>(); } world.initialVariables.Add(new Variable(varName)); varName = ""; break; case "AddSetting": if (string.IsNullOrEmpty(worldSetting)) { return; } if (world.settings == null) { world.settings = new List <WorldSetting>(); } world.settings.Add(new WorldSetting(worldSetting)); worldSetting = ""; break; case "AddCustomShader": if (string.IsNullOrEmpty(customShader)) { return; } if (world.customShaders == null) { world.customShaders = new List <string>(); } world.customShaders.Add(customShader); customShader = ""; break; } SaveWorld(world); }