]>
git.r.bdr.sh - rbdr/sumo/blob - lib/systems/render_winner.js
ecda168742f275a904e46ad6ff589ca0c2f6f05a
1 import { System
} from '@serpentity/serpentity';
2 import { Text
} from 'pixi.js';
3 import Tinycolor
from 'tinycolor2';
5 import Config
from '../config';
6 import WinnerNode
from '../nodes/winner';
9 kNoPixiError: 'No pixi application passed to render system. Make sure you set the `application` key in the config object when initializing.'
13 * Renders a winner if there is one
15 * @extends {external:Serpentity.System}
16 * @class RenderWinnerSystem
17 * @param {object} config a configuration object to extend.
19 export default class RenderWinnerSystem
extends System
{
21 constructor(config
= {}) {
26 * The keepers of the winner
28 * @property {external:Serpentity.NodeCollection} pointsKeepers
30 * @memberof RenderWinnerSystem
32 this.winnerKeepers
= null;
35 * The pixi engine we will use to render
37 * @property {external:PixiJs.Application} application
39 * @memberof RenderWinnerSystem
41 this.application
= config
.application
;
43 if (!this.application
) {
44 throw new Error(internals
.kNoPixiError
);
49 * Initializes system when added. Requests winner keepers
52 * @memberof RenderWinnerSystem
54 * @param {external:Serpentity.Engine} engine the serpentity engine to
55 * which we are getting added
59 this.winnerKeepers
= engine
.getNodes(WinnerNode
);
63 * Clears system resources when removed.
67 * @memberof RenderWinnerSystem
71 this.pointsKeepers
= null;
72 if (internals
.winnerText
) {
73 this.application
.stage
.removeChild(internals
.winnerText
);
74 internals
.winnerText
= null;
79 * Runs on every update of the loop. Updates the bars
83 * @param {Number} currentFrameDuration the duration of the current
85 * @memberof RenderWinnerSystem
87 update(currentFrameDuration
) {
89 // Right now this is final, once a winner is rendered you would need
90 // to restart the whole system.
91 if (internals
.winnerText
) {
92 const color
= Tinycolor(internals
.winnerText
.tint
.toString(16));
93 internals
.winnerText
.tint
= parseInt(color
.spin(2).toString().substring(1,7), 16);
97 for (const winnerKeeper
of this.winnerKeepers
) {
98 const winner
= winnerKeeper
.winner
.winner
;
100 const message
= `${winner} has won`;
101 internals
.winnerText
= new Text(message
, {
108 internals
.winnerText
.tint
= 0xffbbff;
109 internals
.winnerText
.scale
.x
= 0.125;
110 internals
.winnerText
.scale
.y
= 0.125;
111 internals
.winnerText
.position
.x
= Config
.horizontalResolution
/ 2;
112 internals
.winnerText
.position
.y
= Config
.verticalResolution
/ 2;
113 internals
.winnerText
.anchor
.set(0.5);
114 this.application
.stage
.addChild(internals
.winnerText
);