diff --git a/src/Assets/PackManifest.cs b/src/Assets/PackManifest.cs index 013d587..0243644 100644 --- a/src/Assets/PackManifest.cs +++ b/src/Assets/PackManifest.cs @@ -2,8 +2,8 @@ internal static class PackManifest { - private const string Uuid = "2fef88eb-05b4-47eb-97a8-67d3d5e8f31c"; - private const string Data = $$""" + internal const string Uuid = "2fef88eb-05b4-47eb-97a8-67d3d5e8f31c"; + internal const string Data = $$""" { "format_version": 2, "header": { @@ -24,7 +24,7 @@ internal static class PackManifest "language": "javascript", "uuid": "8c78f4ed-aa7f-46e8-af4f-cb460e0a3de5", "version": [0, 1, 0], - "entry": "scripts/121eiqkr.yel.js" + "entry": "scripts/main.js" } ], "dependencies": [ diff --git a/src/Assets/Prepare.cs b/src/Assets/Prepare.cs index 8cd6a45..3869a82 100644 --- a/src/Assets/Prepare.cs +++ b/src/Assets/Prepare.cs @@ -1,4 +1,5 @@ -using Hosihikari.Minecraft.Extension.GlobalService; +using System.Text.Json.Nodes; +using Hosihikari.Minecraft.Extension.PackHelper; namespace Hosihikari.VanillaScript.Assets; @@ -6,7 +7,43 @@ internal static class Prepare { internal static void Init() { - var cd = Environment.CurrentDirectory; - //Global.FilePathManager.OnInit(path => { }); + var pack = Path.GetFullPath(Path.Combine("config", nameof(VanillaScript), "pack")); + var manifest = Path.Combine(pack, "manifest.json"); + var scripts = Path.Combine(pack, "scripts"); + if (!Directory.Exists(pack)) + Directory.CreateDirectory(pack); + if (!Directory.Exists(scripts)) + Directory.CreateDirectory(scripts); + //if (!File.Exists(manifest)) + File.WriteAllText(manifest, PackManifest.Data); + File.WriteAllText(Path.Combine(scripts, "main.js"), "'EntryPoint';"); + PackHelper.AddPack( + PackType.BehaviorPack, + pack, + new(Guid.Parse(PackManifest.Uuid), (0, 1, 0)) + ); + FixConfig(); + } + + private static void FixConfig() + { + var configFile = Path.GetFullPath(Path.Combine("config", "default", "permissions.json")); + if (File.Exists(configFile)) + { + var json = JsonNode.Parse(File.ReadAllText(configFile)); + if (json is not null) + { + json["permissions"] = new JsonArray + { + "@minecraft/server-gametest", + "@minecraft/server", + "@minecraft/server-ui", + "@minecraft/server-admin", + "@minecraft/server-editor", + "@minecraft/server-net" + }; + File.WriteAllText(configFile, json.ToString()); + } + } } }