Skip to content

Commit 607ed89

Browse files
committed
redo export modal
1 parent acd9c3b commit 607ed89

File tree

3 files changed

+31
-34
lines changed

3 files changed

+31
-34
lines changed

src/lib/components/CheckBox.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
$props();
66
</script>
77

8-
<div class="mt-2 flex items-center gap-2">
8+
<div class="flex items-center gap-2">
99
<button
1010
name={label}
1111
class="flex aspect-square size-8 flex-col items-center rounded-md bg-zinc-900"

src/lib/components/modals/ExportModal.svelte

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
outputVersion = $bindable(),
1010
editor,
1111
recentlyCopied,
12-
indent,
13-
indentSize,
1412
shouldOptimise = true,
1513
} = $props();
1614
@@ -39,30 +37,36 @@
3937
<option value="new">1.21.5+</option>
4038
<option value="old">Before 1.21.5</option>
4139
</select>
42-
<div class="mt-2 flex w-full flex-col">
43-
<p>For tellraw commands (send to chat):</p>
40+
<div class="flex w-full flex-col">
41+
{#if outputVersion == "new"}
42+
<div class="flex items-center space-x-2 mt-1">
43+
<CheckBox bind:value={exportAsJSON} label="json" />
44+
<span>Toggle JSON mode (for use in json files)</span>
45+
</div>
46+
{/if}
47+
48+
<p class="mt-2">As {outputVersion == "new" ? " " : "JSON "}text components:</p>
4449
<div class="flex items-start space-x-3 rounded-lg bg-zinc-950 p-3">
4550
<button
4651
class="rounded-md p-1 text-lg font-medium hover:bg-zinc-900 active:bg-white/10"
4752
onclick={() => {
4853
navigator.clipboard.writeText(
49-
"/tellraw @s " +
50-
convert(
51-
editor.getJSON(),
52-
"standard",
53-
outputVersion,
54-
shouldOptimise,
55-
),
54+
convert(
55+
editor.getJSON(),
56+
"standard",
57+
outputVersion,
58+
shouldOptimise,
59+
exportAsJSON
60+
),
5661
);
5762
recentlyCopied = true;
5863
setTimeout(() => (recentlyCopied = false), 2000);
5964
}}>
6065
<IconCopy />
6166
</button>
62-
<code class="inline-block max-h-56 w-full overflow-auto"
63-
><span class="text-white/60">/tellraw @s</span>
67+
<code class="inline-block max-h-56 w-full overflow-auto">
6468
{editor
65-
? convert(editor.getJSON(), "standard", outputVersion, shouldOptimise)
69+
? convert(editor.getJSON(), "standard", outputVersion, shouldOptimise, exportAsJSON)
6670
: "Loading..."}
6771
</code>
6872
</div>
@@ -73,32 +77,24 @@
7377
class="rounded-md p-1 text-lg font-medium hover:bg-zinc-900 active:bg-white/10"
7478
onclick={() => {
7579
navigator.clipboard.writeText(
76-
`[lore=${convert(editor.getJSON(), "item_lore", outputVersion, shouldOptimise)}]`,
80+
`[lore=${convert(editor.getJSON(), "item_lore", outputVersion, shouldOptimise, exportAsJSON)}]`,
7781
);
7882
recentlyCopied = true;
7983
setTimeout(() => (recentlyCopied = false), 2000);
8084
}}>
8185
<IconCopy />
8286
</button>
83-
{#if outputVersion == "new"}
8487
<code class="inline-block max-h-56 w-full overflow-auto"
85-
><span class="text-white/60">[lore=</span>{editor
86-
? exportThing(exportAsJSON)
87-
: "Loading..."}<span class="text-white/60">]</span>
88-
</code>
89-
<CheckBox bind:value={exportAsJSON} label="json" />
90-
<label for="json">Export as JSON</label>
91-
{:else}
92-
<code class="inline-block max-h-56 w-full overflow-auto"
93-
><span class="text-white/60">[lore=</span>{editor
94-
? `'${translateJSON(editor.getJSON(), {
95-
exportType: "item_lore",
96-
exportVersion: outputVersion,
97-
optimise: shouldOptimise,
98-
})}`
99-
: "Loading..."}'<span class="text-white/60">]</span>
88+
><span class="text-white/35">[lore=</span>{editor
89+
? convert(
90+
editor.getJSON(),
91+
"item_lore",
92+
outputVersion,
93+
shouldOptimise,
94+
exportAsJSON
95+
)
96+
: "Loading..."}<span class="text-white/35">]</span>
10097
</code>
101-
{/if}
10298
</div>
10399

104100
<p class="mt-2">As a MOTD:</p>

src/lib/text/nbt_or_json.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,10 @@ export function convert(
319319
exportType: "standard" | "item_lore" = "standard",
320320
exportVersion: "new" | "old" = "new",
321321
optimise: boolean,
322+
force_json: boolean = false
322323
): string {
323324
let out = translateJSON(jsonContent, { exportVersion, exportType, optimise });
324-
if (exportVersion == "new") {
325+
if (exportVersion == "new" && !force_json) {
325326
// only remove strings
326327
out = out.replace(/(?<=[{,]\s*)"[^"]*"\s*:/g, (match) =>
327328
match.replace(/"/g, ""),

0 commit comments

Comments
 (0)