Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamDman committed Jul 15, 2024
2 parents 348b54f + 6f117e1 commit 81274a7
Show file tree
Hide file tree
Showing 49 changed files with 2,770 additions and 1,039 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mod_name=Super Factory Manager
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=Mozilla Public License Version 2.0
# The mod version. See https://semver.org/
mod_version=4.16.1
mod_version=4.17.0
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
526 changes: 522 additions & 4 deletions src/gametest/java/ca/teamdman/sfm/SFMCorrectnessGameTests.java

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/gametest/java/ca/teamdman/sfm/SFMGameTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ca.teamdman.sfm.common.item.DiskItem;
import ca.teamdman.sfm.common.program.ProgramContext;
import ca.teamdman.sfml.ast.Block;
import ca.teamdman.sfml.ast.Program;
import ca.teamdman.sfml.ast.Trigger;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -22,6 +23,7 @@
import java.util.Locale;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.IntStream;
import java.util.stream.LongStream;

Expand All @@ -32,6 +34,21 @@ protected static void assertTrue(boolean condition, String message) {
}
}

protected static Program compile(String code) {
AtomicReference<Program> rtn = new AtomicReference<>();
Program.compile(
code,
rtn::set,
errors -> {
throw new GameTestAssertException("Failed to compile program: " + errors
.stream()
.map(Object::toString)
.reduce("", (a, b) -> a + "\n" + b));
}
);
return rtn.get();
}

protected static void succeedIfManagerDidThingWithoutLagging(
GameTestHelper helper,
ManagerBlockEntity manager,
Expand Down
11 changes: 9 additions & 2 deletions src/generated/resources/assets/sfm/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
"gui.sfm.manager.edit_button.tooltip": "Press Ctrl+E to edit.",
"gui.sfm.manager.hovered_tick_time": "Hovered tick time: %s ms",
"gui.sfm.manager.peak_tick_time": "Peak tick time: %s ms",
"gui.sfm.manager.reset_confirm_screen.message": "Are you sure you want to reset this disk?",
"gui.sfm.manager.reset_confirm_screen.no_button": "Never mind, make no changes",
"gui.sfm.manager.reset_confirm_screen.title": "Reset disk?",
"gui.sfm.manager.reset_confirm_screen.yes_button": "Wipe program and labels",
"gui.sfm.manager.state": "State: %s",
"gui.sfm.manager.state.invalid_program": "invalid program",
"gui.sfm.manager.state.no_disk": "missing disk",
Expand All @@ -70,6 +74,7 @@
"gui.sfm.save_changes_confirm.yes_button": "Overwrite disk",
"gui.sfm.text_editor.done_button.tooltip": "Shift+Enter to submit",
"gui.sfm.text_editor.title": "Text Editor",
"gui.sfm.text_editor.toggle_line_numbers_button.tooltip": "Toggle line numbers",
"gui.sfm.title.labelgun": "Label Gun",
"gui.sfm.title.program_template_picker": "Program Template Picker",
"item.sfm.disk": "Factory Manager Program Disk",
Expand Down Expand Up @@ -109,7 +114,7 @@
"log.sfm.program.tick": "PROGRAM TICK BEGIN",
"log.sfm.program.tick.redstone_count": "Program ticking with %d unprocessed redstone pulses.",
"log.sfm.program.voided_resources": "!!!RESOURCE LOSS HAS OCCURRED!!! Failed to move all promised items, found %s %s:%s, took %d but had %d left over after insertion",
"log.sfm.resource_type.get_capabilities.begin": "Gathering capabilities of type %s against labels %s",
"log.sfm.resource_type.get_capabilities.begin": "Gathering capabilities of type %s (%s) against labels %s",
"log.sfm.resource_type.get_capabilities.not_present": "Capability %s %s direction=%s not present",
"log.sfm.resource_type.get_capabilities.present": "Capability %s %s direction=%s present",
"log.sfm.statement.tick.forget": "FORGET %s",
Expand All @@ -124,7 +129,7 @@
"log.sfm.statement.tick.io.gather_slots.not_each": "EACH keyword not used - trackers will be shared between blocks",
"log.sfm.statement.tick.io.gather_slots.not_in_range": "Slot %d - not in range",
"log.sfm.statement.tick.io.gather_slots.range": "Gathering slots in range set: %s",
"log.sfm.statement.tick.io.gather_slots.resource_types": "Gathering for: %s",
"log.sfm.statement.tick.io.gather_slots.resource_types": "Gathering for: %s (%s)",
"log.sfm.statement.tick.io.gather_slots.should_not_create": "Slot %d - skipping - %s",
"log.sfm.statement.tick.io.move_to.begin": "Begin moving %s into %s",
"log.sfm.statement.tick.io.move_to.destination_tracker_reject": "Destination tracker rejected the transfer, skipping",
Expand Down Expand Up @@ -156,9 +161,11 @@
"program.sfm.warnings.adjacent_but_disconnected_label": "Label \"%s\" is assigned in the world at %s and is connected by cables but is not detected as a valid inventory.",
"program.sfm.warnings.disconnected_label": "Label \"%s\" is assigned in the world at %s but not connected by cables.",
"program.sfm.warnings.each_without_pattern": "EACH used without a pattern, statement %s",
"program.sfm.warnings.output_label_not_found_in_inputs": "Statement \"%s\" at %s uses resource type \"%s\" which has no matching input statement.",
"program.sfm.warnings.round_robin_smelly_count": "Round robin by label should be used with more than one label, statement %s",
"program.sfm.warnings.round_robin_smelly_each": "Round robin by block shouldn't be used with EACH, statement %s",
"program.sfm.warnings.undefined_label": "Label \"%s\" is assigned in the world but not defined in code.",
"program.sfm.warnings.unknown_resource_id": "Resource \"%s\" was not found.",
"program.sfm.warnings.unused_input_label": "Statement \"%s\" at %s inputs \"%s\" from \"%s\" but no future output statement consume \"%s\".",
"program.sfm.warnings.unused_label": "Label \"%s\" is used in code but not assigned in the world."
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static Optional<Runnable> getContextAction(String programString, int curs
.getNodesUnderCursor(cursorPosition - 1)
.stream()
)
.map(pair -> getContextAction(programString, builder, pair.a, pair.b, cursorPosition))
.map(pair -> getContextAction(programString, builder, pair.getFirst(), pair.getSecond(), cursorPosition))
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public boolean equalsAnyTemplate(String content) {
@Override
public void saveAndClose() {
// The user is attempting to apply a code change to the disk
if (equalsAnyTemplate(program)) {
if (program.isBlank() || equalsAnyTemplate(program)) {
// The disk contains template code, safe to overwrite
super.saveAndClose();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected void init() {
String finalProgram = program;
Program.compile(
program,
(successProgram, builder) -> templatePrograms.put(
successProgram -> templatePrograms.put(
successProgram.name().isBlank() ? entry.getKey().toString() : successProgram.name(),
finalProgram
),
Expand Down
83 changes: 52 additions & 31 deletions src/main/java/ca/teamdman/sfm/client/gui/screen/ManagerScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
import ca.teamdman.sfm.SFM;
import ca.teamdman.sfm.client.ClientDiagnosticInfo;
import ca.teamdman.sfm.client.ClientStuff;
import ca.teamdman.sfm.common.Constants;
import ca.teamdman.sfm.common.containermenu.ManagerContainerMenu;
import ca.teamdman.sfm.common.item.DiskItem;
import ca.teamdman.sfm.common.net.ServerboundManagerFixPacket;
import ca.teamdman.sfm.common.net.ServerboundManagerProgramPacket;
import ca.teamdman.sfm.common.net.ServerboundManagerRebuildPacket;
import ca.teamdman.sfm.common.net.ServerboundManagerResetPacket;
import ca.teamdman.sfm.common.registry.SFMPackets;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.gui.screens.ConfirmScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.player.LocalPlayer;
Expand Down Expand Up @@ -103,7 +106,7 @@ protected void init() {
buttonWidth,
16,
MANAGER_GUI_PASTE_FROM_CLIPBOARD_BUTTON.getComponent(),
button -> this.onLoadClipboard(),
button -> this.onClipboardPasteButtonClicked(),
buildTooltip(MANAGER_GUI_PASTE_FROM_CLIPBOARD_BUTTON_TOOLTIP)
));
editButton = this.addRenderableWidget(new ExtendedButtonWithTooltip(
Expand All @@ -112,7 +115,7 @@ protected void init() {
buttonWidth,
16,
MANAGER_GUI_EDIT_BUTTON.getComponent(),
button -> onEdit(),
button -> onEditButtonClicked(),
buildTooltip(MANAGER_GUI_EDIT_BUTTON_TOOLTIP)
));
examplesButton = this.addRenderableWidget(new ExtendedButtonWithTooltip(
Expand All @@ -121,7 +124,7 @@ protected void init() {
buttonWidth,
16,
MANAGER_GUI_VIEW_EXAMPLES_BUTTON.getComponent(),
button -> onShowExamples(),
button -> onExamplesButtonClicked(),
buildTooltip(MANAGER_GUI_VIEW_EXAMPLES_BUTTON_TOOLTIP)
));
clipboardCopyButton = this.addRenderableWidget(new ExtendedButton(
Expand All @@ -130,31 +133,31 @@ protected void init() {
buttonWidth,
16,
MANAGER_GUI_COPY_TO_CLIPBOARD_BUTTON.getComponent(),
button -> this.onSaveClipboard()
button -> this.onClipboardCopyButtonClicked()
));
logsButton = this.addRenderableWidget(new ExtendedButton(
(this.width - this.imageWidth) / 2 - buttonWidth,
(this.height - this.imageHeight) / 2 + 16 * 9,
buttonWidth,
16,
MANAGER_GUI_VIEW_LOGS_BUTTON.getComponent(),
button -> onShowLogs()
button -> onLogsButtonClicked()
));
rebuildButton = this.addRenderableWidget(new ExtendedButton(
(this.width - this.imageWidth) / 2 - buttonWidth,
(this.height - this.imageHeight) / 2 + 16 * 10,
buttonWidth,
16,
MANAGER_GUI_REBUILD_BUTTON.getComponent(),
button -> this.onSendRebuild()
button -> this.onRebuildButtonClicked()
));
resetButton = this.addRenderableWidget(new ExtendedButtonWithTooltip(
(this.width - this.imageWidth) / 2 + 120,
(this.height - this.imageHeight) / 2 + 10,
50,
12,
MANAGER_GUI_RESET_BUTTON.getComponent(),
button -> sendReset(),
button -> onResetButtonClicked(),
buildTooltip(MANAGER_GUI_RESET_BUTTON_TOOLTIP)
));
diagButton = this.addRenderableWidget(new ExtendedButtonWithTooltip(
Expand All @@ -163,42 +166,60 @@ protected void init() {
12,
14,
Component.literal("!"),
button -> {
if (Screen.hasShiftDown() && !isReadOnly()) {
sendAttemptFix();
} else {
this.onSaveDiagClipboard();
}
},
button -> onDiagButtonClicked(),
buildTooltip(isReadOnly()
? MANAGER_GUI_WARNING_BUTTON_TOOLTIP_READ_ONLY
: MANAGER_GUI_WARNING_BUTTON_TOOLTIP)
));
updateVisibilities();
}

private void onEdit() {
private void onDiagButtonClicked() {
if (Screen.hasShiftDown() && !isReadOnly()) {
sendAttemptFix();
} else {
this.onSaveDiagClipboard();
}
}

private void onEditButtonClicked() {
ClientStuff.showProgramEditScreen(DiskItem.getProgram(menu.getDisk()), this::sendProgram);
}

private void onShowExamples() {
private void onExamplesButtonClicked() {
ClientStuff.showExampleListScreen(DiskItem.getProgram(menu.getDisk()), this::sendProgram);
}

private void onShowLogs() {
private void onLogsButtonClicked() {
ClientStuff.showLogsScreen(menu);
}

private void sendReset() {
PacketDistributor.SERVER.noArg().send(new ServerboundManagerResetPacket(
menu.containerId,
menu.MANAGER_POSITION
));
status = MANAGER_GUI_STATUS_RESET.getComponent();
statusCountdown = STATUS_DURATION;
private void onResetButtonClicked() {
ConfirmScreen confirmScreen = new ConfirmScreen(
proceed -> {
assert this.minecraft != null;
this.minecraft.popGuiLayer(); // Close confirm screen

if (proceed) {
PacketDistributor.SERVER.noArg().send(new ServerboundManagerResetPacket(
menu.containerId,
menu.MANAGER_POSITION
));
status = MANAGER_GUI_STATUS_RESET.getComponent();
statusCountdown = STATUS_DURATION;
}
},
Constants.LocalizationKeys.MANAGER_RESET_CONFIRM_SCREEN_TITLE.getComponent(),
Constants.LocalizationKeys.MANAGER_RESET_CONFIRM_SCREEN_MESSAGE.getComponent(),
Constants.LocalizationKeys.MANAGER_RESET_CONFIRM_SCREEN_YES_BUTTON.getComponent(),
Constants.LocalizationKeys.MANAGER_RESET_CONFIRM_SCREEN_NO_BUTTON.getComponent()
);
assert this.minecraft != null;
this.minecraft.pushGuiLayer(confirmScreen);
confirmScreen.setDelay(20);
}

private void onSendRebuild() {
private void onRebuildButtonClicked() {
PacketDistributor.SERVER.noArg().send(new ServerboundManagerRebuildPacket(
menu.containerId,
menu.MANAGER_POSITION
Expand Down Expand Up @@ -227,7 +248,7 @@ private void sendProgram(String program) {
statusCountdown = STATUS_DURATION;
}

private void onSaveClipboard() {
private void onClipboardCopyButtonClicked() {
try {
Minecraft.getInstance().keyboardHandler.setClipboard(menu.program);
status = MANAGER_GUI_STATUS_SAVED_CLIPBOARD.getComponent();
Expand Down Expand Up @@ -260,7 +281,7 @@ private void onSaveDiagClipboard() {
}
}

private void onLoadClipboard() {
private void onClipboardPasteButtonClicked() {
try {
String contents = Minecraft.getInstance().keyboardHandler.getClipboard();
sendProgram(contents);
Expand All @@ -272,19 +293,19 @@ private void onLoadClipboard() {
@Override
public boolean keyPressed(int pKeyCode, int pScanCode, int pModifiers) {
if (Screen.isPaste(pKeyCode) && clipboardPasteButton.visible) {
onLoadClipboard();
onClipboardPasteButtonClicked();
return true;
} else if (Screen.isCopy(pKeyCode) && clipboardCopyButton.visible) {
onSaveClipboard();
onClipboardCopyButtonClicked();
return true;
} else if (pKeyCode == GLFW.GLFW_KEY_E
&& Screen.hasControlDown()
&& Screen.hasShiftDown()
&& examplesButton.visible) {
onShowExamples();
onExamplesButtonClicked();
return true;
} else if (pKeyCode == GLFW.GLFW_KEY_E && Screen.hasControlDown() && editButton.visible) {
onEdit();
onEditButtonClicked();
return true;
}
return super.keyPressed(pKeyCode, pScanCode, pModifiers);
Expand Down
Loading

0 comments on commit 81274a7

Please sign in to comment.