From 3158c3cec804054175fe189f486d1789f2631914 Mon Sep 17 00:00:00 2001 From: Asaki Yuki Date: Wed, 28 Jan 2026 11:37:43 +0700 Subject: [PATCH] idk --- src/compilers/ui/builder.ts | 11 ++++++----- src/compilers/ui/linker.ts | 23 ++++++++++++++++------- src/compilers/ui/manifest.ts | 4 +++- src/components/AnimationKeyframe.ts | 2 +- src/components/UI.ts | 16 +++++++++------- 5 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/compilers/ui/builder.ts b/src/compilers/ui/builder.ts index efde52f..a456da9 100644 --- a/src/compilers/ui/builder.ts +++ b/src/compilers/ui/builder.ts @@ -2,16 +2,16 @@ import { isBuildMode } from "../Configuration.js" import { Memory } from "../Memory.js" import { createBuildFolder } from "./linker.js" import fs from "fs/promises" +import { genManifest } from "./manifest.js" async function buildUI() { const build = Memory.build() - let i = 0 - build.set("ui/ui_defs.json", { + build.set("ui/_ui_defs.json", { ui_defs: Array.from(build.keys()), }) - await Promise.all( + const out = await Promise.all( build.entries().map(async ([file, value]) => { const outFile = `build/build/${file}` await fs @@ -20,11 +20,12 @@ async function buildUI() { await fs.writeFile(outFile, JSON.stringify(value), "utf-8") build.delete(file) - i++ }), ) - return i - 1 + await fs.writeFile("build/build/manifest.json", await genManifest(), "utf-8") + + return out.length } if (isBuildMode) { diff --git a/src/compilers/ui/linker.ts b/src/compilers/ui/linker.ts index abf8692..1da09d8 100644 --- a/src/compilers/ui/linker.ts +++ b/src/compilers/ui/linker.ts @@ -2,14 +2,23 @@ import fs from "fs/promises" import { BuildCache } from "./buildcache.js" import { RandomString } from "../../components/Utils.js" -const HEX: string[] = Array.from({ length: 256 }, (_, i) => i.toString(16).toUpperCase().padStart(2, "0")) -function genUUID() { +const HEX: string[] = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0")) + +function genUUID(): string { const b = Array.from({ length: 16 }, () => Math.floor(Math.random() * 256)) - return `${HEX[b[0]]}${HEX[b[1]]}${HEX[b[2]]}${HEX[b[3]]}-${HEX[b[4]]}${HEX[b[5]]}-${ - HEX[b[6]] - }${HEX[b[7]]}-${HEX[b[8]]}${HEX[b[9]]}-${HEX[b[10]]}${HEX[b[11]]}${HEX[b[12]]}${ - HEX[b[13]] - }${HEX[b[14]]}${HEX[b[15]]}` + + // version 4 + b[6] = (b[6] & 0x0f) | 0x40 + // variant 10xx + b[8] = (b[8] & 0x3f) | 0x80 + + return ( + `${HEX[b[0]]}${HEX[b[1]]}${HEX[b[2]]}${HEX[b[3]]}-` + + `${HEX[b[4]]}${HEX[b[5]]}-` + + `${HEX[b[6]]}${HEX[b[7]]}-` + + `${HEX[b[8]]}${HEX[b[9]]}-` + + `${HEX[b[10]]}${HEX[b[11]]}${HEX[b[12]]}${HEX[b[13]]}${HEX[b[14]]}${HEX[b[15]]}` + ) } export async function clearBuild() { diff --git a/src/compilers/ui/manifest.ts b/src/compilers/ui/manifest.ts index 69a57e4..67442f5 100644 --- a/src/compilers/ui/manifest.ts +++ b/src/compilers/ui/manifest.ts @@ -6,12 +6,14 @@ export async function genManifest() { format_version: 2, header: { name: "AsaJS UI", - uuid: uuid1, description: "A framework for creating UIs for AsaJS.", + uuid: uuid1, version: [4, 0, 0], + min_engine_version: [1, 21, 132], }, modules: [ { + description: "This resource pack generate by AsaJS.", type: "resources", uuid: uuid2, version: [4, 0, 0], diff --git a/src/components/AnimationKeyframe.ts b/src/components/AnimationKeyframe.ts index 5613a8e..c33ee0e 100644 --- a/src/components/AnimationKeyframe.ts +++ b/src/components/AnimationKeyframe.ts @@ -37,7 +37,7 @@ export class AnimationKeyframe extends Class { this.name = name || RandomString(16) this.namespace = namespace || RandomNamespace() - this.path = path || `@/${this.namespace}` + this.path = path || `@/${this.namespace}.json` Memory.add(this) } diff --git a/src/components/UI.ts b/src/components/UI.ts index 6d70e70..e1d3dde 100644 --- a/src/components/UI.ts +++ b/src/components/UI.ts @@ -53,7 +53,7 @@ export class UI extends Class this.name = name?.match(/^(\w|\/)+/)?.[0] || RandomString(16) this.namespace = namespace || RandomNamespace() - if (!path) this.path = `@/${this.namespace}` + if (!path) this.path = `@/${this.namespace}.json` else this.path = path this.extendable = this.name.search("/") === -1 @@ -247,9 +247,11 @@ export class ModifyUI ex return this.addModifications({ array_name: ArrayName.CONTROLS, operation: Operation.INSERT_FRONT, - value: { - [`${name}${child}`]: properties || {}, - }, + value: [ + { + [`${name}${child}`]: properties || {}, + }, + ], }) } @@ -292,7 +294,7 @@ export class ModifyUI ex } insertChild(child: UI, properties?: Properties) { - return this.insertBackChild(child, properties) + return this.insertFrontChild(child, properties) } replaceChild(where: S, child: UI, properties?: Properties) { @@ -334,7 +336,7 @@ export class ModifyUI ex } insertBindings(...bindings: BindingItem[]) { - return this.insertBackBindings(...bindings) + return this.insertFrontBindings(...bindings) } /** @@ -366,7 +368,7 @@ export class ModifyUI ex } insertButtonMappings(...buttonMappings: ButtonMapping[]) { - return this.insertBackButtonMappings(...buttonMappings) + return this.insertFrontButtonMappings(...buttonMappings) } /**