Skip to content

Commit

Permalink
Syntax Check Command : /tt syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Preta-Crowz committed Apr 11, 2022
1 parent c6cb553 commit 629eb13
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 31 deletions.
23 changes: 22 additions & 1 deletion Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -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){
Expand All @@ -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.");
}
}
}
}
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
displayName = TerraTweaker
author = KoKoNya
version = 1.3.5
version = 1.3.6
homepage = https://github.com/Preta-Crowz/TerraTweaker
2 changes: 1 addition & 1 deletion description.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
67 changes: 39 additions & 28 deletions zzzTerraTweaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,54 @@ namespace zzzTerraTweaker{
class zzzTerraTweaker : Mod{
public zzzTerraTweaker(){}

private string DataPath, ScriptPath;
private List<string> ScriptFiles = new List<string>();
private List<string> Errors = new List<string>();
public List<string> ScriptFiles { get; private set; }
public List<string> Compiled { get; private set; }
public List<string> Failed { get; private set; }
private Dictionary<string,byte[]> HashDict = new Dictionary<string,byte[]>();
private Dictionary<string,byte[]> ServerHash;
public static readonly string ScriptPath = Path.Combine(Main.SavePath, "Scripts");

private List<MLRecipe> recipes = new List<MLRecipe>();
private List<MLItem> removes = new List<MLItem>();
public List<MLRecipe> recipes { get; private set; }
public List<MLItem> 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<string>();
Compiled = new List<string>();
Failed = new List<string>();
recipes = new List<MLRecipe>();
removes = new List<MLItem>();
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);
}
}
}

Expand Down

0 comments on commit 629eb13

Please sign in to comment.