Skip to content

Commit

Permalink
The "My Version" Development
Browse files Browse the repository at this point in the history
100% NOT Canon, Not Official, Not Default, Not Associated with Anything...

This is just a thing I make because want to
  • Loading branch information
Iteranya committed Nov 5, 2024
1 parent d6535b4 commit 6fa01b8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/arsparadox/mobtalkerredux/DemoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
if (context.getSource().getEntity() instanceof ServerPlayer player) {
Minecraft.getInstance().execute(() -> {
try {
Minecraft.getInstance().setScreen(new DialogueScreen(new VisualNovelEngine(ScriptLoader.loadDemo())));
Minecraft.getInstance().setScreen(new DialogueScreen(new VisualNovelEngine(ScriptLoader.loadDemo(),"demo.json")));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -38,7 +38,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
Minecraft.getInstance().execute(() -> {
try {
player.sendSystemMessage(Component.literal("Trying to load the file config/mobtalkerredux/"+name));
Minecraft.getInstance().setScreen(new DialogueScreen(new VisualNovelEngine(ScriptLoader.loadScript(name))));
Minecraft.getInstance().setScreen(new DialogueScreen(new VisualNovelEngine(ScriptLoader.loadScript(name),"demo.json")));

} catch (IOException e) {
player.sendSystemMessage(Component.literal("Failed to find the file config/mobtalkerredux/"+name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public InteractionResult useOn(UseOnContext context) {

Minecraft.getInstance().execute(() -> {
try {
Minecraft.getInstance().setScreen(new DialogueScreen(new VisualNovelEngine(ScriptLoader.loadDemo())));
Minecraft.getInstance().setScreen(new DialogueScreen(new VisualNovelEngine(ScriptLoader.loadDemo(),"demo.json")));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.arsparadox.mobtalkerredux.vn.data.DialogueState;
import org.arsparadox.mobtalkerredux.vn.data.SpriteState;
import org.arsparadox.mobtalkerredux.vn.model.ScriptLoader;

import java.util.*;

Expand All @@ -14,11 +15,14 @@ public class VisualNovelEngine {
public DialogueState state;
public boolean isEngineRunning = false;

public VisualNovelEngine(List<Map<String, Object>> gameData) {
public String scriptName;

public VisualNovelEngine(List<Map<String, Object>> gameData,String scriptName) {
this.gameData = gameData;
this.currentState = 0;
this.variables = new HashMap<>();
this.state = new DialogueState(null,null,null);
this.scriptName = scriptName;
}

private Long findLabelId(String var) {
Expand Down Expand Up @@ -248,15 +252,20 @@ private boolean processAction(Map<String, Object> action) {
this.currentState++;
break;
case "finish_dialogue":
isEngineRunning=false;
shutdown = true;
processFinishing();
default:
this.currentState++;
break;
}
return false;
}

private void processFinishing() {
isEngineRunning=false;
ScriptLoader.saveState(variables,scriptName);
shutdown = true;
}

public void runEngine() {
while (isEngineRunning) { // Infinite loop
// Check if engine is running
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.io.*;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -72,4 +73,25 @@ public static List<Map<String, Object>> loadDemo() throws IOException {
throw new FileNotFoundException("Resource file demo.json could not be found.");
}
}

public static void saveState(Map<String, Object> variables, String filePath) {
try {
filePath = FMLPaths.CONFIGDIR.get() + "\\"+ MobTalkerRedux.MODID +"\\" + filePath;
// Load existing JSON content
List<Map<String, Object>> list = loadJson(filePath);

// Append the 'variables' map to the list
list.add(variables);

// Convert the updated list back to a JSON string
String jsonContent = gson.toJson(list);

// Save the JSON string back into the file
try (Writer writer = new OutputStreamWriter(new FileOutputStream(filePath), StandardCharsets.UTF_8)) {
writer.write(jsonContent);
}
} catch (IOException e) {
throw new RuntimeException("Failed to save state to file at " + filePath, e);
}
}
}

0 comments on commit 6fa01b8

Please sign in to comment.