Basin
This commit is contained in:
+21
-2
@@ -50,7 +50,8 @@ export async function setup(config: Record<string, unknown> = {}) {
|
||||
}
|
||||
|
||||
// create's client script with only what its visuals need, and a block for one to draw that records what its instances
|
||||
// do, by model ("own" for the block's own model): how rotating ones turn, and where transformed ones are moved
|
||||
// do, by model ("own" for the block's own model): how rotating ones turn, and where transformed ones are moved. and the
|
||||
// items and fluid boxes it draws now, by item and fluid id
|
||||
export async function visual_for(
|
||||
id: string,
|
||||
states: Record<string, number>,
|
||||
@@ -69,6 +70,8 @@ export async function visual_for(
|
||||
const key = (model?: ModelRef) => model === undefined ? "own" : JSON.stringify(model);
|
||||
const turns = new Map<string, [string, number, number]>();
|
||||
const transforms = new Map<string, number[]>();
|
||||
const items = new Set<{ id: string; transform?: number[] }>();
|
||||
const fluids = new Set<{ id: string; box?: [number[], number[]] }>();
|
||||
const instances = {
|
||||
rotating: (model?: ModelRef) => ({
|
||||
set_rotation: (axis: string, rpm: number, offset = 0) => turns.set(key(model), [axis, rpm, offset]),
|
||||
@@ -78,8 +81,24 @@ export async function visual_for(
|
||||
set_transform: (matrix: ArrayLike<number>) => transforms.set(key(model), Array.from(matrix)),
|
||||
delete() {},
|
||||
}),
|
||||
item: (stack: { id: string }) => {
|
||||
const item: { id: string; transform?: number[] } = { id: stack.id };
|
||||
items.add(item);
|
||||
return {
|
||||
set_transform: (matrix: ArrayLike<number>) => item.transform = Array.from(matrix),
|
||||
delete: () => items.delete(item),
|
||||
};
|
||||
},
|
||||
fluid: (fluid: { id: string }) => {
|
||||
const box: { id: string; box?: [number[], number[]] } = { id: fluid.id };
|
||||
fluids.add(box);
|
||||
return {
|
||||
set_box: (from: number[], to: number[]) => box.box = [from, to],
|
||||
delete: () => fluids.delete(box),
|
||||
};
|
||||
},
|
||||
} as unknown as Instances;
|
||||
const block = { id, x, y, z, states, get_client_data: (field: string) => structuredClone(data[field]) as never };
|
||||
const visual = visuals.get(id)!(block, instances);
|
||||
return { visual, turns, transforms, data };
|
||||
return { visual, turns, transforms, items, fluids, data };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user