Skip to content

Commit 3bd307a

Browse files
committed
feat: 0.4.0 updates
1 parent a79ee27 commit 3bd307a

File tree

6,122 files changed

+205264
-94
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

6,122 files changed

+205264
-94
lines changed

bun.lock

Lines changed: 176 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,22 @@
4141
"@codemirror/lang-json": "^6.0.2",
4242
"@codemirror/language": "^6.11.3",
4343
"@codemirror/lint": "^6.8.5",
44-
"@codemirror/lsp-client": "^6.1.1",
44+
"@codemirror/lsp-client": "^6.1.2",
4545
"@codemirror/search": "^6.5.11",
4646
"@codemirror/view": "^6.38.1",
4747
"@minecraftmetascript/mms-wasm": "../mms/result/js",
48+
"@open-rpc/client-js": "^1.8.1",
4849
"@spyglassmc/mcdoc": "^0.3.38",
4950
"@steeze-ui/svelte-icon": "^1.6.2",
5051
"@steeze-ui/tabler-icons": "^3.3.1",
5152
"@sveltejs/adapter-static": "^3.0.9",
53+
"@tailwindcss/typography": "^0.5.19",
5254
"@types/golang-wasm-exec": "^1.15.2",
5355
"@zip.js/zip.js": "^2.8.2",
5456
"codemirror": "^6.0.2",
5557
"deepslate": "^0.24.0",
5658
"es-toolkit": "^1.39.10",
59+
"svelte-exmarkdown": "^5.0.2",
5760
"svelte-splitpanes": "^8.0.9",
5861
"valibot": "^1.1.0"
5962
}

src/app.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
@import 'tailwindcss';
2+
@plugin "@tailwindcss/typography";
23

34
button {
45
@apply cursor-pointer disabled:cursor-default;
56
}
7+
.cm-tooltip.cm-tooltip-hover {
8+
@apply bg-slate-200 px-1 py-0.5 text-xs;
9+
& .cm-tooltip-arrow:before {
10+
@apply bg-slate-700;
11+
}
12+
& .cm-tooltip-arrow:after {
13+
@apply bg-transparent;
14+
}
15+
}

src/lib/MMSProject.svelte.ts

Lines changed: 73 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Go, type FileTreeLike, type MmsSymbol } from '@minecraftmetascript/mms-
22
import MMSWasm from '@minecraftmetascript/mms-wasm/dist/main.wasm?init';
33
import * as deepslate from 'deepslate';
44
import * as zip from '@zip.js/zip.js';
5+
import { debounce } from 'es-toolkit';
6+
57
export class MMSFile {
68
private _content: string;
79
get content() {
@@ -21,11 +23,12 @@ export class MMSFile {
2123
this._diagnostics = $state([]);
2224
}
2325

26+
private goUpdate = debounce(updateFile, 100);
2427
async updateContent(content: string) {
2528
if (!content) return;
2629
this._content = content;
27-
updateFile(this.filename, content, (...args) => {
28-
this.project.onProjectUpdate(...args);
30+
this.goUpdate(this.filename, content, (result: Uint8Array) => {
31+
this.project.onProjectUpdate(atob(result.toBase64()));
2932
getFileDiag(this.filename, (serialDiag: string) => {
3033
if (serialDiag) this._diagnostics = JSON.parse(serialDiag);
3134
else this._diagnostics = [];
@@ -57,11 +60,67 @@ export class MMSProject {
5760
a.href = url;
5861
a.download = 'project.zip';
5962
a.click();
60-
URL.revokeObjectURL(url);
63+
// URL.revokeObjectURL(url);
6164
a.remove();
6265
}
6366

67+
private lspReaders = new Set<(s: string) => void>();
68+
lspSub(fn: (s: string) => void) {
69+
this.lspReaders.add(fn);
70+
}
71+
lspUnsub(fn: (s: string) => void) {
72+
this.lspReaders.delete(fn);
73+
}
74+
75+
partial: string | null = null;
76+
lspRead = (s: string | Uint8Array) => {
77+
let msgStr: string;
78+
// chop off the header
79+
if (s instanceof Uint8Array) {
80+
msgStr = atob(s.toBase64());
81+
} else {
82+
msgStr = s;
83+
}
84+
try {
85+
let message = msgStr.split('\r\n\r\n')[1];
86+
if (message === '' || message === undefined) {
87+
message = msgStr;
88+
}
89+
if (this.partial) {
90+
if (message) message = this.partial + message;
91+
else message = this.partial;
92+
}
93+
try {
94+
JSON.parse(message);
95+
console.log({ message: JSON.parse(message) });
96+
this.partial = '';
97+
this.lspReaders.forEach((r) => r(message));
98+
} catch (e) {
99+
if (message) {
100+
this.partial = message;
101+
} else console.warn(e);
102+
}
103+
} catch (e) {
104+
console.error(e);
105+
}
106+
};
107+
lspWrite(s: string) {
108+
const encoder = new TextEncoder();
109+
110+
const body = encoder.encode(s);
111+
const header = encoder.encode(`Content-Length: ${body.byteLength}\r\n\r\n`);
112+
113+
const packet = new Uint8Array(body.byteLength + header.byteLength);
114+
packet.set(header, 0);
115+
packet.set(body, header.byteLength);
116+
117+
// Send exact bytes
118+
// @ts-ignore allow Uint8Array until typings are updated
119+
globalThis.mmsLspWrite(packet);
120+
}
121+
64122
async init(signal?: AbortSignal) {
123+
globalThis.mmsLspRead = this.lspRead;
65124
const wasmInstance = await MMSWasm(this.goInstance.importObject);
66125
this.goInstance.run(wasmInstance).catch((err) => {
67126
console.error('MMS WASM Failed: ', { err });
@@ -91,18 +150,20 @@ export class MMSProject {
91150
get fs() {
92151
return this._fs;
93152
}
94-
private _symbols: Record<string, MmsSymbol> | null;
153+
private _symbols: Record<string, Record<string, MmsSymbol>> | null;
95154
get symbols() {
96155
return this._symbols;
97156
}
98-
private set symbols(next: Record<string, MmsSymbol> | null) {
99-
for (const [k, v] of Object.entries(next ?? {})) {
100-
switch (v.type) {
101-
case 'Noise': {
102-
deepslate.WorldgenRegistries.NOISE.register(
103-
new deepslate.Identifier(...(v.ref.split(':') as [string, string])),
104-
deepslate.NoiseParameters.fromJson(v.value)
105-
);
157+
private set symbols(next: Record<string, Record<string, MmsSymbol>> | null) {
158+
for (const [ns, v] of Object.entries(next ?? {})) {
159+
for (const [n, s] of Object.entries(v)) {
160+
switch (s.kind) {
161+
case 'Noise': {
162+
deepslate.WorldgenRegistries.NOISE.register(
163+
new deepslate.Identifier(ns, n),
164+
deepslate.NoiseParameters.fromJson(s.kind)
165+
);
166+
}
106167
}
107168
}
108169
}

src/lib/deepslate/DeepslateRendererOffloaded.svelte

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<script lang="ts" module>
2-
export const SupportedPreviewTypes = ['DensityFunction', 'Noise'];
2+
export const SupportedPreviewTypes = ['DensityFunction', 'Noise', 'NoiseSettings'];
33
</script>
44

55
<script lang="ts">
66
import type { MouseEventHandler } from 'svelte/elements';
7-
import DeepslateRenderWorker from './deepslate_render_worker?worker';
7+
import DeepslateRenderWorker from './worker/deepslate_render_worker?worker';
88
import type { Action } from 'svelte/action';
99
import {
1010
DeepslateRenderWorkerMessageSchema,
@@ -67,23 +67,25 @@
6767
send({
6868
kind: 'update::preview',
6969
value: JSON.stringify(editor.previewSymbol.value),
70-
type: editor.previewSymbol.type
70+
type: editor.previewSymbol.kind
7171
});
7272
}
7373
});
7474
7575
$effect(() => {
76-
for (const symbol of Object.values(editor.project.symbols ?? {})) {
77-
if (symbol.type === 'Noise') {
78-
const ref = symbol.ref.split(':');
79-
send({
80-
kind: 'injest::noise',
81-
ref: {
82-
namespace: ref[0],
83-
name: ref[1]
84-
},
85-
value: JSON.stringify(symbol.value)
86-
});
76+
for (const nsSymbols of Object.values(editor.project.symbols ?? {})) {
77+
for (const symbol of Object.values(nsSymbols)) {
78+
if (symbol.kind === 'Noise') {
79+
const ref = symbol.ref.split(':');
80+
send({
81+
kind: 'injest::noise',
82+
ref: {
83+
namespace: ref[0],
84+
name: ref[1]
85+
},
86+
value: JSON.stringify(symbol.value)
87+
});
88+
}
8789
}
8890
}
8991
});
@@ -127,7 +129,7 @@
127129
case 'response::value_at_point':
128130
mousePosLabel = {
129131
label: message.label,
130-
value: message.value.toFixed(2)
132+
value: typeof message.value === 'number' ? message.value.toFixed(2) : message.value
131133
};
132134
}
133135
});

src/lib/deepslate/proto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const RequestValueAtPoint = v.object({
4040
export const ResponseValueAtPoint = v.object({
4141
kind: v.literal('response::value_at_point'),
4242
point: PointSchema,
43-
value: v.number(),
43+
value: v.union([v.number(), v.string()]),
4444
label: v.string()
4545
});
4646

0 commit comments

Comments
 (0)