]>
git.r.bdr.sh - rbdr/sumo/blob - lib/systems/render_winner.js
1 import { System
} from '@serpentity/serpentity';
2 import { Text
} from 'pixi.js';
4 import Config
from '../config';
5 import WinnerNode
from '../nodes/winner';
8 kNoPixiError: 'No pixi application passed to render system. Make sure you set the `application` key in the config object when initializing.'
12 * Renders a winner if there is one
14 * @extends {external:Serpentity.System}
15 * @class RenderWinnerSystem
16 * @param {object} config a configuration object to extend.
18 export default class RenderWinnerSystem
extends System
{
20 constructor(config
= {}) {
25 * The keepers of the winner
27 * @property {external:Serpentity.NodeCollection} pointsKeepers
29 * @memberof RenderWinnerSystem
31 this.winnerKeepers
= null;
34 * The pixi engine we will use to render
36 * @property {external:PixiJs.Application} application
38 * @memberof RenderWinnerSystem
40 this.application
= config
.application
;
42 if (!this.application
) {
43 throw new Error(internals
.kNoPixiError
);
48 * Initializes system when added. Requests winner keepers
51 * @memberof RenderWinnerSystem
53 * @param {external:Serpentity.Engine} engine the serpentity engine to
54 * which we are getting added
58 this.winnerKeepers
= engine
.getNodes(WinnerNode
);
62 * Clears system resources when removed.
66 * @memberof RenderWinnerSystem
70 this.pointsKeepers
= null;
71 if (internals
.winnerText
) {
72 this.application
.stage
.removeChild(internals
.winnerText
);
73 internals
.winnerText
= null;
78 * Runs on every update of the loop. Updates the bars
82 * @param {Number} currentFrameDuration the duration of the current
84 * @memberof RenderWinnerSystem
86 update(currentFrameDuration
) {
88 // Right now this is final, once a winner is rendered you would need
89 // to restart the whole system.
90 if (internals
.winnerText
) {
94 for (const winnerKeeper
of this.winnerKeepers
) {
95 const winner
= winnerKeeper
.winner
.winner
;
97 const message
= `${winner} has won`;
98 internals
.winnerText
= new Text(message
, {
105 internals
.winnerText
.position
.x
= Config
.horizontalResolution
/ 2;
106 internals
.winnerText
.position
.y
= Config
.verticalResolution
/ 2;
107 internals
.winnerText
.anchor
.set(0.5);
108 this.application
.stage
.addChild(internals
.winnerText
);