diff --git a/NeoQOLPack/Mod.cs b/NeoQOLPack/Mod.cs index 6687e7f..cd05e2f 100644 --- a/NeoQOLPack/Mod.cs +++ b/NeoQOLPack/Mod.cs @@ -17,6 +17,7 @@ public Mod(IModInterface modInterface) { modInterface.RegisterScriptMod(new InventoryStackerItem(this)); modInterface.RegisterScriptMod(new InventoryStackerPlayerData(this)); modInterface.RegisterScriptMod(new InventoryStackerInventory(this)); + modInterface.RegisterScriptMod(new InventoryStackerSelect(this)); } public IEnumerable GetMod() diff --git a/NeoQOLPack/Mods/InventoryStackerInventory.cs b/NeoQOLPack/Mods/InventoryStackerInventory.cs index 76ad39f..3de5f91 100644 --- a/NeoQOLPack/Mods/InventoryStackerInventory.cs +++ b/NeoQOLPack/Mods/InventoryStackerInventory.cs @@ -6,21 +6,17 @@ namespace NeoQOLPack.Mods; public class InventoryStackerInventory(Mod mod) : IScriptMod { - private Mod mod = mod; - public bool ShouldRun(string path) => path == "res://Scenes/HUD/inventory.gdc"; public IEnumerable Modify(string path, IEnumerable tokens) { mod.Logger.Information("hi im loaded probably"); - MultiTokenWaiter addWaiter = new ([ - t => t is IdentifierToken {Name: "box"}, - t => t is IdentifierToken {Name: "add_child"}, - t => t.Type == TokenType.Newline - ], allowPartialMatch: true); + MultiTokenWaiter refreshWaiter = new([ t => t is IdentifierToken {Name: "_refresh"}, + t => t is IdentifierToken {Name: "refs"}, + t => t.Type == TokenType.CurlyBracketClose, t => t.Type is TokenType.Newline ], allowPartialMatch: true); @@ -47,37 +43,35 @@ public IEnumerable Modify(string path, IEnumerable tokens) foreach (Token token in tokens) { - mod.Logger.Information("wawa"); - mod.Logger.Information(token.ToString()); - mod.Logger.Information(refreshWaiter.Check(token).ToString()); + // mod.Logger.Information("wawa"); + // mod.Logger.Information(token.ToString()); + // mod.Logger.Information(refreshWaiter.Check(token).ToString()); if (refreshWaiter.Check(token)) { yield return token; - mod.Logger.Information("#################### FOUND REFRESH FUNC ######################"); + var t1 = new Token(TokenType.Period); + var t2 = new IdentifierToken("_stack_items"); + var t3 = new Token(TokenType.ParenthesisOpen); + var t4 = new Token(TokenType.ParenthesisClose); + var t5 = new Token(TokenType.Newline, 1); - foreach (var t in mod.GetMod()) yield return t; - yield return new Token(TokenType.Period); - yield return new IdentifierToken("_stack_items()"); - yield return new Token(TokenType.ParenthesisOpen); - yield return new Token(TokenType.ParenthesisClose); - yield return new Token(TokenType.Newline, 1); - } - else if (addWaiter.Check(token)) - { - mod.Logger.Information("#################### FOUND ADD FUNC ######################"); - yield return token; + mod.Logger.Information($"tokens: {t1}{t2}{t3}{t4}{t5} at {token}"); - yield return new IdentifierToken("i"); - yield return new Token(TokenType.Period); - yield return new IdentifierToken("display_stacked"); - yield return new Token(type: TokenType.OpAssign); - yield return new ConstantToken(new BoolVariant(true)); - yield return new Token(TokenType.Newline, 1); + mod.Logger.Information("#################### FOUND REFRESH FUNC ######################"); // C + mod.Logger.Information("WAWAWAWAWAWAWWA"); + yield return new Token(TokenType.Dollar); + yield return new ConstantToken(new StringVariant("/root/NeoQOLPack")); + yield return t1; + yield return t2; + yield return t3; + yield return t4; + yield return t5; } + else if (skipperWaiter.Check(token)) { - mod.Logger.Information("#################### FOUND SKIP FUNC ######################"); + mod.Logger.Information("#################### FOUND SKIP FUNC ######################"); // C yield return token; yield return new Token(TokenType.CfIf); diff --git a/NeoQOLPack/Mods/InventoryStackerItem.cs b/NeoQOLPack/Mods/InventoryStackerItem.cs index 6af1b75..74db87c 100644 --- a/NeoQOLPack/Mods/InventoryStackerItem.cs +++ b/NeoQOLPack/Mods/InventoryStackerItem.cs @@ -6,8 +6,6 @@ namespace NeoQOLPack.Mods; public class InventoryStackerItem(Mod mod) : IScriptMod { - private Mod mod = mod; - public bool ShouldRun(string path) => path == "res://Scenes/HUD/inventory_item.gdc"; public IEnumerable Modify(string path, IEnumerable tokens) @@ -29,7 +27,7 @@ public IEnumerable Modify(string path, IEnumerable tokens) { if (varWaiter.Check(token)) { - mod.Logger.Information("#################### FOUND VAR SPOT ######################"); + mod.Logger.Information("#################### FOUND VAR SPOT ######################"); // C yield return token; yield return new Token(TokenType.PrVar); @@ -41,7 +39,8 @@ public IEnumerable Modify(string path, IEnumerable tokens) yield return new Token(TokenType.PrVar); yield return new IdentifierToken("stack_size"); yield return new Token(TokenType.OpAssign); - foreach (var t in mod.GetMod()) yield return t; + yield return new Token(TokenType.Dollar); + yield return new ConstantToken(new StringVariant("/root/NeoQOLPack")); yield return new Token(TokenType.Period); yield return new IdentifierToken("_attach_stack_size"); yield return new Token(TokenType.ParenthesisOpen); @@ -52,11 +51,12 @@ public IEnumerable Modify(string path, IEnumerable tokens) } else if (updateWaiter.Check(token)) { - mod.Logger.Information("#################### FOUND UPDATE FUNC ######################"); + mod.Logger.Information("#################### FOUND UPDATE FUNC ######################"); // C yield return token; yield return new Token(TokenType.Newline, 1); - foreach (var t in mod.GetMod()) yield return t; + yield return new Token(TokenType.Dollar); + yield return new ConstantToken(new StringVariant("/root/NeoQOLPack")); yield return new Token(TokenType.Period); yield return new IdentifierToken("_apply_stack_visual"); yield return new Token(TokenType.ParenthesisOpen); diff --git a/NeoQOLPack/Mods/InventoryStackerPlayerData.cs b/NeoQOLPack/Mods/InventoryStackerPlayerData.cs index 827d17e..2de1091 100644 --- a/NeoQOLPack/Mods/InventoryStackerPlayerData.cs +++ b/NeoQOLPack/Mods/InventoryStackerPlayerData.cs @@ -6,8 +6,6 @@ namespace NeoQOLPack.Mods; public class InventoryStackerPlayerData(Mod mod) : IScriptMod { - private Mod mod = mod; - public bool ShouldRun(string path) => path == "res://Scenes/Singletons/playerdata.gdc"; public IEnumerable Modify(string path, IEnumerable tokens) @@ -36,7 +34,8 @@ public IEnumerable Modify(string path, IEnumerable tokens) yield return token; yield return new Token(TokenType.Newline, 1); - foreach (var t in mod.GetMod()) yield return t; + yield return new Token(TokenType.Dollar); + yield return new ConstantToken(new StringVariant("/root/NeoQOLPack")); yield return new Token(TokenType.Period); yield return new IdentifierToken("_append_entry"); yield return new Token(TokenType.ParenthesisOpen); @@ -50,7 +49,8 @@ public IEnumerable Modify(string path, IEnumerable tokens) yield return token; yield return new Token(TokenType.Newline, 1); - foreach (var t in mod.GetMod()) yield return t; + yield return new Token(TokenType.Dollar); + yield return new ConstantToken(new StringVariant("/root/NeoQOLPack")); yield return new Token(TokenType.Period); yield return new IdentifierToken("_append_entry"); yield return new Token(TokenType.ParenthesisOpen); @@ -64,15 +64,17 @@ public IEnumerable Modify(string path, IEnumerable tokens) yield return token; yield return new Token(TokenType.Newline, 1); - foreach (var t in mod.GetMod()) yield return t; + yield return new Token(TokenType.Dollar); + yield return new ConstantToken(new StringVariant("/root/NeoQOLPack")); yield return new Token(TokenType.Period); yield return new IdentifierToken("_initialize_keys"); yield return new Token(TokenType.ParenthesisOpen); yield return new Token(TokenType.ParenthesisClose); yield return new Token(TokenType.Newline, 1); - foreach (var t in mod.GetMod()) yield return t; + yield return new Token(TokenType.Dollar); + yield return new ConstantToken(new StringVariant("/root/NeoQOLPack")); yield return new Token(TokenType.Period); - yield return new IdentifierToken("_stack_items()"); + yield return new IdentifierToken("_stack_items"); yield return new Token(TokenType.ParenthesisOpen); yield return new Token(TokenType.ParenthesisClose); yield return new Token(TokenType.Newline, 1); diff --git a/NeoQOLPack/Mods/InventoryStackerSelect.cs b/NeoQOLPack/Mods/InventoryStackerSelect.cs new file mode 100644 index 0000000..9d8bb3d --- /dev/null +++ b/NeoQOLPack/Mods/InventoryStackerSelect.cs @@ -0,0 +1,42 @@ +using GDWeave.Godot; +using GDWeave.Godot.Variants; +using GDWeave.Modding; + +namespace NeoQOLPack.Mods; + +public class InventoryStackerSelect(Mod mod) : IScriptMod +{ + public bool ShouldRun(string path) => path == "res://Scenes/HUD/ItemSelect/item_select.gdc"; + + public IEnumerable Modify(string path, IEnumerable tokens) + { + MultiTokenWaiter addWaiter = new ([ + t => t is IdentifierToken {Name: "_ready"}, + t => t.Type == TokenType.PrVar, + t => t is IdentifierToken {Name: "i"}, + t => t.Type == TokenType.Newline + ], allowPartialMatch: true); + + foreach (Token token in tokens) + { + if (addWaiter.Check(token)) + { + for (var i = 0; i < 20; i++) + { + mod.Logger.Information("PENIS"); + } + + mod.Logger.Information("#################### FOUND ADD FUNC ######################"); + yield return token; + + yield return new IdentifierToken("i"); + yield return new Token(TokenType.Period); + yield return new IdentifierToken("display_stacked"); + yield return new Token(type: TokenType.OpAssign); + yield return new ConstantToken(new BoolVariant(true)); + yield return new Token(TokenType.Newline, 2); + } + else yield return token; + } + } +} \ No newline at end of file diff --git a/mods/NeoQOLPack/Scenes/HUD/StackSize.tscn b/mods/NeoQOLPack/Scenes/HUD/StackSize.tscn new file mode 100644 index 0000000..ffa727a --- /dev/null +++ b/mods/NeoQOLPack/Scenes/HUD/StackSize.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Assets/Themes/main.tres" type="Theme" id=1] + +[node name="StackSize" type="Label"] +grow_horizontal = 0 +theme = ExtResource( 1 ) +custom_colors/font_color = Color( 0, 0, 0, 1 ) +text = "x0" +align = 2 diff --git a/mods/NeoQOLPack/main.gd b/mods/NeoQOLPack/main.gd new file mode 100644 index 0000000..f8cd07b --- /dev/null +++ b/mods/NeoQOLPack/main.gd @@ -0,0 +1,67 @@ +class_name NeoQOL +extends Node + +static func _apply_stack_visual(display_stacked,idata,stack_size): + #print("######################## APPLYING VISUAL ######################## ") + if not display_stacked: + if idata["stack_size"]>0: + stack_size.visible = true + stack_size.text = "x"+str(idata["stack_size"]+1) + else: + stack_size.visible = false + else: stack_size.visible = false + +static func _attach_stack_size(parent): + #print("######################## ATTACHING LABEL ########################") + var stack_size_label: Label = preload("res://mods/NeoQOLPack/Scenes/HUD/StackSize.tscn").instance() + parent.add_child(stack_size_label) + stack_size_label.rect_position = Vector2(41.74,51) + stack_size_label.rect_size = Vector2(41.26,34) + stack_size_label.margin_left = 43 + stack_size_label.margin_top = 51 + stack_size_label.margin_right = -7 + stack_size_label.margin_bottom = -5 + stack_size_label.anchor_left = -0.18 + stack_size_label.anchor_top = 0 + stack_size_label.anchor_right = 1 + stack_size_label.anchor_bottom = 1 + #print(parent) + return stack_size_label + +static func _append_entry(entry): + print("######################## APPENDING ENTRY ########################") + #"locked": locked, "stack_size": 0, "stacked": false + entry["locked"] = false + entry["stack_size"] = 0 + entry["stacked"] = false + +static func _initialize_keys(): + print("######################## INITIALIZING KEYS ########################") + for item in PlayerData.inventory: + if !item.has("locked"): item["locked"] = false + if !item.has("stack_size"): item["stack_size"] = 0 # note: stack size is zero indexed, 0 = 1, 1 = 2, etc + if !item.has("stacked"): item["stacked"] = false # tracks if item is considered stacked with another item + +static func _stack_items(): + print("######################## STACKING ITEMS ########################") + var tools_to_stack = [] + var items_marked_for_stack = [] + + # Required to ensure everyone's save is updated with the new dictionary keys + for item in PlayerData.inventory: + var file = Globals.item_data[item["id"]]["file"] + if file.category == "tool": + var found_item = false + for t_item in tools_to_stack: + if item["id"] == t_item["id"]: + found_item = true + t_item["stack_size"] += 1 + items_marked_for_stack.append(item) + break + if not found_item: + item["stack_size"] = 0 + item["stacked"] = false + tools_to_stack.append(item) + + for item in items_marked_for_stack: + item["stacked"] = true