@drincs/pixi-vn
Version:
Pixi'VN is a npm package that provides various features for creating visual novels.
80 lines (77 loc) • 2.35 kB
JavaScript
var pixi_js = require('pixi.js');
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 getTexture(imageUrl) {
return __async(this, null, function* () {
if (pixi_js.Assets.cache.has(imageUrl)) {
return pixi_js.Assets.get(imageUrl);
}
return pixi_js.Assets.load(imageUrl).then((texture) => {
if (!texture) {
console.error("[Pixi'VN] Texture not found", imageUrl);
return;
}
if (!(texture instanceof pixi_js.Texture)) {
console.error("[Pixi'VN] File not is a image", imageUrl);
return;
}
return texture;
}).catch((e) => {
console.error("[Pixi'VN] Error loading image", e);
return;
});
});
}
function getFillGradientFillPattern(prop, propName) {
if (!(prop instanceof Object)) {
return prop;
}
console.warn(`[Pixi'VN] CanvasText.style.${propName} is a FillGradient or FillPattern, this is not supported yet.`, prop);
return void 0;
}
function getTextStyle(style) {
return {
align: style.align,
breakWords: style.breakWords,
dropShadow: style.dropShadow,
fill: getFillGradientFillPattern(style.stroke, "fill"),
fontFamily: style.fontFamily,
fontSize: style.fontSize,
fontStyle: style.fontStyle,
fontVariant: style.fontVariant,
fontWeight: style.fontWeight,
leading: style.leading,
letterSpacing: style.letterSpacing,
lineHeight: style.lineHeight,
padding: style.padding,
stroke: getFillGradientFillPattern(style.stroke, "stroke"),
textBaseline: style.textBaseline,
trim: style.trim,
whiteSpace: style.whiteSpace,
wordWrap: style.wordWrap,
wordWrapWidth: style.wordWrapWidth
};
}
exports.getTextStyle = getTextStyle;
exports.getTexture = getTexture;
//# sourceMappingURL=TextureUtility.js.map
//# sourceMappingURL=TextureUtility.js.map
;