idk
This commit is contained in:
parent
6a5addb383
commit
ac3802e8fb
11 changed files with 1542 additions and 59 deletions
|
|
@ -25,8 +25,9 @@
|
|||
"test": "bun test/app.ts",
|
||||
"test:watch": "bun --watch test/app.ts",
|
||||
"prefetch": "bun scripts/prefetch",
|
||||
"gen:enums": "bun scripts/write/enum",
|
||||
"vanilla:defs": "bun scripts/vanilladefs",
|
||||
"gen:enums": "bun scripts/enum",
|
||||
"gen:items": "bun scripts/items",
|
||||
"gen:autocomplete": "bun scripts/autocomplete-build"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { PFFS } from "../components"
|
||||
import { PFFS } from "./components"
|
||||
import fs from "fs/promises"
|
||||
import "../custom"
|
||||
import "./custom"
|
||||
|
||||
const schema = PFFS.readFileJSON("ui.schema.json").definitions
|
||||
|
||||
29
scripts/items.ts
Normal file
29
scripts/items.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import fs from "fs"
|
||||
|
||||
interface Item {
|
||||
id: number
|
||||
id_aux: number
|
||||
name: string
|
||||
}
|
||||
|
||||
interface ItemAPI {
|
||||
version: string
|
||||
length: number
|
||||
items: Item[]
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const itemlist: string[] = ["export enum ItemAuxID {"]
|
||||
|
||||
const { items }: ItemAPI = await fetch("https://www.asakiyuki.com/api/minecraft/items/id").then(v => v.json())
|
||||
for (const { name: fullname, id, id_aux } of items) {
|
||||
const [namespace, name] = fullname.split(":")
|
||||
const enumName = name.toUpperCase()
|
||||
itemlist.push(` ${enumName} = ${id_aux},`)
|
||||
}
|
||||
|
||||
itemlist.push("}")
|
||||
fs.writeFileSync("src/types/enums/Items.ts", itemlist.join("\n"))
|
||||
}
|
||||
|
||||
main()
|
||||
|
|
@ -1,41 +1,3 @@
|
|||
import { UI } from "../components/UI.js"
|
||||
import { Renderer } from "../types/enums/Renderer.js"
|
||||
import { Type } from "../types/enums/Type.js"
|
||||
import { Class } from "../components/Class.js"
|
||||
|
||||
export const Memory = {
|
||||
cache: new Map<string, { namespace: string; elements: Map<string, UI<Type, Renderer | null>> }>(),
|
||||
|
||||
register_ui(path: string, element: UI<Type, Renderer | null>) {
|
||||
const { elements: saver, namespace } = this.get_file(path, element.namespace!)
|
||||
|
||||
if (saver.get(element.name!)) {
|
||||
console.error(`Element ${element.name} already exists in ${path}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
saver.set(element.name!, element)
|
||||
return namespace
|
||||
},
|
||||
|
||||
gen_ui_file_contents(namespace: string, elements: Map<string, UI<Type, Renderer | null>>) {
|
||||
return JSON.stringify(
|
||||
{
|
||||
namespace,
|
||||
...elements.toJSON(),
|
||||
},
|
||||
null,
|
||||
4
|
||||
)
|
||||
},
|
||||
|
||||
get_file(path: string, namespace: string) {
|
||||
let cached = this.cache.get(path)
|
||||
|
||||
if (!cached) {
|
||||
cached = { namespace, elements: new Map<string, UI<Type, Renderer | null>>() }
|
||||
this.cache.set(path, cached)
|
||||
}
|
||||
|
||||
return cached
|
||||
},
|
||||
}
|
||||
export class Memory extends Class {}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
import { Memory } from "./Memory.js"
|
||||
|
||||
process.on("beforeExit", () => {
|
||||
Memory.cache.forEach(({ elements, namespace }) => {
|
||||
const contents = Memory.gen_ui_file_contents(namespace, elements)
|
||||
})
|
||||
})
|
||||
process.on("beforeExit", () => {})
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import { Memory } from "../compilers/Memory.js"
|
|||
import { Renderer } from "../types/enums/Renderer.js"
|
||||
import { Type } from "../types/enums/Type.js"
|
||||
import { Properties } from "../types/properties/components.js"
|
||||
import { Namespace, VanillaType } from "../types/vanilla/intellisense.js"
|
||||
import { Class } from "./Class.js"
|
||||
import { RandomString } from "./Utils.js"
|
||||
|
||||
|
|
@ -16,7 +15,7 @@ export class UI<T extends Type, K extends Renderer | null = null> extends Class
|
|||
namespace: string
|
||||
extend?: UI<Type, Renderer | null>
|
||||
|
||||
canExtend: boolean
|
||||
extendable: boolean
|
||||
|
||||
controls = new Map<string, [UI<Type, Renderer | null>, Properties<Type, Renderer | null>]>()
|
||||
properties: Properties<T, K> = <any>{}
|
||||
|
|
@ -40,9 +39,7 @@ export class UI<T extends Type, K extends Renderer | null = null> extends Class
|
|||
if (!path) this.path = `@/${this.namespace}`
|
||||
else this.path = path
|
||||
|
||||
this.canExtend = this.name.search("/") === -1
|
||||
|
||||
Memory.register_ui(this.path, this)
|
||||
this.extendable = this.name.search("/") === -1
|
||||
}
|
||||
|
||||
setProperties(properties: Properties<T, K>) {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import {
|
|||
Slider,
|
||||
SliderBox,
|
||||
} from "../types/properties/components.js"
|
||||
import { ItemAuxID } from "../types/enums/Items.js"
|
||||
|
||||
const CHARS = "0123456789abcdefghijklmnopqrstuvwxyz"
|
||||
|
||||
|
|
@ -79,6 +80,11 @@ export function RandomBindingString(length: number, base: number = 32): Binding
|
|||
return `#${RandomString(length, base)}`
|
||||
}
|
||||
|
||||
export function GetItemByAuxID(auxID: number) {
|
||||
const item = ItemAuxID[auxID]
|
||||
if (item) return `minecraft:${item.toLowerCase()}`
|
||||
}
|
||||
|
||||
// Quick Elements
|
||||
export function Panel(properties?: Panel, name?: string, namespace?: string) {
|
||||
return new UI(Type.PANEL, name, namespace).setProperties(properties || {})
|
||||
|
|
@ -167,13 +173,13 @@ export function SliderBox(properties?: SliderBox, name?: string, namespace?: str
|
|||
return new UI(Type.SLIDER_BOX, name, namespace).setProperties(properties || {})
|
||||
}
|
||||
|
||||
export function Extends<T extends Type, K extends Renderer | null>(
|
||||
export function ExtendsOf<T extends Type, K extends Renderer | null>(
|
||||
element: UI<T, K>,
|
||||
properties?: Properties<T, K>,
|
||||
name?: string,
|
||||
namespace?: string,
|
||||
) {
|
||||
if (!element.canExtend) {
|
||||
if (!element.extendable) {
|
||||
throw new Error("Cannot extend a UI that cannot be extended")
|
||||
}
|
||||
const ui = new UI<T, K>(undefined, name, namespace)
|
||||
|
|
|
|||
|
|
@ -7,5 +7,6 @@ export * from "./components/Modify.js"
|
|||
export * from "./components/Utils.js"
|
||||
|
||||
export * from "./types/enums/index.js"
|
||||
export * from "./compilers/bindings/index.js"
|
||||
export * as Properties from "./types/properties/index.js"
|
||||
|
||||
export { ItemAuxID } from "./types/enums/Items.js"
|
||||
|
|
|
|||
1488
src/types/enums/Items.ts
Normal file
1488
src/types/enums/Items.ts
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -2,6 +2,7 @@ import { Value } from "../value.js"
|
|||
|
||||
export interface Image {
|
||||
texture_path?: Value<string>
|
||||
texture?: Value<string>
|
||||
}
|
||||
|
||||
export interface Cycler {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
import { Extends, GlobalVariables, Modify } from ".."
|
||||
import { Anchor, Modify, Properties } from ".."
|
||||
|
||||
const vanilla = Modify("anvil_pocket", "slots_panel").setProperties({
|
||||
const vanilla = Modify("authentication_modals", "ad_modal_dialog").setProperties({
|
||||
ignored: true,
|
||||
anchor: Anchor.CENTER,
|
||||
offset: [10, 10],
|
||||
})
|
||||
|
||||
console.log(vanilla.path)
|
||||
console.log(vanilla)
|
||||
|
|
|
|||
Reference in a new issue