bc-minecraft-bedrock-project
Version:
The typescript library responsible for reading/parsing minecraft bedrock data
86 lines • 3.67 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Process = Process;
const Internal = __importStar(require("../../../internal/resource-pack/AnimationController"));
const bc_minecraft_molang_1 = require("bc-minecraft-molang");
const types_1 = require("../../../types");
const types_2 = require("../../../types");
const bc_minecraft_molang_2 = require("bc-minecraft-molang");
const bc_minecraft_bedrock_types_1 = require("bc-minecraft-bedrock-types");
const types_3 = require("../../../types");
/** */
function Process(doc) {
const imp = types_1.TextDocument.toObject(doc, Internal.AnimationControllers.is);
if (!imp)
return undefined;
const uri = doc.uri;
const content = doc.getText();
const out = [];
const container = imp.animation_controllers;
const keys = Object.getOwnPropertyNames(container);
for (let I = 0; I < keys.length; I++) {
const id = keys[I];
const controller = container[id];
if (Internal.AnimationController.is(controller)) {
const item = {
id: id,
location: bc_minecraft_bedrock_types_1.Types.Location.create(uri, content.indexOf(id)),
molang: bc_minecraft_molang_1.Molang.MolangSet.harvest(controller),
documentation: types_3.Documentation.getDoc(doc, () => `RP Animation Controller: '${id}'`),
animations: bc_minecraft_molang_2.Using.empty(),
particles: bc_minecraft_molang_2.Using.empty(),
sounds: bc_minecraft_molang_2.Using.empty(),
};
types_2.SMap.forEach(controller.states, (State) => {
if (State.animations)
bc_minecraft_bedrock_types_1.Types.Conditional.forEach(State.animations, (reference) => item.animations.using.push(reference));
if (State.particle_effects)
harvest(State.particle_effects, item.particles);
if (State.sound_effects)
harvest(State.sound_effects, item.sounds);
});
out.push(item);
}
}
return out;
}
function harvest(data, receiver) {
data.forEach((e) => {
if (e.effect)
receiver.using.push(e.effect);
});
}
//# sourceMappingURL=process.js.map