Skip to content

Commit

Permalink
working ver, has item stacking
Browse files Browse the repository at this point in the history
  • Loading branch information
neomoth committed Oct 21, 2024
1 parent 93f0a11 commit c45b41a
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 42 deletions.
1 change: 1 addition & 0 deletions NeoQOLPack/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Token> GetMod()
Expand Down
52 changes: 23 additions & 29 deletions NeoQOLPack/Mods/InventoryStackerInventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Token> Modify(string path, IEnumerable<Token> 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);

Expand All @@ -47,37 +43,35 @@ public IEnumerable<Token> Modify(string path, IEnumerable<Token> 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);
Expand Down
12 changes: 6 additions & 6 deletions NeoQOLPack/Mods/InventoryStackerItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Token> Modify(string path, IEnumerable<Token> tokens)
Expand All @@ -29,7 +27,7 @@ public IEnumerable<Token> Modify(string path, IEnumerable<Token> 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);
Expand All @@ -41,7 +39,8 @@ public IEnumerable<Token> Modify(string path, IEnumerable<Token> 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);
Expand All @@ -52,11 +51,12 @@ public IEnumerable<Token> Modify(string path, IEnumerable<Token> 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);
Expand Down
16 changes: 9 additions & 7 deletions NeoQOLPack/Mods/InventoryStackerPlayerData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Token> Modify(string path, IEnumerable<Token> tokens)
Expand Down Expand Up @@ -36,7 +34,8 @@ public IEnumerable<Token> Modify(string path, IEnumerable<Token> 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);
Expand All @@ -50,7 +49,8 @@ public IEnumerable<Token> Modify(string path, IEnumerable<Token> 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);
Expand All @@ -64,15 +64,17 @@ public IEnumerable<Token> Modify(string path, IEnumerable<Token> 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);
Expand Down
42 changes: 42 additions & 0 deletions NeoQOLPack/Mods/InventoryStackerSelect.cs
Original file line number Diff line number Diff line change
@@ -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<Token> Modify(string path, IEnumerable<Token> 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;
}
}
}
10 changes: 10 additions & 0 deletions mods/NeoQOLPack/Scenes/HUD/StackSize.tscn
Original file line number Diff line number Diff line change
@@ -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
67 changes: 67 additions & 0 deletions mods/NeoQOLPack/main.gd
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c45b41a

Please sign in to comment.