diff --git a/Command.cs b/Command.cs index c74b4ad..720ee43 100644 --- a/Command.cs +++ b/Command.cs @@ -25,9 +25,11 @@ public override void Action(CommandCaller caller, string input, string[] args){ return; } switch(args[0]){ + case "help": Help(caller); + break; case "hand": HandInfo(caller); break; - case "help": Help(caller); + case "syntax": Syntax(caller); break; default: caller.Reply("Unknown subcommand, use /tt help for more information."); @@ -41,6 +43,8 @@ void Help(CommandCaller caller){ caller.Reply(" Display this information."); caller.Reply("/tt hand"); caller.Reply(" Get information about item that you hold."); + caller.Reply("/tt syntax"); + caller.Reply(" Check syntax for scripts without reload."); } void HandInfo(CommandCaller caller){ @@ -57,5 +61,22 @@ void HandInfo(CommandCaller caller){ } caller.Reply("Max Stack : " + item.maxStack); } + + void Syntax(CommandCaller caller){ + zzzTerraTweaker TT = (zzzTerraTweaker)Mod; + caller.Reply("Start syntax checking, script count : " + TT.ScriptFiles.Count.ToString()); + TT.SetupScripts(true); + caller.Reply("Done."); + caller.Reply("Successfuly compiled : " + TT.Compiled.Count.ToString()); + if (TT.Failed.Count == 0) caller.Reply("You should reload to apply script to game."); + else { + caller.Reply("Failed compiled : " + TT.Failed.Count.ToString()); + caller.Reply("Failed scripts :"); + foreach (string name in TT.Failed) { + caller.Reply(" " + name); + } + caller.Reply("Check log file for more information."); + } + } } } \ No newline at end of file diff --git a/build.txt b/build.txt index 3d6cc86..99d29aa 100644 --- a/build.txt +++ b/build.txt @@ -1,4 +1,4 @@ displayName = TerraTweaker author = KoKoNya -version = 1.3.5 +version = 1.3.6 homepage = https://github.com/Preta-Crowz/TerraTweaker diff --git a/description.txt b/description.txt index 148be48..424883b 100644 --- a/description.txt +++ b/description.txt @@ -1,4 +1,4 @@ -This version was built for 1.4(Alpha) +This version was built for 1.4 (Alpha) Tweak Terraria experience with Custom Script! only recipe add/remove is aviliable for now. diff --git a/zzzTerraTweaker.cs b/zzzTerraTweaker.cs index 2612a2b..eb62f7d 100644 --- a/zzzTerraTweaker.cs +++ b/zzzTerraTweaker.cs @@ -14,43 +14,54 @@ namespace zzzTerraTweaker{ class zzzTerraTweaker : Mod{ public zzzTerraTweaker(){} - private string DataPath, ScriptPath; - private List ScriptFiles = new List(); - private List Errors = new List(); + public List ScriptFiles { get; private set; } + public List Compiled { get; private set; } + public List Failed { get; private set; } private Dictionary HashDict = new Dictionary(); private Dictionary ServerHash; + public static readonly string ScriptPath = Path.Combine(Main.SavePath, "Scripts"); - private List recipes = new List(); - private List removes = new List(); + public List recipes { get; private set; } + public List removes { get; private set; } public override void Load(){ - this.ScriptPath = Path.Combine(Main.SavePath, "Scripts"); - this.Logger.Debug("Script Path : " + this.ScriptPath); - Directory.CreateDirectory(this.ScriptPath); - string[] allFiles = Directory.GetFiles(this.ScriptPath); + SetupScripts(false); + } + + public void SetupScripts(bool CheckOnly){ + ScriptFiles = new List(); + Compiled = new List(); + Failed = new List(); + recipes = new List(); + removes = new List(); + this.Logger.Debug("Script Path : " + ScriptPath); + Directory.CreateDirectory(ScriptPath); + string[] allFiles = Directory.GetFiles(ScriptPath); foreach(string file in allFiles){ if(Path.GetExtension(file) == ".moon"){ string fileName = Path.GetFileName(file); - this.ScriptFiles.Add(fileName); + ScriptFiles.Add(fileName); }} - this.Logger.Debug("Script List : " + string.Join(",", this.ScriptFiles)); - SetupScripts(); - } - - public void SetupScripts(){ - foreach(string name in this.ScriptFiles){ - Script script = new Script(Path.Combine(this.ScriptPath, name)); - script.Load(); - HashDict.Add(name, script.hash); - this.Logger.Info("Loaded " + name + ", MD5 : " + script.hexHash); - this.Logger.Info("Start Compile " + name); - script.Compile(); - this.Logger.Info("Compiled " + name); - int i = 0; - foreach(MLRecipe recipe in script.GetRecipes()) - recipes.Add((MLRecipe)recipe); - foreach(MLItem item in script.GetRemoves()) - removes.Add(item); + this.Logger.Debug("Script List : " + string.Join(",", ScriptFiles)); + foreach(string name in ScriptFiles){ + try { + Script script = new Script(Path.Combine(ScriptPath, name)); + script.Load(); + if (!CheckOnly) HashDict.Add(name, script.hash); + this.Logger.Info("Loaded " + name + ", MD5 : " + script.hexHash); + this.Logger.Info("Start Compile " + name); + script.Compile(); + this.Logger.Info("Compiled " + name); + Compiled.Add(name); + foreach(MLRecipe recipe in script.GetRecipes()) + recipes.Add((MLRecipe)recipe); + foreach(MLItem item in script.GetRemoves()) + removes.Add(item); + } catch (Exception e) { + this.Logger.Error("Failed to compile script : " + name); + this.Logger.Error(e); + Failed.Add(name); + } } }