Skip to content

Commit f597af3

Browse files
Overhaul shape as layout
1 parent e6dbb5b commit f597af3

7 files changed

Lines changed: 124 additions & 173 deletions

File tree

src/main/java/io/github/apickledwalrus/skriptgui/SkriptGUI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ public void load(SkriptAddon addon) {
9393
ExprGUIValues::register,
9494
ExprGUIWithId::register,
9595
ExprLastGUI::register,
96+
ExprLayout::register,
9697
ExprLockStatus::register,
9798
ExprNextSlot::register,
9899
ExprPaginatedList::register,
99-
ExprShape::register,
100100
ExprVirtualInventory::register,
101101
SecCreateGUI::register,
102102
SecMakeSlot::register,

src/main/java/io/github/apickledwalrus/skriptgui/elements/expressions/ExprShape.java renamed to src/main/java/io/github/apickledwalrus/skriptgui/elements/expressions/ExprLayout.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,47 @@
1212
import org.jspecify.annotations.Nullable;
1313
import org.skriptlang.skript.registration.SyntaxRegistry;
1414

15-
@Name("GUI Shape")
16-
@Description("The shape of a GUI, which controls how its items are laid out.")
15+
@Name("GUI Layout")
16+
@Description("The layout of a GUI, which controls how its items are displayed.")
1717
@Example("""
18-
set the shape of the player's gui to "xxxxxxxxx", "x-------x", and "xxxxxxxxx"
18+
set the layout of the player's gui to "xxxxxxxxx", "x-------x", and "xxxxxxxxx"
1919
""")
2020
@Since("1.0.0, 1.3.0 (support outside of edit sections)")
21-
public class ExprShape extends SimplePropertyExpression<GUI, String> {
21+
public class ExprLayout extends SimplePropertyExpression<GUI, String> {
2222

2323
public static void register(SyntaxRegistry syntaxRegistry) {
2424
syntaxRegistry.register(SyntaxRegistry.EXPRESSION,
25-
infoBuilder(ExprShape.class, String.class, "[gui] shape[s]", "guis", false)
26-
.supplier(ExprShape::new)
25+
infoBuilder(ExprLayout.class, String.class, "[gui] (layout|shape)[s]", "guis", false)
26+
.supplier(ExprLayout::new)
2727
.build());
2828
}
2929

3030
@Override
3131
public String convert(GUI gui) {
32-
return gui.getRawShape();
32+
return gui.getLayout();
3333
}
3434

3535
@Override
3636
public Class<?> @Nullable [] acceptChange(ChangeMode mode) {
3737
return switch (mode) {
38-
case ADD, DELETE, RESET -> CollectionUtils.array(String[].class);
38+
case SET, DELETE, RESET -> CollectionUtils.array(String[].class);
3939
default -> null;
4040
};
4141
}
4242

4343
@Override
4444
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
45-
if (delta == null) {
46-
for (GUI gui : getExpr().getArray(event)) {
47-
gui.resetShape();
45+
String layout = null;
46+
if (delta != null) {
47+
StringBuilder layoutBuilder = new StringBuilder();
48+
for (Object string : delta) {
49+
layoutBuilder.append((String) string);
4850
}
49-
return;
51+
layout = layoutBuilder.toString();
5052
}
5153

52-
String[] newShape = new String[delta.length];
53-
for (int i = 0; i < delta.length; i++) {
54-
newShape[i] = (String) delta[i];
55-
}
5654
for (GUI gui : getExpr().getArray(event)) {
57-
gui.setShape(newShape);
55+
gui.setLayout(layout);
5856
}
5957
}
6058

@@ -65,7 +63,7 @@ public Class<? extends String> getReturnType() {
6563

6664
@Override
6765
protected String getPropertyName() {
68-
return "shape";
66+
return "layout";
6967
}
7068

7169
}

src/main/java/io/github/apickledwalrus/skriptgui/elements/expressions/ExprNextSlot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
@Name("Next GUI Slot")
2525
@Description("""
2626
Obtains the next open slot of a GUI.
27-
This is a single character representing the next available character of the shape.
27+
This is a single character representing the next available character of the layout.
2828
""")
2929
@Example("make the next gui slot with dirt named \"Slot: %the next gui slot%\"")
3030
@Since("1.3.0")

src/main/java/io/github/apickledwalrus/skriptgui/elements/sections/SecCreateGUI.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
create a gui with virtual chest inventory with 3 rows named "My GUI"
3131
""")
3232
@Example("""
33-
create a gui with a virtual chest inventory with shape "xxxxxxxxx", "x-------x", and "xxxxxxxxx"
33+
create a gui with a virtual chest inventory with layout "xxxxxxxxx", "x-------x", and "xxxxxxxxx"
3434
""")
3535
@Example("""
3636
edit the player's gui:
@@ -42,15 +42,15 @@ public class SecCreateGUI extends EffectSection {
4242
public static void register(SyntaxRegistry syntaxRegistry) {
4343
syntaxRegistry.register(SyntaxRegistry.SECTION, SyntaxInfo.builder(SecCreateGUI.class)
4444
.supplier(SecCreateGUI::new)
45-
.addPatterns("create [a] [new] gui [[with id[entifier]] %-string%] with [a] %inventory% [removable:(and|with) ([re]mov[e]able|stealable) items] [(and|with) shape %-strings%]",
45+
.addPatterns("create [a] [new] gui [[with id[entifier]] %-string%] with [a] %inventory% [removable:(and|with) ([re]mov[e]able|stealable) items] [(and|with) (layout|shape) %-strings%]",
4646
"(change|edit) [gui] %gui%")
4747
.build());
4848
}
4949

5050
private @Nullable Expression<String> id;
5151
private Expression<Inventory> inventory;
5252
private boolean removableItems;
53-
private @Nullable Expression<String> shape;
53+
private @Nullable Expression<String> layout;
5454

5555
private @Nullable Expression<GUI> gui;
5656

@@ -67,7 +67,7 @@ public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean kl
6767
} else {
6868
id = (Expression<String>) expressions[0];
6969
inventory = (Expression<Inventory>) expressions[1];
70-
shape = (Expression<String>) expressions[2];
70+
layout = (Expression<String>) expressions[2];
7171
removableItems = parseResult.hasTag("removable");
7272
}
7373

@@ -96,7 +96,16 @@ public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean kl
9696
name = exprVirtualInventory.getName();
9797
}
9898

99-
gui = new GUI(inventory, removableItems, name, shape == null ? null : shape.getArray(event));
99+
String layout = null;
100+
if (this.layout != null) {
101+
StringBuilder layoutBuilder = new StringBuilder();
102+
for (String string : this.layout.getArray(event)) {
103+
layoutBuilder.append(string);
104+
}
105+
layout = layoutBuilder.toString();
106+
}
107+
108+
gui = new GUI(inventory, removableItems, name, layout);
100109

101110
String id = this.id == null ? null : this.id.getSingle(event);
102111
if (id != null && !id.isEmpty()) {
@@ -152,7 +161,7 @@ public String toString(@Nullable Event event, boolean debug) {
152161
.appendIf(id != null, "with id", id)
153162
.append("with", inventory)
154163
.appendIf(removableItems, "with removable items")
155-
.appendIf(shape != null, "and shape", shape)
164+
.appendIf(layout != null, "and layout", layout)
156165
.toString();
157166
}
158167

src/main/java/io/github/apickledwalrus/skriptgui/elements/sections/SecSlotChange.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
@Name("GUI Slot Change")
2828
@Description("""
2929
A section for executing code when a slot changes.
30-
Note that for shaped GUIs, where multiple slots are represented by a single character, the section will execute when any of those slots change.
30+
Note that for GUIs with a layout, where multiple slots are represented by a single character, the section will execute when any of those slots change.
3131
""")
3232
@Example("""
33-
create a gui with a virtual chest inventory with shape "xxxxxxxxx", "x-------x", and "xxxxxxxxx"
33+
create a gui with a virtual chest inventory with layout "xxxxxxxxx", "x-------x", and "xxxxxxxxx"
3434
run when slot 1 changes:
3535
send "You changed slot 1"
3636
run when slot "-" changes:

0 commit comments

Comments
 (0)