Skip to content

Commit

Permalink
Modified Interface, Recipe remove & add will work at one time now.
Browse files Browse the repository at this point in the history
  • Loading branch information
Preta-Crowz committed Apr 22, 2022
1 parent 629eb13 commit f53b816
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 33 deletions.
17 changes: 5 additions & 12 deletions Moonlight/Script.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public string hexHash {
private bool loaded = false;
private bool compiled = false;

private List<MLRecipe> recipes = new List<MLRecipe>();
private List<MLItem> removes = new List<MLItem>();
private List<IWorkable> works = new List<IWorkable>();
private List<string> errors = new List<string>();

public IVariable vv;
Expand Down Expand Up @@ -52,9 +51,8 @@ public void Compile(){
IVariable Value = Split.Parse(expr, ref index, ';');
tt.Value.Logger.Debug("Parsed Expr to : "+Value.ToString());
string vt = Value.GetType();
if(vt == "Condition" && !Value.GetValue()) return;
if(vt == "Recipe") recipes.Add((MLRecipe)Value);
else if(vt == "Remove") removes.Add((MLItem)Value.GetValue());
if(Value is MLCondition && !Value.GetValue()) return;
if(Value is IWorkable) works.Add((IWorkable)Value);
}
}

Expand All @@ -66,14 +64,9 @@ public bool IsCompiled(){
return compiled;
}

public List<MLRecipe> GetRecipes(){
public List<IWorkable> GetWorks(){
if(!this.IsCompiled()) this.Compile();
return this.recipes;
}

public List<MLItem> GetRemoves(){
if(!this.IsCompiled()) this.Compile();
return this.removes;
return this.works;
}
}
}
2 changes: 1 addition & 1 deletion Moonlight/Variable/IIngredient.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace Moonlight.Variable{
interface IIngredient : IVariable{}
interface IIngredient{}
}
3 changes: 3 additions & 0 deletions Moonlight/Variable/IWorkable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Moonlight.Variable{
interface IWorkable{}
}
2 changes: 1 addition & 1 deletion Moonlight/Variable/MLItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Terraria.ID;

namespace Moonlight.Variable{
class MLItem : IIngredient{
class MLItem : IVariable, IIngredient{
ModItem Value;
public int Code;
public int Count = 1;
Expand Down
2 changes: 1 addition & 1 deletion Moonlight/Variable/MLRecipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Terraria.ModLoader;

namespace Moonlight.Variable{
class MLRecipe : IVariable{
class MLRecipe : IVariable, IWorkable{
MLItem Value;
public bool isEnded = false;

Expand Down
2 changes: 1 addition & 1 deletion Moonlight/Variable/MLRemove.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Terraria.ModLoader;

namespace Moonlight.Variable{
class MLRemove : IIngredient{
class MLRemove : IVariable, IWorkable{
MLItem Value;
public string Name;
public bool isEnded = false;
Expand Down
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.6
version = 1.3.7
homepage = https://github.com/Preta-Crowz/TerraTweaker
29 changes: 13 additions & 16 deletions zzzTerraTweaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public zzzTerraTweaker(){}
private Dictionary<string,byte[]> ServerHash;
public static readonly string ScriptPath = Path.Combine(Main.SavePath, "Scripts");

public List<MLRecipe> recipes { get; private set; }
public List<MLItem> removes { get; private set; }
public List<IWorkable> Works { get; private set; }

public override void Load(){
SetupScripts(false);
Expand All @@ -32,8 +31,7 @@ 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>();
Works = new List<IWorkable>();
this.Logger.Debug("Script Path : " + ScriptPath);
Directory.CreateDirectory(ScriptPath);
string[] allFiles = Directory.GetFiles(ScriptPath);
Expand All @@ -53,10 +51,8 @@ public void SetupScripts(bool CheckOnly){
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);
foreach(MLRecipe recipe in script.GetWorks())
Works.Add(recipe);
} catch (Exception e) {
this.Logger.Error("Failed to compile script : " + name);
this.Logger.Error(e);
Expand All @@ -66,9 +62,11 @@ public void SetupScripts(bool CheckOnly){
}

public override void PostAddRecipes(){
RemoveRecipe(removes);
foreach(MLRecipe recipe in recipes)
RegisterRecipe(recipe);
foreach(IWorkable work in Works) {
if (work is MLRemove) RemoveRecipe((MLRemove)work);
else if (work is MLRecipe) RegisterRecipe((MLRecipe)work);
throw new Exception("Failed to parse work!");
}
}

public void RegisterRecipe(MLRecipe data){
Expand All @@ -94,12 +92,11 @@ public void RegisterRecipe(MLRecipe data){
this.Logger.Debug("Registered");
}

public void RemoveRecipe(List<MLItem> data){
public void RemoveRecipe(MLRemove data){
List<int> targets = new List<int>();
foreach(MLItem item in data){
if(item.isVanilla) targets.Add(item.GetValue());
else targets.Add(item.GetValue().type);
}
MLItem item = data.GetValue();
if(item.isVanilla) targets.Add(item.GetValue());
else targets.Add(item.GetValue().type);
for (int i = 0; i < Recipe.numRecipes; i++) {
Recipe R = Main.recipe[i];
if(targets.Exists(id => id == R.createItem.type))
Expand Down

0 comments on commit f53b816

Please sign in to comment.