Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/main/java/io/github/techstreet/dfscript/screen/CScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.Items;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;

Expand All @@ -25,6 +24,10 @@ protected CScreen(int width, int height) {
// DFScript.MC.keyboard.setRepeatEvents(true);
}

public void changeScreen(Screen screen) {
DFScript.MC.setScreen(screen);
}

@Override
public void render(@NotNull DrawContext context, int mouseX, int mouseY, float tickDelta) {
//renderBackground(context, mouseX, mouseY, tickDelta);
Expand Down Expand Up @@ -174,4 +177,13 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double del

return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
}

public static CScreen getCurrent() {
Screen current = DFScript.MC.currentScreen;

if(current instanceof CScreen c) {
return c;
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import io.github.techstreet.dfscript.screen.widget.CScrollPanel;
import io.github.techstreet.dfscript.script.Script;
import io.github.techstreet.dfscript.script.ScriptParametrizedPart;
import io.github.techstreet.dfscript.script.ScriptPart;
import io.github.techstreet.dfscript.script.action.ScriptAction;
import io.github.techstreet.dfscript.script.argument.ScriptConfigArgument;
import io.github.techstreet.dfscript.script.event.ScriptHeader;
import io.github.techstreet.dfscript.script.options.ScriptNamedOption;
Expand All @@ -19,8 +17,8 @@ public class ScriptAddConfigValueScreen extends CScreen {
private final ScriptParametrizedPart action;
private final int insertIndex;

private static int WIDTH = 200;
private static int HEIGHT = 94;
private static final int WIDTH = 200;
private static final int HEIGHT = 94;

public ScriptAddConfigValueScreen(ScriptParametrizedPart action, Script script, int insertIndex, ScriptHeader header, String overwrite) {
super(WIDTH, HEIGHT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.github.techstreet.dfscript.script.Script;
import io.github.techstreet.dfscript.script.ScriptParametrizedPart;
import io.github.techstreet.dfscript.script.action.ScriptActionArgument;
import io.github.techstreet.dfscript.script.argument.ScriptConfigArgument;
import io.github.techstreet.dfscript.script.argument.ScriptFunctionArgument;
import io.github.techstreet.dfscript.script.event.ScriptFunction;
import io.github.techstreet.dfscript.script.event.ScriptHeader;
Expand All @@ -19,8 +18,8 @@ public class ScriptAddFunctionArgValueScreen extends CScreen {
private final ScriptParametrizedPart action;
private final int insertIndex;

private static int WIDTH = 200;
private static int HEIGHT = 94;
private static final int WIDTH = 200;
private static final int HEIGHT = 94;

public ScriptAddFunctionArgValueScreen(ScriptParametrizedPart action, Script script, int insertIndex, ScriptHeader header, String overwrite) {
super(WIDTH, HEIGHT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import io.github.techstreet.dfscript.script.options.ScriptOptionEnum;
import io.github.techstreet.dfscript.util.chat.ChatUtil;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.text.Text;
Expand All @@ -19,7 +18,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class ScriptAddSettingSubtypeScreen extends CScreen {

Expand All @@ -33,7 +31,7 @@ public class ScriptAddSettingSubtypeScreen extends CScreen {

private int optionPos;

private List<ScriptOptionEnum> subtypes;
private final List<ScriptOptionEnum> subtypes;

static {
primitiveTypes = Arrays.stream(ScriptOptionEnum.values()).filter(c -> c.getExtraTypes() == 0).toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.github.techstreet.dfscript.DFScript;
import io.github.techstreet.dfscript.screen.CReloadableScreen;
import io.github.techstreet.dfscript.screen.CScreen;
import io.github.techstreet.dfscript.screen.ContextMenuButton;
import io.github.techstreet.dfscript.screen.widget.*;
import io.github.techstreet.dfscript.script.Script;
Expand All @@ -12,8 +11,8 @@
import io.github.techstreet.dfscript.script.event.ScriptHeader;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -57,7 +56,7 @@ public void reload()
panel.add(name);

CButton settings = new CTexturedButton(120-8, y, 8, 8, DFScript.MOD_ID + ":settings.png", DFScript.MOD_ID + ":settings_highlight.png", () -> {
DFScript.MC.setScreen(new ScriptSettingsScreen(this.script, true));
changeScreen(new ScriptSettingsScreen(this.script, true));
});
panel.add(settings);

Expand Down Expand Up @@ -86,10 +85,10 @@ public boolean mouseClicked(double x, double y, int button) {

if (button != 0) {
CButton insertBefore = new CButton((int) x, (int) y, 40, 8, "Insert Before", () -> {
DFScript.MC.setScreen(new ScriptHeaderCategoryScreen(script, currentIndex));
changeScreen(new ScriptHeaderCategoryScreen(script, currentIndex));
});
CButton insertAfter = new CButton((int) x, (int) y+8, 40, 8, "Insert After", () -> {
DFScript.MC.setScreen(new ScriptHeaderCategoryScreen(script, currentIndex + 1));
changeScreen(new ScriptHeaderCategoryScreen(script, currentIndex + 1));
});
CButton delete = new CButton((int) x, (int) y+16, 40, 8, "Delete", () -> {
script.getHeaders().remove(currentIndex);
Expand All @@ -109,7 +108,7 @@ public boolean mouseClicked(double x, double y, int button) {
}
else {
if(header instanceof ScriptFunction f) {
DFScript.MC.setScreen(new ScriptEditFunctionScreen(f, script));
changeScreen(new ScriptEditFunctionScreen(f, script));
}
}
return true;
Expand All @@ -121,14 +120,20 @@ public boolean mouseClicked(double x, double y, int button) {
}

CButton add = new CButton(37, y, 46, 8, "Add Header", () -> {
DFScript.MC.setScreen(new ScriptHeaderCategoryScreen(script, script.getHeaders().size()));
changeScreen(new ScriptHeaderCategoryScreen(script, script.getHeaders().size()));
});

panel.add(add);

panel.setScroll(scroll);
}

@Override
public void changeScreen(Screen screen) {
scroll = panel.getScroll();
DFScript.MC.setScreen(screen);
}

public void createIndent(int indent, int y)
{
for (int i = 0; i < indent; i += 5) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ public boolean mouseClicked(double x, double y, int button) {

if (button != 0) {
CButton insertBefore = new CButton((int) x, (int) y, 40, 8, "Insert Before", () -> {
scroll = panel.getScroll();
DFScript.MC.setScreen(new ScriptAddSettingScreen(script, finalIndex));
});
CButton insertAfter = new CButton((int) x, (int) y+8, 40, 8, "Insert After", () -> {
scroll = panel.getScroll();
DFScript.MC.setScreen(new ScriptAddSettingScreen(script, finalIndex + 1));
});
CButton delete = new CButton((int) x, (int) y+16, 40, 8, "Delete", () -> {
Expand All @@ -107,6 +109,7 @@ public boolean mouseClicked(double x, double y, int button) {
}
else
{
scroll = panel.getScroll();
DFScript.MC.setScreen(new ScriptEditSettingScreen(script, option));
}
return true;
Expand All @@ -126,6 +129,7 @@ public boolean mouseClicked(double x, double y, int button) {
if(owned)
{
CButton add = new CButton(37, y, 48, 9, "Add Option", () -> {
scroll = panel.getScroll();
DFScript.MC.setScreen(new ScriptAddSettingScreen(script, script.getOptions().size()));
});
panel.add(add);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io.github.techstreet.dfscript.script.options.ScriptNamedOption;
import io.github.techstreet.dfscript.script.repetitions.ScriptBuiltinRepetition;
import io.github.techstreet.dfscript.script.repetitions.ScriptWhile;
import io.github.techstreet.dfscript.script.util.ScriptValueJson;
import io.github.techstreet.dfscript.script.values.*;
import io.github.techstreet.dfscript.util.FileUtil;
import io.github.techstreet.dfscript.util.chat.ChatType;
Expand Down Expand Up @@ -77,7 +76,8 @@ public class ScriptManager implements Loadable {
.registerTypeAdapter(ScriptTextValue.class, new ScriptTextValue.Serializer())
.registerTypeAdapter(ScriptListValue.class, new ScriptListValue.Serializer())
.registerTypeAdapter(ScriptDictionaryValue.class, new ScriptDictionaryValue.Serializer())
.registerTypeAdapter(ScriptBoolValue.class, new ScriptDictionaryValue.Serializer())
.registerTypeAdapter(ScriptBoolValue.class, new ScriptBoolValue.Serializer())
.registerTypeAdapter(ScriptVariable.class, new ScriptVariable.Serializer())
.create();

public ScriptManager() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gson.*;
import io.github.techstreet.dfscript.DFScript;
import io.github.techstreet.dfscript.screen.CScreen;
import io.github.techstreet.dfscript.screen.ContextMenuButton;
import io.github.techstreet.dfscript.screen.script.ScriptEditPartScreen;
import io.github.techstreet.dfscript.screen.script.ScriptEditScreen;
Expand All @@ -17,7 +18,6 @@
import io.github.techstreet.dfscript.script.conditions.ScriptConditionType;
import io.github.techstreet.dfscript.script.event.ScriptHeader;
import io.github.techstreet.dfscript.script.execution.ScriptActionContext;
import io.github.techstreet.dfscript.script.execution.ScriptPosStackElement;
import io.github.techstreet.dfscript.script.execution.ScriptTask;
import io.github.techstreet.dfscript.script.render.ScriptPartRender;
import io.github.techstreet.dfscript.script.repetitions.ScriptBuiltinRepetition;
Expand All @@ -33,7 +33,7 @@
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.Objects;

public class ScriptSnippet extends ArrayList<ScriptPart> {
boolean hidden = false;
Expand Down Expand Up @@ -129,16 +129,16 @@ public boolean mouseClicked(double x, double y, int button) {

if (button == 0) {
if(part instanceof ScriptParametrizedPart parametrizedPart)
DFScript.MC.setScreen(new ScriptEditPartScreen(parametrizedPart, script, header));
CScreen.getCurrent().changeScreen(new ScriptEditPartScreen(parametrizedPart, script, header));
if(part instanceof ScriptComment)
return false;
} else {
List<ContextMenuButton> contextMenu = new ArrayList<>();
contextMenu.add(new ContextMenuButton("Insert Before", () -> {
DFScript.MC.setScreen(new ScriptPartCategoryScreen(script, thisSnippet, currentIndex));
CScreen.getCurrent().changeScreen(new ScriptPartCategoryScreen(script, thisSnippet, currentIndex));
}, false));
contextMenu.add(new ContextMenuButton("Insert After", () -> {
DFScript.MC.setScreen(new ScriptPartCategoryScreen(script, thisSnippet, currentIndex + 1));
CScreen.getCurrent().changeScreen(new ScriptPartCategoryScreen(script, thisSnippet, currentIndex + 1));
}, false));
contextMenu.add(new ContextMenuButton("Delete", () -> {
thisSnippet.remove(currentIndex);
Expand All @@ -162,7 +162,7 @@ public boolean mouseClicked(double x, double y, int button) {

ScriptPartRender.createIndent(panel, indent, y, 8);
CButton add = new CButton((ScriptEditScreen.width-30)/2, y, 30, 8, "Add Part", () -> {
DFScript.MC.setScreen(new ScriptPartCategoryScreen(script, thisSnippet, thisSnippet.size()));
CScreen.getCurrent().changeScreen(new ScriptPartCategoryScreen(script, thisSnippet, thisSnippet.size()));
});

panel.add(add);
Expand Down Expand Up @@ -247,7 +247,7 @@ public void removeOption(String option) {
public void replaceFunction(String oldFunction, String newFunction) {
for(ScriptPart part : this) {
if(part instanceof ScriptFunctionCall fc) {
if(fc.getFunctionName() == oldFunction) {
if(Objects.equals(fc.getFunctionName(), oldFunction)) {
fc.setFunction(newFunction);
}
}
Expand All @@ -263,7 +263,7 @@ public void removeFunction(String function) {
while(index < this.size()) {
ScriptPart part = this.get(index);
if(part instanceof ScriptFunctionCall fc) {
if(fc.getFunctionName() == function) {
if(Objects.equals(fc.getFunctionName(), function)) {
this.remove(index);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import com.google.gson.*;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ScriptDictionaryValue extends ScriptValue {
Expand Down Expand Up @@ -89,7 +87,7 @@ public JsonElement serialize(ScriptDictionaryValue scriptValue, Type type, JsonS
dictObj.add(key, context.serialize(dict.get(key)));
}
JsonObject obj = new JsonObject();
obj.add("dict", obj);
obj.add("dict", dictObj);
obj.addProperty("___objectType", "dict");
return obj;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.github.techstreet.dfscript.script.values;

import io.github.techstreet.dfscript.script.values.ScriptUnknownValue;
import io.github.techstreet.dfscript.script.values.ScriptValue;
import com.google.gson.*;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class ScriptVariable extends ScriptValue {
private ScriptValue value;
Expand All @@ -24,6 +22,11 @@ public ScriptValue get() {
return value;
}

@Override
public String toString() {
return asText();
}

public void set(ScriptValue value) {
this.value = value;
}
Expand Down Expand Up @@ -62,4 +65,26 @@ String typeName() {
public boolean valueEquals(ScriptValue other) {
return get().valueEquals(other);
}

@Override
public ScriptValue getCompareValue() {
return get().getCompareValue();
}

@Override
public int compare(ScriptValue other) {
return get().compare(other);
}

@Override
public String formatAsText() {
return get().formatAsText();
}

public static class Serializer implements JsonSerializer<ScriptVariable> {
@Override
public JsonElement serialize(ScriptVariable scriptValue, Type type, JsonSerializationContext context) {
return context.serialize(scriptValue.get());
}
}
}