Skip to content

Commit

Permalink
Added Outfit Feature~
Browse files Browse the repository at this point in the history
  • Loading branch information
Iteranya committed Nov 23, 2024
1 parent d762910 commit 6497f0b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/main/java/org/arsparadox/mobtalkerredux/DemoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import org.arsparadox.mobtalkerredux.vn.controller.vnmodules.PlayerInventoryHandler;
import org.arsparadox.mobtalkerredux.vn.controller.VisualNovelEngine;
import org.arsparadox.mobtalkerredux.vn.controller.vnmodules.PlayerInventoryHandler;
import org.arsparadox.mobtalkerredux.vn.model.ScriptLoader;
import org.arsparadox.mobtalkerredux.vn.view.DialogueScreen;

Expand All @@ -22,7 +22,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(Commands.literal("mob_talker")
.executes(context -> {
if (context.getSource().getEntity() instanceof ServerPlayer player) {
serverSideExecute(player, "demo.json");
serverSideExecute(player, "demo");
}
return 1;
})
Expand All @@ -43,12 +43,12 @@ private static void serverSideExecute(ServerPlayer player, String scriptFileName
boolean day = player.level().isDay();

try {
List<Map<String,Object>> script = ScriptLoader.loadScript(scriptFileName,null,uid);
List<Map<String,Object>> script = ScriptLoader.loadScript(scriptFileName,"default",uid);
List<Map<String,Object>> global = ScriptLoader.loadGlobal(uid);
VisualNovelEngine vnEngine = new VisualNovelEngine(
script,
scriptFileName,
null,
"demo",
uid,
day,
inventory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public DialogueScreen(VisualNovelEngine vn, LivingEntity target, Player player)
super(Component.empty());
this.vn = vn;
this.se = new SoundUtils();
this.mob = (Mob)target;
this.player = player;


}
Expand Down Expand Up @@ -172,14 +170,14 @@ public void render(GuiGraphics poseStack, int mouseX, int mouseY, float partialT
// Render the Sprites and Everything In Foreground
if (spritesToRender != null && !spritesToRender.isEmpty()) {
ForegroundComponent.processForeground(
poseStack, this.width, this.height, spritesToRender
poseStack, this.width, this.height, spritesToRender,vn.localVariables
);
}

// Render the Dialogue Box
if (content != null && !content.isEmpty() && !hiddenDialogue) {
poseStack = DialogueBoxManager.processGui(
poseStack,this.width,this.height,content,label,this.font
poseStack,this.width,this.height,content,label,this.font,vn.localVariables
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DialogueBoxManager {

public static GuiGraphics processGui(GuiGraphics poseStack, int width,int height,String content, String label, Font font){
public static GuiGraphics processGui(GuiGraphics poseStack, int width,int height,String content, String label, Font font, Map<String,Object> variables){
int CHARACTER_NAME_OFFSET = 40;
int DISPLAYED_SPRITE_HEIGHT = 300;
int dialogueBoxHeight = 80;
int DIALOGUE_BOX_PADDING = 15;
if (content != null && !content.isEmpty()) {
// Set dialogue box dimensions and position
content = replaceTemplateVariables(variables,content);
int boxWidth = Math.min(600, width - 40); // Max width of 600 or screen width - 40
int boxX = (width - boxWidth) / 2;
int boxY = height - dialogueBoxHeight - 5; // 20 pixels from bottom
Expand Down Expand Up @@ -178,6 +182,27 @@ private static List<String> wrapText(String text, int maxWidth, Font font) {
return lines;
}

public static String replaceTemplateVariables(Map<String, Object> variables, String template) {
if (template == null || variables == null) {
return template;
}

String result = template;
Pattern pattern = Pattern.compile("<(.*?)>");
Matcher matcher = pattern.matcher(template);

while (matcher.find()) {
String key = matcher.group(1);
Object value = variables.get(key);

if (value != null) {
result = result.replace("<" + key + ">", value.toString());
}
}

return result;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import org.arsparadox.mobtalkerredux.vn.data.SpriteState;

import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ForegroundComponent {
// MINECRAFT RENDERING SYSTEM IS A NIGHTMARE!!!
Expand All @@ -25,11 +28,13 @@ public class ForegroundComponent {
// Yeah...
// So in the FSM, determining position should be like:
// (Screen Ratio, Image Ratio, Coordinate Position) -> (16x9, 3x5, 8x1)
public static GuiGraphics processForeground(GuiGraphics poseStack, int width, int height, List<SpriteState> spritesToRender){
public static GuiGraphics processForeground(GuiGraphics poseStack, int width, int height, List<SpriteState> spritesToRender, Map<String, Object> variables){

for (SpriteState sprite : spritesToRender) {
String spriteLocationRaw = sprite.getLocation();
String spriteLocation = replaceTemplateVariables(variables,spriteLocationRaw);
ResourceLocation currentSprite = new ResourceLocation(
"mobtalkerredux", "textures/" + sprite.getLocation()
"mobtalkerredux", "textures/" + spriteLocation
);
RenderSystem.setShaderTexture(0, currentSprite);

Expand Down Expand Up @@ -77,4 +82,27 @@ public static GuiGraphics processForeground(GuiGraphics poseStack, int width, in
return poseStack;
}



public static String replaceTemplateVariables(Map<String, Object> variables, String template) {
if (template == null || variables == null) {
return template;
}

String result = template;
Pattern pattern = Pattern.compile("<(.*?)>");
Matcher matcher = pattern.matcher(template);

while (matcher.find()) {
String key = matcher.group(1);
Object value = variables.getOrDefault(key, "default");

result = result.replace("<" + key + ">", value.toString());
}

return result;
}



}

0 comments on commit 6497f0b

Please sign in to comment.