Files
Construct-CN/packs/BP/scripts/classes/Render/model/BlockModelKeyResolver.js
T
wed150 136d5ffa3b
/ build (push) Has been cancelled
Start working at 1.2.0
2026-08-26 09:54:39 +08:00

37 lines
1.3 KiB
JavaScript

import { blockKeySpecs, blockModels } from "../../../blockModels";
export class BlockModelKeyResolver {
lookupFaceRefs(blockId, states) {
const keySpec = blockKeySpecs[blockId];
if (keySpec === void 0)
return void 0;
for (let shapeIndex = 0; shapeIndex < keySpec.props.length; shapeIndex++) {
const key = this.buildStateKey(blockId, keySpec.props[shapeIndex], shapeIndex, states);
if (key === void 0)
continue;
const faceReferences = blockModels[key];
if (faceReferences !== void 0)
return faceReferences;
}
return void 0;
}
faceRefsForKey(key) {
return blockModels[key];
}
buildStateKey(blockId, shapeProperties, shapeIndex, states) {
let key = `${blockId}[${shapeIndex}|`;
for (let propertyIndex = 0; propertyIndex < shapeProperties.length; propertyIndex++) {
const propertyName = shapeProperties[propertyIndex];
const value = states[propertyName];
if (value === void 0)
return void 0;
if (propertyIndex > 0)
key += ",";
key += typeof value === "boolean" ? (value ? 1 : 0) : value;
}
return `${key}]`;
}
}