@drincs/pixi-vn
Version:
Pixi'VN is a npm package that provides various features for creating visual novels.
133 lines (126 loc) • 3.65 kB
JavaScript
Object.defineProperty(exports, '__esModule', { value: true });
require('crypto-js/sha1');
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
function checkIfStepsIsEqual(step1, step2) {
return step1 === step2;
}
// src/classes/LabelAbstract.ts
var LabelAbstract = class {
/**
* @param id is the id of the label
* @param props is the properties of the label
*/
constructor(id, props) {
this._id = id;
this._onStepStart = props == null ? void 0 : props.onStepStart;
this._onLoadStep = props == null ? void 0 : props.onLoadStep;
this._onStepEnd = props == null ? void 0 : props.onStepEnd;
this._choiseIndex = props == null ? void 0 : props.choiseIndex;
}
/**
* Get the id of the label. This variable is used in the system to get the label by id, {@link getLabelById}
*/
get id() {
return this._id;
}
/**
* Get the corresponding steps number
* @param externalSteps
* @returns Numer of corresponding steps, for example, if externalSteps is [ABC, DEF, GHI] and the steps of the label is [ABC, GHT], the result will be 1
*/
getCorrespondingStepsNumber(externalSteps) {
if (externalSteps.length === 0) {
return 0;
}
let res = 0;
externalSteps.forEach((step, index) => {
if (checkIfStepsIsEqual(step, this.steps[index])) {
res = index;
}
});
return res;
}
/**
* Is a function that will be executed in {@link Label#onStepStart} and when the user goes back to it or when the user laods a save file.
* @returns Promise<void> or void
*/
get onStepStart() {
return (stepIndex, label) => __async(this, null, function* () {
if (this._onLoadStep) {
yield this._onLoadStep(stepIndex, label);
}
if (this._onStepStart) {
return yield this._onStepStart(stepIndex, label);
}
});
}
/**
* Get the function that will be executed a old step is reloaded. A step is reloaded when the user goes back to it or when the user laods a save file.
* @returns Promise<void> or void
*/
get onLoadStep() {
return this._onLoadStep;
}
/**
* Is a function that will be executed when the step ends.
* @returns Promise<void> or void
*/
get onStepEnd() {
return this._onStepEnd;
}
get choiseIndex() {
return this._choiseIndex;
}
};
// src/classes/Label.ts
var Label = class extends LabelAbstract {
/**
* @param id is the id of the label
* @param steps is the list of steps that the label will perform
* @param props is the properties of the label
*/
constructor(id, steps, props) {
super(id, props);
this._steps = steps;
}
/**
* Get the steps of the label.
*/
get steps() {
if (typeof this._steps === "function") {
return this._steps();
}
return this._steps;
}
};
// src/classes/CloseLabel.ts
var CLOSE_LABEL_ID = "__close-label-id__";
function newCloseLabel(choiseIndex) {
return new Label(CLOSE_LABEL_ID, [], {
choiseIndex
});
}
exports.CLOSE_LABEL_ID = CLOSE_LABEL_ID;
exports.default = newCloseLabel;
//# sourceMappingURL=CloseLabel.js.map
//# sourceMappingURL=CloseLabel.js.map
;