bard-legends-framework 0.10.3 → 0.10.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,11 @@
1
+ import { Variable } from 'actions-lib';
1
2
  import { Attachable } from '../base/attachable';
2
3
  export type SceneClassType = new (...services: any[]) => Scene<any>;
3
4
  export declare function SceneDecorator(): (SceneClass: SceneClassType) => any;
4
5
  export declare abstract class Scene<InputType> extends Attachable {
5
6
  private static sceneInstance?;
6
7
  private static sceneTransitioning;
7
- static get activeScene(): Scene<any> | undefined;
8
+ static activeScene: Variable<Scene<any> | undefined>;
8
9
  static getActiveSceneOrFail(): Scene<any>;
9
10
  static isActive<T extends Scene<any>>(this: new (...args: any[]) => T): boolean;
10
11
  static getInstance<T extends Scene<any>>(this: new (...args: any[]) => T): T | undefined;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Scene = exports.SceneDecorator = void 0;
4
+ const actions_lib_1 = require("actions-lib");
4
5
  const attachable_1 = require("../base/attachable");
5
6
  const service_1 = require("../service/service");
6
7
  const update_cycle_1 = require("../update-cycle");
@@ -16,9 +17,7 @@ function SceneDecorator() {
16
17
  exports.SceneDecorator = SceneDecorator;
17
18
  class Scene extends attachable_1.Attachable {
18
19
  static { this.sceneTransitioning = false; }
19
- static get activeScene() {
20
- return Scene.sceneInstance;
21
- }
20
+ static { this.activeScene = new actions_lib_1.Variable(); }
22
21
  static getActiveSceneOrFail() {
23
22
  if (!Scene.sceneInstance) {
24
23
  throw new Error(`Scene: getActiveSceneOrFail is called when there is no active scene!`);
@@ -47,10 +46,12 @@ class Scene extends attachable_1.Attachable {
47
46
  await Scene.sceneInstance.prepareToClose();
48
47
  Scene.sceneInstance.destroy();
49
48
  Scene.sceneInstance = undefined;
49
+ Scene.activeScene.set(undefined);
50
50
  }
51
51
  let resolvedArgs = service_1.Service.resolveParameters([], this.$meta.paramtypes);
52
52
  let scene = new this(...resolvedArgs);
53
53
  Scene.sceneInstance = scene;
54
+ Scene.activeScene.set(scene);
54
55
  await scene.init(input);
55
56
  Scene.sceneTransitioning = false;
56
57
  }
@@ -60,6 +61,7 @@ class Scene extends attachable_1.Attachable {
60
61
  await Scene.sceneInstance.prepareToClose();
61
62
  Scene.sceneInstance.destroy();
62
63
  Scene.sceneInstance = undefined;
64
+ Scene.activeScene.set(undefined);
63
65
  }
64
66
  }
65
67
  constructor() {
@@ -53,8 +53,8 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
53
53
  (0, scene_1.SceneDecorator)()
54
54
  ], SampleScene);
55
55
  SampleScene.open(undefined);
56
- (0, vitest_1.expect)(scene_1.Scene.activeScene).toBeDefined();
57
- (0, vitest_1.expect)(scene_1.Scene.activeScene).toBeInstanceOf(SampleScene);
56
+ (0, vitest_1.expect)(scene_1.Scene.activeScene.value).toBeDefined();
57
+ (0, vitest_1.expect)(scene_1.Scene.activeScene.value).toBeInstanceOf(SampleScene);
58
58
  });
59
59
  (0, vitest_1.test)('arguments in open call should be passed to the init function', () => {
60
60
  let SampleScene = class SampleScene extends scene_1.Scene {
@@ -114,7 +114,7 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
114
114
  (0, vitest_1.expect)(SampleScene1.destroyCalled).toBeFalsy();
115
115
  SampleScene2.open(undefined);
116
116
  await update_cycle_1.UpdateCycle.triggerUpdateTick(1); // Update cycle should take place to destroy functions to be called
117
- (0, vitest_1.expect)(scene_1.Scene.activeScene).toBeInstanceOf(SampleScene2);
117
+ (0, vitest_1.expect)(scene_1.Scene.activeScene.value).toBeInstanceOf(SampleScene2);
118
118
  (0, vitest_1.expect)(SampleScene1.destroyCalled).toBeTruthy();
119
119
  });
120
120
  (0, vitest_1.test)('get instance should return the scene with its type', () => {
@@ -15,11 +15,15 @@ export interface TextOptions {
15
15
  readonly fontStyle: 'normal' | 'italic' | 'oblique';
16
16
  readonly lineHeight: number | undefined;
17
17
  readonly dropShadow: DropShadowOptions | undefined;
18
- readonly wordWrapWidth?: number;
18
+ readonly wordWrapWidth: number | undefined;
19
+ readonly lineThrough: boolean;
19
20
  }
20
21
  export type PartialTextOptions = Partial<Omit<TextOptions, 'dropShadow'>> & {
21
22
  dropShadow?: Partial<DropShadowOptions> | true;
22
23
  };
23
- export declare class PixiTextStyleConverter {
24
- static getPixiTextStyle(partialOptions?: PartialTextOptions): Partial<PIXI.ITextStyle>;
24
+ export interface ExtendedPixiTextStyle extends Partial<PIXI.ITextStyle> {
25
+ readonly lineThrough: boolean;
26
+ }
27
+ export declare class TextStyleConverter {
28
+ static getPixiTextStyle(partialOptions?: PartialTextOptions): ExtendedPixiTextStyle;
25
29
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PixiTextStyleConverter = void 0;
3
+ exports.TextStyleConverter = void 0;
4
4
  const helpers_lib_1 = require("helpers-lib");
5
- class PixiTextStyleConverter {
5
+ class TextStyleConverter {
6
6
  static getPixiTextStyle(partialOptions) {
7
7
  let options = {
8
8
  color: helpers_lib_1.ColorHelper.white,
@@ -11,6 +11,8 @@ class PixiTextStyleConverter {
11
11
  fontStyle: 'normal',
12
12
  fontSize: 18,
13
13
  lineHeight: undefined,
14
+ wordWrapWidth: undefined,
15
+ lineThrough: false,
14
16
  ...partialOptions
15
17
  };
16
18
  let partialDropShadowOptions = partialOptions?.dropShadow === true ? {} : partialOptions?.dropShadow;
@@ -42,9 +44,10 @@ class PixiTextStyleConverter {
42
44
  lineHeight: options.lineHeight,
43
45
  wordWrapWidth: options.wordWrapWidth,
44
46
  wordWrap: options.wordWrapWidth !== undefined,
47
+ lineThrough: options.lineThrough,
45
48
  ...shadowOptions
46
49
  };
47
50
  }
48
51
  }
49
- exports.PixiTextStyleConverter = PixiTextStyleConverter;
52
+ exports.TextStyleConverter = TextStyleConverter;
50
53
  //# sourceMappingURL=pixi-text-style-converter.js.map
@@ -1,12 +1,11 @@
1
- import * as PIXI from 'pixi.js';
2
1
  import { RichTextOptions } from '../../../rich-text';
3
2
  import { ChunkData } from '../../rich-text-to-plane-text';
4
- import { PartialTextOptions } from './pixi-text-style-converter';
3
+ import { ExtendedPixiTextStyle, PartialTextOptions } from './pixi-text-style-converter';
5
4
  export interface TagsWithStyles {
6
5
  readonly text: string;
7
6
  readonly cacheKey: string;
8
7
  readonly style: PartialTextOptions;
9
- readonly pixiStyle: PIXI.TextStyle;
8
+ readonly pixiStyle: ExtendedPixiTextStyle;
10
9
  readonly spaceWidth: number;
11
10
  }
12
11
  export declare class RichTextDataInConverter {
@@ -43,14 +43,14 @@ class RichTextDataInConverter {
43
43
  if (pixiStyleCache.has(cacheKey)) {
44
44
  return pixiStyleCache.get(cacheKey);
45
45
  }
46
- let pixiStyle = new PIXI.TextStyle(pixi_text_style_converter_1.PixiTextStyleConverter.getPixiTextStyle(style));
46
+ let pixiStyle = pixi_text_style_converter_1.TextStyleConverter.getPixiTextStyle(style);
47
47
  pixiStyleCache.set(cacheKey, pixiStyle);
48
48
  return pixiStyle;
49
49
  };
50
50
  let tagsWithStyles = textSegments.map(segment => {
51
51
  let { style, cacheKey } = this.getCombinedStyle(segment.tags, options, styleCache);
52
52
  let pixiStyle = GetPixiStyle(style, cacheKey);
53
- let spaceMeasurement = PIXI.TextMetrics.measureText(' ', pixiStyle, false);
53
+ let spaceMeasurement = PIXI.TextMetrics.measureText(' ', new PIXI.TextStyle(pixiStyle), false);
54
54
  let data = {
55
55
  text: segment.text,
56
56
  cacheKey,
@@ -112,14 +112,15 @@ class RichTextDataInConverter {
112
112
  let chunkData = line.flatMap(data => {
113
113
  let chunkStrings = this.splitToChunks(data.text);
114
114
  return chunkStrings.map(chunkString => {
115
- let metrics = PIXI.TextMetrics.measureText(chunkString, data.pixiStyle, false);
115
+ let pixiStyle = new PIXI.TextStyle(data.pixiStyle);
116
+ let metrics = PIXI.TextMetrics.measureText(chunkString, pixiStyle, false);
116
117
  let chunkDatum = {
117
118
  text: chunkString,
118
119
  whitespace: chunkString.trim() === '',
119
120
  style: {
120
121
  cacheKey: data.cacheKey,
121
122
  style: data.style,
122
- pixiStyle: data.pixiStyle,
123
+ pixiStyle,
123
124
  height: metrics.height,
124
125
  ascent: metrics.fontProperties.ascent,
125
126
  descent: metrics.fontProperties.descent,
@@ -1,29 +1,5 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
- const PIXI = __importStar(require("pixi.js"));
27
3
  const script_engine_lib_1 = require("script-engine-lib");
28
4
  const vitest_1 = require("vitest");
29
5
  const rich_text_to_plane_text_test_1 = require("../../rich-text-to-plane-text.test");
@@ -47,11 +23,11 @@ const ExpectedResults = {
47
23
  'style1+style2': { fontFamily: 'Arial', color: Style2Color, fontSize: 22, lineHeight: 25 }
48
24
  };
49
25
  const ExpectedPixiStyles = {
50
- empty: new PIXI.TextStyle(pixi_text_style_converter_1.PixiTextStyleConverter.getPixiTextStyle({})),
51
- default: new PIXI.TextStyle(pixi_text_style_converter_1.PixiTextStyleConverter.getPixiTextStyle(ExpectedResults.default)),
52
- style1: new PIXI.TextStyle(pixi_text_style_converter_1.PixiTextStyleConverter.getPixiTextStyle(ExpectedResults.style1)),
53
- style2: new PIXI.TextStyle(pixi_text_style_converter_1.PixiTextStyleConverter.getPixiTextStyle(ExpectedResults.style2)),
54
- 'style1+style2': new PIXI.TextStyle(pixi_text_style_converter_1.PixiTextStyleConverter.getPixiTextStyle(ExpectedResults['style1+style2']))
26
+ empty: pixi_text_style_converter_1.TextStyleConverter.getPixiTextStyle({}),
27
+ default: pixi_text_style_converter_1.TextStyleConverter.getPixiTextStyle(ExpectedResults.default),
28
+ style1: pixi_text_style_converter_1.TextStyleConverter.getPixiTextStyle(ExpectedResults.style1),
29
+ style2: pixi_text_style_converter_1.TextStyleConverter.getPixiTextStyle(ExpectedResults.style2),
30
+ 'style1+style2': pixi_text_style_converter_1.TextStyleConverter.getPixiTextStyle(ExpectedResults['style1+style2'])
55
31
  };
56
32
  (0, vitest_1.describe)('RichTextDataInConverter', () => {
57
33
  (0, rich_text_to_plane_text_test_1.MockPixiMeasureText)();
@@ -242,9 +218,9 @@ const ExpectedPixiStyles = {
242
218
  b: { fontSize: 14 }
243
219
  };
244
220
  const PixiStyles = {
245
- default: new PIXI.TextStyle(pixi_text_style_converter_1.PixiTextStyleConverter.getPixiTextStyle(mockStyles.default)),
246
- red: new PIXI.TextStyle(pixi_text_style_converter_1.PixiTextStyleConverter.getPixiTextStyle(mockStyles.red)),
247
- b: new PIXI.TextStyle(pixi_text_style_converter_1.PixiTextStyleConverter.getPixiTextStyle(mockStyles.b))
221
+ default: pixi_text_style_converter_1.TextStyleConverter.getPixiTextStyle(mockStyles.default),
222
+ red: pixi_text_style_converter_1.TextStyleConverter.getPixiTextStyle(mockStyles.red),
223
+ b: pixi_text_style_converter_1.TextStyleConverter.getPixiTextStyle(mockStyles.b)
248
224
  };
249
225
  const GetTagsWithStyles = (text, style = 'default') => {
250
226
  let result = {
@@ -34,7 +34,7 @@ const CreateSampleChunkData = (text, options) => ({
34
34
  style: {
35
35
  cacheKey: JSON.stringify(options) ?? 'empty',
36
36
  style: { fontSize: options?.fontSize ?? 16, fontFamily: 'Arial' },
37
- pixiStyle: { fontSize: options?.fontSize ?? 16, fontFamily: 'Arial' },
37
+ pixiStyle: new PIXI.TextStyle({ fontSize: options?.fontSize ?? 16, fontFamily: 'Arial' }),
38
38
  height: options?.fontSize ?? 16,
39
39
  ascent: options?.fontSize ? options.fontSize - 4 : 12,
40
40
  descent: 4,
@@ -2,13 +2,15 @@ import { RGBColor, Vector } from 'helpers-lib';
2
2
  import { Container } from '../../container';
3
3
  import { PartialTextOptions } from './helpers/process-steps/1-data-in-converter/pixi-text-style-converter';
4
4
  export declare class Text extends Container {
5
+ private readonly partialOptions?;
5
6
  private pixiText;
6
- private style;
7
+ private strikethroughGraphics?;
8
+ private pixiTextStyle;
7
9
  private text;
8
10
  private _textMetrics?;
9
11
  private get textMetrics();
10
12
  get ascent(): number;
11
- constructor(text: string, partialOptions?: PartialTextOptions);
13
+ constructor(text: string, partialOptions?: PartialTextOptions | undefined);
12
14
  protected destroySelf(): void;
13
15
  setAnchor(value: Vector): this;
14
16
  get anchor(): Vector;
@@ -20,4 +22,5 @@ export declare class Text extends Container {
20
22
  setText(text: string): this;
21
23
  setColor(color: RGBColor): this;
22
24
  private regeneratePixiText;
25
+ private addStrikethroughToText;
23
26
  }
@@ -33,7 +33,7 @@ const FONT_SIZE_MULTIPLIER_INVERSE = 1 / FONT_SIZE_MULTIPLIER;
33
33
  class Text extends container_1.Container {
34
34
  get textMetrics() {
35
35
  if (!this._textMetrics) {
36
- let pixiTextStyle = new PIXI.TextStyle(this.style);
36
+ let pixiTextStyle = new PIXI.TextStyle(this.pixiTextStyle);
37
37
  this._textMetrics = PIXI.TextMetrics.measureText(this.text, pixiTextStyle);
38
38
  }
39
39
  return this._textMetrics;
@@ -43,7 +43,8 @@ class Text extends container_1.Container {
43
43
  }
44
44
  constructor(text, partialOptions) {
45
45
  super();
46
- this.style = pixi_text_style_converter_1.PixiTextStyleConverter.getPixiTextStyle(partialOptions);
46
+ this.partialOptions = partialOptions;
47
+ this.pixiTextStyle = pixi_text_style_converter_1.TextStyleConverter.getPixiTextStyle(partialOptions);
47
48
  this.setText(text);
48
49
  }
49
50
  destroySelf() {
@@ -62,7 +63,7 @@ class Text extends container_1.Container {
62
63
  }
63
64
  setPosition(value, options) {
64
65
  if (options?.holdFrom) {
65
- let blurDistance = this.style.dropShadowDistance ?? 0;
66
+ let blurDistance = this.pixiTextStyle.dropShadowDistance ?? 0;
66
67
  let shadowOffset = new helpers_lib_1.Vector(options.holdFrom.x * blurDistance, options.holdFrom.y * blurDistance);
67
68
  value = value.add(shadowOffset);
68
69
  }
@@ -78,19 +79,52 @@ class Text extends container_1.Container {
78
79
  }
79
80
  setColor(color) {
80
81
  let colorHex = helpers_lib_1.ColorHelper.rgbToHex(color);
81
- if (this.style.fill !== colorHex) {
82
- this.style.fill = colorHex;
82
+ if (this.pixiTextStyle.fill !== colorHex) {
83
+ this.pixiTextStyle.fill = colorHex;
83
84
  this.regeneratePixiText();
84
85
  }
85
86
  return this;
86
87
  }
87
88
  regeneratePixiText() {
88
89
  this.pixiText?.destroy();
90
+ this.strikethroughGraphics?.destroy();
91
+ this.strikethroughGraphics = undefined;
89
92
  this._textMetrics = undefined;
90
- let pixiTextStyle = new PIXI.TextStyle(this.style);
93
+ let pixiTextStyle = new PIXI.TextStyle(this.pixiTextStyle);
91
94
  this.pixiText = new PIXI.Text(this.text, pixiTextStyle);
92
95
  this.pixiText.scale.set(FONT_SIZE_MULTIPLIER_INVERSE, FONT_SIZE_MULTIPLIER_INVERSE);
93
96
  this.pixiContainer.addChild(this.pixiText);
97
+ if (this.pixiTextStyle.lineThrough) {
98
+ this.strikethroughGraphics = this.addStrikethroughToText(this.pixiText, this.pixiTextStyle.fill);
99
+ this.pixiContainer.addChild(this.strikethroughGraphics);
100
+ }
101
+ }
102
+ addStrikethroughToText(pixiText, lineColor) {
103
+ let textMetrics = PIXI.TextMetrics.measureText(pixiText.text, pixiText.style);
104
+ let lineThickness = Math.max(1, Math.round(textMetrics.lineHeight * 0.07));
105
+ let lineOffset = (lineThickness % 2) * 0.5;
106
+ let strikethroughGraphics = new PIXI.Graphics();
107
+ strikethroughGraphics.lineStyle(lineThickness, lineColor);
108
+ let currentY = 0;
109
+ textMetrics.lines.forEach((line, index) => {
110
+ let lineMetrics = PIXI.TextMetrics.measureText(line, pixiText.style);
111
+ let lineY = Math.round(currentY +
112
+ (lineMetrics.fontProperties.ascent - lineMetrics.fontProperties.descent) * 0.6 +
113
+ lineMetrics.fontProperties.descent) + lineOffset;
114
+ let lineX = 0;
115
+ if (pixiText.style.align === 'center') {
116
+ lineX = 0 + (pixiText.width - lineMetrics.width) * 0.5;
117
+ }
118
+ else if (pixiText.style.align === 'right') {
119
+ lineX = 0 + pixiText.width - lineMetrics.width;
120
+ }
121
+ lineX = Math.floor(lineX);
122
+ strikethroughGraphics.moveTo(Math.floor(lineX), lineY);
123
+ strikethroughGraphics.lineTo(Math.floor(lineX + lineMetrics.width), lineY);
124
+ currentY += lineMetrics.lineHeight;
125
+ });
126
+ strikethroughGraphics.endFill();
127
+ return strikethroughGraphics;
94
128
  }
95
129
  }
96
130
  exports.Text = Text;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bard-legends-framework",
3
- "version": "0.10.3",
3
+ "version": "0.10.5",
4
4
  "description": "Bard Legends Framework",
5
5
  "main": "dist/index.js",
6
6
  "files": [