@drincs/pixi-vn
Version:
Pixi'VN is a npm package that provides various features for creating visual novels.
1 lines • 22.8 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/decorators/EventDecorator.ts","../../../src/functions/TextureUtility.ts","../../../src/classes/canvas/CanvasContainer.ts","../../../src/classes/canvas/CanvasText.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAQO,IAAM,mBAAsF,EAAC,CAAA;AA0B7F,SAAS,iBAA0D,OAAqC,EAAA;AAC3G,EAAI,IAAA;AACA,IAAI,IAAA,SAAA,GAAY,iBAAiB,OAAO,CAAA,CAAA;AACxC,IAAA,IAAI,CAAC,SAAW,EAAA;AACZ,MAAQ,OAAA,CAAA,KAAA,CAAM,CAAmB,gBAAA,EAAA,OAAO,CAAY,UAAA,CAAA,CAAA,CAAA;AACpD,MAAA,OAAA;AAAA,KACJ;AACA,IAAA,IAAI,SAAU,EAAA,CAAA;AACd,IAAO,OAAA,SAAA,CAAA;AAAA,WAEJ,CAAG,EAAA;AACN,IAAA,OAAA,CAAQ,KAAM,CAAA,CAAA,oCAAA,EAAuC,OAAO,CAAA,CAAA,EAAI,CAAC,CAAA,CAAA;AACjE,IAAA,OAAA;AAAA,GACJ;AACJ,CAAA;AAOO,SAAS,qBAAuD,OAAqC,EAAA;AACxG,EAAI,IAAA;AACA,IAAI,IAAA,SAAA,GAAY,iBAAiB,OAAO,CAAA,CAAA;AACxC,IAAA,IAAI,CAAC,SAAW,EAAA;AACZ,MAAQ,OAAA,CAAA,KAAA,CAAM,CAAmB,gBAAA,EAAA,OAAO,CAAY,UAAA,CAAA,CAAA,CAAA;AACpD,MAAA,OAAA;AAAA,KACJ;AACA,IAAI,IAAA,KAAA,GAAQ,IAAI,SAAU,EAAA,CAAA;AAC1B,IAAO,OAAA,KAAA,CAAA;AAAA,WAEJ,CAAG,EAAA;AACN,IAAA,OAAA,CAAQ,KAAM,CAAA,CAAA,oCAAA,EAAuC,OAAO,CAAA,CAAA,EAAI,CAAC,CAAA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A2B,EAAA;AAC1E,EAAA,kBAAA,CAAmB,SAAS,MAAM,CAAA,CAAA;AAClC,EAAA,IAAI,OAAO,MAAQ,EAAA;AACf,IAAI,IAAA,OAAO,MAAO,CAAA,MAAA,KAAW,QAAU,EAAA;AACnC,MAAA,OAAA,CAAQ,MAAO,CAAA,GAAA,CAAI,MAAO,CAAA,MAAA,EAAQ,OAAO,MAAM,CAAA,CAAA;AAAA,KAE9C,MAAA;AACD,MAAA,OAAA,CAAQ,OAAO,GAAI,CAAA,MAAA,CAAO,OAAO,CAAG,EAAA,MAAA,CAAO,OAAO,CAAC,CAAA,CAAA;AAAA,KACvD;AAAA,GACJ;AACA,EAAO,MAAA,CAAA,IAAA,KAAS,OAAQ,CAAA,IAAA,GAAO,MAAO,CAAA,IAAA,CAAA,CAAA;AACtC,EAAO,MAAA,CAAA,UAAA,KAAe,OAAQ,CAAA,UAAA,GAAa,MAAO,CAAA,UAAA,CAAA,CAAA;AAClD,EAAO,MAAA,CAAA,KAAA,KAAU,OAAQ,CAAA,KAAA,GAAQ,MAAO,CAAA,KAAA,CAAA,CAAA;AACxC,EAAO,MAAA,CAAA,WAAA,KAAgB,OAAQ,CAAA,WAAA,GAAc,MAAO,CAAA,WAAA,CAAA,CAAA;AACpD,EAAS,KAAA,IAAA,KAAA,IAAS,OAAO,QAAU,EAAA;AAC/B,IAAI,IAAA,EAAA,GAAK,MAAO,CAAA,QAAA,CAAS,KAAK,CAAA,CAAA;AAC9B,IAAI,IAAA,QAAA,GAAW,iBAAiB,EAAE,CAAA,CAAA;AAClC,IAAA,IAAI,QAAU,EAAA;AACV,MAAQ,OAAA,CAAA,OAAA,CAAQ,OAA+B,QAAQ,CAAA,CAAA;AAAA,KAC3D;AAAA,GACJ;AACJ","file":"CanvasText.mjs","sourcesContent":["import { CanvasEvent } from \"../classes\"\nimport CanvasBase from \"../classes/canvas/CanvasBase\"\nimport { CanvasEventNamesType } from \"../types\"\nimport { EventIdType } from \"../types/EventIdType\"\n\n/**\n * Canvas Event Register\n */\nexport const registeredEvents: { [name: EventIdType]: typeof CanvasEvent<CanvasEventNamesType> } = {}\n/**\n * Is a decorator that register a event in the game.\n * Is a required decorator for use the event in the game.\n * Thanks to this decoration the game has the possibility of updating the events to the latest modification and saving the game.\n * @param name is th identifier of the event, by default is the name of the class\n * @returns \n */\nexport default function eventDecorator(name?: EventIdType) {\n return function (target: typeof CanvasEvent<any>) {\n if (!name) {\n name = target.name\n }\n if (registeredEvents[name]) {\n console.info(`[Pixi'VN] Event ${name} already exists, it will be overwritten`)\n }\n target.prototype.id = name\n registeredEvents[name] = target\n }\n}\n\n/**\n * Get an event by the id.\n * @param eventId The id of the event.\n * @returns The event type.\n */\nexport function getEventTypeById<T = typeof CanvasEvent<CanvasBase<any>>>(eventId: EventIdType): T | undefined {\n try {\n let eventType = registeredEvents[eventId]\n if (!eventType) {\n console.error(`[Pixi'VN] Event ${eventId} not found`)\n return\n }\n new eventType()\n return eventType as T\n }\n catch (e) {\n console.error(`[Pixi'VN] Error while getting Event ${eventId}`, e)\n return\n }\n}\n\n/**\n * Get an event instance by the id.\n * @param eventId The id of the event.\n * @returns The event instance.\n */\nexport function getEventInstanceById<T = CanvasEvent<CanvasBase<any>>>(eventId: EventIdType): T | undefined {\n try {\n let eventType = registeredEvents[eventId]\n if (!eventType) {\n console.error(`[Pixi'VN] Event ${eventId} not found`)\n return\n }\n let event = new eventType()\n return event as T\n }\n catch (e) {\n console.error(`[Pixi'VN] Error while getting Event ${eventId}`, e)\n return\n }\n}\n","import { Assets, ColorSource, FillGradient, FillPattern, StrokeStyle, TextStyle, TextStyleOptions, Texture } from 'pixi.js';\n\n/**\n * Get a texture from a url.\n * @param imageUrl is the url of the image.\n * @returns the texture of the image, or a text with the error.\n */\nexport async function getTexture(imageUrl: string): Promise<Texture | void> {\n if (Assets.cache.has(imageUrl)) {\n return Assets.get(imageUrl)\n }\n return Assets.load(imageUrl)\n .then((texture) => {\n if (!texture) {\n console.error(\"[Pixi'VN] Texture not found\", imageUrl)\n return\n }\n // if texture not is a Texture, then it is a TextureResource\n if (!(texture instanceof Texture)) {\n console.error(\"[Pixi'VN] File not is a image\", imageUrl)\n return\n }\n\n return texture\n })\n .catch((e) => {\n console.error(\"[Pixi'VN] Error loading image\", e)\n return\n })\n}\n\nfunction getFillGradientFillPattern(prop: ColorSource | FillGradient | FillPattern | StrokeStyle, propName: keyof TextStyle) {\n if (!(prop instanceof Object)) {\n return prop\n }\n // TODO: FillGradient and FillPattern are not supported yet\n console.warn(`[Pixi'VN] CanvasText.style.${propName} is a FillGradient or FillPattern, this is not supported yet.`, prop)\n return undefined\n}\n\nexport function getTextStyle(style: TextStyle): TextStyleOptions {\n return {\n align: style.align,\n breakWords: style.breakWords,\n dropShadow: style.dropShadow,\n fill: getFillGradientFillPattern(style.stroke, \"fill\"),\n fontFamily: style.fontFamily,\n fontSize: style.fontSize,\n fontStyle: style.fontStyle,\n fontVariant: style.fontVariant,\n fontWeight: style.fontWeight,\n leading: style.leading,\n letterSpacing: style.letterSpacing,\n lineHeight: style.lineHeight,\n padding: style.padding,\n stroke: getFillGradientFillPattern(style.stroke, \"stroke\"),\n textBaseline: style.textBaseline,\n trim: style.trim,\n whiteSpace: style.whiteSpace,\n wordWrap: style.wordWrap,\n wordWrapWidth: style.wordWrapWidth,\n }\n}\n","import { Container, ContainerOptions } from \"pixi.js\";\nimport { exportCanvasElement, importCanvasElement } from \"../../functions/CanvasUtility\";\nimport ICanvasContainerMemory from \"../../interface/canvas/ICanvasContainerMemory\";\nimport CanvasBase from \"./CanvasBase\";\n\nexport const CANVAS_CONTAINER_ID = \"CanvasContainer\"\n\n/**\n * This class is a extension of the [PIXI.Container class](https://pixijs.com/8.x/examples/basic/container), it has the same properties and methods, \n * but it has the ability to be saved and loaded by the Pixi'VN library.\n * @example\n * ```typescript\n * const container = new CanvasContainer();\n * GameWindowManager.addCanvasElement(container);\n * const texture = await Assets.load('https://pixijs.com/assets/bunny.png');\n * for (let i = 0; i < 25; i++)\n * {\n * const bunny = new CanvasSprite(texture);\n * bunny.x = (i % 5) * 40;\n * bunny.y = Math.floor(i / 5) * 40;\n * container.addChild(bunny);\n * }\n * ```\n */\nexport default class CanvasContainer extends Container implements CanvasBase<ICanvasContainerMemory> {\n constructor(options?: ContainerOptions) {\n super(options)\n this.pixivnId = this.constructor.prototype.pixivnId || CANVAS_CONTAINER_ID\n }\n pixivnId: string = CANVAS_CONTAINER_ID\n get memory(): ICanvasContainerMemory {\n let memory = getMemoryContainer(this)\n this.children.forEach(child => {\n memory.elements.push(exportCanvasElement(child as CanvasBase<any>))\n })\n return memory\n }\n set memory(value: ICanvasContainerMemory) {\n setMemoryContainer(this, value)\n value.elements.forEach(child => {\n this.addChild(importCanvasElement(child))\n })\n }\n}\n\nexport function getMemoryContainer<T extends Container>(element: T): ICanvasContainerMemory {\n let className = \"CanvasContainer\"\n if (element.hasOwnProperty(\"pixivnId\")) {\n className = (element as any).pixivnId\n }\n return {\n pixivnId: className,\n elements: [],\n\n width: element.width,\n height: element.height,\n\n isRenderGroup: element.isRenderGroup,\n blendMode: element.blendMode,\n tint: element.tint,\n alpha: element.alpha,\n angle: element.angle,\n renderable: element.renderable,\n rotation: element.rotation,\n scale: { x: element.scale.x, y: element.scale.y },\n pivot: { x: element.pivot.x, y: element.pivot.y },\n position: { x: element.position.x, y: element.position.y },\n skew: { x: element.skew.x, y: element.skew.y },\n visible: element.visible,\n x: element.x,\n y: element.y,\n boundsArea: element.boundsArea,\n\n cursor: element.cursor,\n eventMode: element.eventMode,\n interactive: element.interactive,\n interactiveChildren: element.interactiveChildren,\n hitArea: element.hitArea\n }\n}\n\nexport function setMemoryContainer<T extends Container>(element: T | Container, memory: ContainerOptions) {\n memory.isRenderGroup && (element.isRenderGroup = memory.isRenderGroup)\n memory.blendMode && (element.blendMode = memory.blendMode)\n memory.tint && (element.tint = memory.tint)\n memory.alpha && (element.alpha = memory.alpha)\n memory.angle && (element.angle = memory.angle)\n memory.renderable && (element.renderable = memory.renderable)\n memory.rotation && (element.rotation = memory.rotation)\n if (memory.scale) {\n if (typeof memory.scale === \"number\") {\n element.scale.set(memory.scale, memory.scale)\n }\n else {\n element.scale.set(memory.scale.x, memory.scale.y)\n }\n }\n if (memory.pivot) {\n if (typeof memory.pivot === \"number\") {\n element.pivot.set(memory.pivot, memory.pivot)\n }\n else {\n element.pivot.set(memory.pivot.x, memory.pivot.y)\n }\n }\n memory.position && (element.position.set(memory.position.x, memory.position.y))\n memory.skew && (element.skew.set(memory.skew.x, memory.skew.y))\n memory.visible && (element.visible = memory.visible)\n memory.x && (element.x = memory.x)\n memory.y && (element.y = memory.y)\n memory.boundsArea && (element.boundsArea = memory.boundsArea)\n\n memory.cursor && (element.cursor = memory.cursor)\n memory.eventMode && (element.eventMode = memory.eventMode)\n memory.interactive && (element.interactive = memory.interactive)\n memory.interactiveChildren && (element.interactiveChildren = memory.interactiveChildren)\n memory.hitArea && (element.hitArea = memory.hitArea)\n\n // end\n // width and height must be set after the scale\n memory.width && (element.width = memory.width)\n memory.height && (element.height = memory.height)\n}\n","import { ContainerChild, ContainerEvents, EventEmitter, Text, TextOptions } from \"pixi.js\";\nimport { getEventInstanceById, getEventTypeById } from \"../../decorators/EventDecorator\";\nimport { getTextStyle } from \"../../functions/TextureUtility\";\nimport ICanvasTextMemory from \"../../interface/canvas/ICanvasTextTextMemory\";\nimport { CanvasEventNamesType } from \"../../types\";\nimport { EventIdType } from \"../../types/EventIdType\";\nimport CanvasEvent from \"../CanvasEvent\";\nimport CanvasBase from \"./CanvasBase\";\nimport { getMemoryContainer, setMemoryContainer } from \"./CanvasContainer\";\n\nexport const CANVAS_TEXT_ID = \"CanvasText\"\n\n/**\n * This class is a extension of the [PIXI.Text class](https://pixijs.com/8.x/examples/text/pixi-text), it has the same properties and methods,\n * but it has the ability to be saved and loaded by the Pixi'VN library.\n * @example\n * ```typescript\n * const text = new CanvasText();\n * text.text = \"Hello World\"\n * GameWindowManager.addCanvasElement(\"text\", text);\n * ```\n */\nexport default class CanvasText extends Text implements CanvasBase<ICanvasTextMemory> {\n constructor(options?: TextOptions) {\n super(options)\n this.pixivnId = this.constructor.prototype.pixivnId || CANVAS_TEXT_ID\n }\n pixivnId: string = CANVAS_TEXT_ID\n get memory(): ICanvasTextMemory {\n return getMemoryText(this)\n }\n set memory(value: ICanvasTextMemory) {\n setMemoryText(this, value)\n }\n private _onEvents: { [name: CanvasEventNamesType]: EventIdType } = {}\n get onEvents() {\n return this._onEvents\n }\n /**\n * is same function as on(), but it keeps in memory the children.\n * @param event The event type, e.g., 'click', 'mousedown', 'mouseup', 'pointerdown', etc.\n * @param eventClass The class that extends CanvasEvent.\n * @returns \n * @example\n * ```typescript\n * \\@eventDecorator()\n * export class EventTest extends CanvasEvent<CanvasText> {\n * override fn(event: CanvasEventNamesType, text: CanvasText): void {\n * if (event === 'pointerdown') {\n * text.scale.x *= 1.25;\n * text.scale.y *= 1.25;\n * }\n * }\n * }\n * ```\n * \n * ```typescript\n * const text = new CanvasText();\n * text.text = \"Hello World\"\n *\n * text.eventMode = 'static';\n * text.cursor = 'pointer';\n * text.onEvent('pointerdown', EventTest);\n *\n * GameWindowManager.addCanvasElement(\"text\", text);\n * ```\n */\n onEvent<T extends CanvasEventNamesType, T2 extends typeof CanvasEvent<typeof this>>(event: T, eventClass: T2) {\n let id = eventClass.prototype.id\n let instance = getEventInstanceById(id)\n this._onEvents[event] = id\n if (instance) {\n super.on(event, () => {\n (instance as CanvasEvent<CanvasBase<any>>).fn(event, this)\n })\n }\n return this\n }\n /**\n * on() does not keep in memory the event class, use onEvent() instead\n * @deprecated\n * @private\n * @param event \n * @param fn \n * @param context \n */\n override on<T extends keyof ContainerEvents<ContainerChild> | keyof { [K: symbol]: any;[K: {} & string]: any; }>(event: T, fn: (...args: EventEmitter.ArgumentMap<ContainerEvents<ContainerChild> & { [K: symbol]: any;[K: {} & string]: any; }>[Extract<T, keyof ContainerEvents<ContainerChild> | keyof { [K: symbol]: any;[K: {} & string]: any; }>]) => void, context?: any): this {\n return super.on(event, fn, context)\n }\n}\n\nexport function getMemoryText<T extends CanvasText>(element: T | CanvasText): ICanvasTextMemory {\n let temp = getMemoryContainer(element)\n return {\n ...temp,\n pixivnId: element.pixivnId,\n anchor: { x: element.anchor.x, y: element.anchor.y },\n text: element.text,\n resolution: element.resolution,\n style: getTextStyle(element.style),\n roundPixels: element.roundPixels,\n onEvents: element.onEvents,\n }\n}\n\nexport function setMemoryText(element: CanvasText, memory: ICanvasTextMemory) {\n setMemoryContainer(element, memory)\n if (memory.anchor) {\n if (typeof memory.anchor === \"number\") {\n element.anchor.set(memory.anchor, memory.anchor)\n }\n else {\n element.anchor.set(memory.anchor.x, memory.anchor.y)\n }\n }\n memory.text && (element.text = memory.text)\n memory.resolution && (element.resolution = memory.resolution)\n memory.style && (element.style = memory.style)\n memory.roundPixels && (element.roundPixels = memory.roundPixels)\n for (let event in memory.onEvents) {\n let id = memory.onEvents[event]\n let instance = getEventTypeById(id)\n if (instance) {\n element.onEvent(event as CanvasEventNamesType, instance)\n }\n }\n}\n"]}