Add a basic lobby (#3)
- Switch to ExcaliburJS - Add lobby with background table, title, player list and spectator list - Add buttons that do nothing
This commit is contained in:
1 parent
ea8d1871e6
commit
77dcad1015
17 files changed
+543
-138
No files matched your search
@@ -2,16 +2,12 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/png" href="/favicon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
<title>PixiJS - Template</title>
|
||||
<title>Auto Beer Pong</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="app">
|
||||
<div id="pixi-container"></div>
|
||||
</div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
Generated
+6
-94
@@ -8,7 +8,7 @@
|
||||
"name": "frontend",
|
||||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"pixi.js": "^8.8.1"
|
||||
"excalibur": "^0.30.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.21.0",
|
||||
@@ -708,12 +708,6 @@
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/@pixi/colord": {
|
||||
"version": "2.9.6",
|
||||
"resolved": "https://registry.npmjs.org/@pixi/colord/-/colord-2.9.6.tgz",
|
||||
"integrity": "sha512-nezytU2pw587fQstUu1AsJZDVEynjskwOL+kibwcdxsMBFqPsFFNA7xl0ii/gXuDi6M0xj3mfRJj8pBSc2jCfA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@pkgr/core": {
|
||||
"version": "0.2.9",
|
||||
"resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.2.9.tgz",
|
||||
@@ -1007,18 +1001,6 @@
|
||||
"win32"
|
||||
]
|
||||
},
|
||||
"node_modules/@types/css-font-loading-module": {
|
||||
"version": "0.0.12",
|
||||
"resolved": "https://registry.npmjs.org/@types/css-font-loading-module/-/css-font-loading-module-0.0.12.tgz",
|
||||
"integrity": "sha512-x2tZZYkSxXqWvTDgveSynfjq/T2HyiZHXb00j/+gy19yp70PHCizM48XFdjBCWH7eHBD0R5i/pw9yMBP/BH5uA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/earcut": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/earcut/-/earcut-3.0.0.tgz",
|
||||
"integrity": "sha512-k/9fOUGO39yd2sCjrbAJvGDEQvRwRnQIZlBz43roGwUZo5SHAmyVvSFyaVVZkicRVCaDXPKlbxrUcBuJoSWunQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/estree": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz",
|
||||
@@ -1291,21 +1273,6 @@
|
||||
"url": "https://opencollective.com/typescript-eslint"
|
||||
}
|
||||
},
|
||||
"node_modules/@webgpu/types": {
|
||||
"version": "0.1.64",
|
||||
"resolved": "https://registry.npmjs.org/@webgpu/types/-/types-0.1.64.tgz",
|
||||
"integrity": "sha512-84kRIAGV46LJTlJZWxShiOrNL30A+9KokD7RB3dRCIqODFjodS5tCD5yyiZ8kIReGVZSDfA3XkkwyyOIF6K62A==",
|
||||
"license": "BSD-3-Clause"
|
||||
},
|
||||
"node_modules/@xmldom/xmldom": {
|
||||
"version": "0.8.11",
|
||||
"resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.8.11.tgz",
|
||||
"integrity": "sha512-cQzWCtO6C8TQiYl1ruKNn2U6Ao4o4WBBcbL61yJl84x+j5sOWWFU9X7DpND8XZG3daDppSsigMdfAIl2upQBRw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/acorn": {
|
||||
"version": "8.15.0",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz",
|
||||
@@ -1494,12 +1461,6 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/earcut": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/earcut/-/earcut-3.0.2.tgz",
|
||||
"integrity": "sha512-X7hshQbLyMJ/3RPhyObLARM2sNxxmRALLKx1+NVFFnQ9gKzmCrxm9+uLIAdBcvc8FNLpctqlQ2V6AE92Ol9UDQ==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/esbuild": {
|
||||
"version": "0.25.9",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.9.tgz",
|
||||
@@ -1757,11 +1718,11 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/eventemitter3": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz",
|
||||
"integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==",
|
||||
"license": "MIT"
|
||||
"node_modules/excalibur": {
|
||||
"version": "0.30.3",
|
||||
"resolved": "https://registry.npmjs.org/excalibur/-/excalibur-0.30.3.tgz",
|
||||
"integrity": "sha512-RUP3qQ6tFe9BJxvqh6p/I0B9rKMu+KGlHZruJyVOohiYUtCP0LsRgkVHxezvWtWsvCElVBL4PeCooE4KPlIldA==",
|
||||
"license": "BSD-2-Clause"
|
||||
},
|
||||
"node_modules/fast-deep-equal": {
|
||||
"version": "3.1.3",
|
||||
@@ -1910,15 +1871,6 @@
|
||||
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/gifuct-js": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/gifuct-js/-/gifuct-js-2.1.2.tgz",
|
||||
"integrity": "sha512-rI2asw77u0mGgwhV3qA+OEgYqaDn5UNqgs+Bx0FGwSpuqfYn+Ir6RQY5ENNQ8SbIiG/m5gVa7CD5RriO4f4Lsg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"js-binary-schema-parser": "^2.0.3"
|
||||
}
|
||||
},
|
||||
"node_modules/glob-parent": {
|
||||
"version": "6.0.2",
|
||||
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz",
|
||||
@@ -2039,18 +1991,6 @@
|
||||
"dev": true,
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/ismobilejs": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ismobilejs/-/ismobilejs-1.1.1.tgz",
|
||||
"integrity": "sha512-VaFW53yt8QO61k2WJui0dHf4SlL8lxBofUuUmwBo0ljPk0Drz2TiuDW4jo3wDcv41qy/SxrJ+VAzJ/qYqsmzRw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/js-binary-schema-parser": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/js-binary-schema-parser/-/js-binary-schema-parser-2.0.3.tgz",
|
||||
"integrity": "sha512-xezGJmOb4lk/M1ZZLTR/jaBHQ4gG/lqQnJqdIv4721DMggsa1bDVlHXNeHYogaIEHD9vCRv0fcL4hMA+Coarkg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/js-yaml": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
|
||||
@@ -2265,12 +2205,6 @@
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/parse-svg-path": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/parse-svg-path/-/parse-svg-path-0.1.2.tgz",
|
||||
"integrity": "sha512-JyPSBnkTJ0AI8GGJLfMXvKq42cj5c006fnLz6fXy6zfoVjJizi8BNTpu8on8ziI1cKy9d9DGNuY17Ce7wuejpQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/path-exists": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz",
|
||||
@@ -2311,28 +2245,6 @@
|
||||
"url": "https://github.com/sponsors/jonschlinkert"
|
||||
}
|
||||
},
|
||||
"node_modules/pixi.js": {
|
||||
"version": "8.12.0",
|
||||
"resolved": "https://registry.npmjs.org/pixi.js/-/pixi.js-8.12.0.tgz",
|
||||
"integrity": "sha512-or7vrH7WajLevu/JnGMdD80JaSpTlXfjwCLtzhg2BL60LWPf1pF0w08Qleiqr1Saj012gevguM//+6HzzVlnfA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@pixi/colord": "^2.9.6",
|
||||
"@types/css-font-loading-module": "^0.0.12",
|
||||
"@types/earcut": "^3.0.0",
|
||||
"@webgpu/types": "^0.1.40",
|
||||
"@xmldom/xmldom": "^0.8.10",
|
||||
"earcut": "^3.0.2",
|
||||
"eventemitter3": "^5.0.1",
|
||||
"gifuct-js": "^2.1.2",
|
||||
"ismobilejs": "^1.1.1",
|
||||
"parse-svg-path": "^0.1.2"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/pixijs"
|
||||
}
|
||||
},
|
||||
"node_modules/postcss": {
|
||||
"version": "8.5.6",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.6.tgz",
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"dev": "vite"
|
||||
},
|
||||
"dependencies": {
|
||||
"pixi.js": "^8.8.1"
|
||||
"excalibur": "^0.30.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.21.0",
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 830 B |
@@ -4,12 +4,3 @@ body {
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #000000;
|
||||
}
|
||||
|
||||
#app {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import * as ex from 'excalibur';
|
||||
|
||||
const radius = 20;
|
||||
const margin = 2;
|
||||
|
||||
export class Cups extends ex.Graphic {
|
||||
protected _drawImage(context: ex.ExcaliburGraphicsContext, x: number, y: number): void {
|
||||
y += radius;
|
||||
for (let r = 4; r > 0; r--) {
|
||||
x = -r * radius + radius;
|
||||
for (let c = 0; c < r; c++) {
|
||||
context.drawCircle(ex.vec(x, y), radius, ex.Color.Red, ex.Color.White, 2)
|
||||
x += radius * 2 + margin;
|
||||
}
|
||||
|
||||
y += radius * 2 + margin;
|
||||
}
|
||||
}
|
||||
|
||||
clone(): ex.Graphic {
|
||||
return new Cups();
|
||||
}
|
||||
|
||||
get computeHeight(): number {
|
||||
return 4 * 2 * radius + 3 * margin;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
|
||||
export interface GameState {
|
||||
players: string[];
|
||||
spectators: string[];
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import * as ex from 'excalibur';
|
||||
import { GameState } from '../GameState';
|
||||
|
||||
export class GameStateScene extends ex.Scene {
|
||||
public updateFromGameState(_engine: ex.Engine, _gameState: GameState): void { }
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
import * as ex from 'excalibur';
|
||||
import { spacingL, spacingM, spacingS } from '../utils/formattingUtils';
|
||||
import { subTitleFont, titleFont } from '../utils/fontUtil';
|
||||
import { Cups } from '../Cups';
|
||||
import { GameState } from '../GameState';
|
||||
import { GameStateScene } from './GameStateScene';
|
||||
import { PlayerListScreenElement } from '../ScreenElements/PlayerListScreenElement';
|
||||
import { TitledListScreenElement } from '../ScreenElements/TitledListScreenElement';
|
||||
import { Text } from '../ScreenElements/Text';
|
||||
import { Button } from '../ScreenElements/Button';
|
||||
|
||||
const tableWidth = 400;
|
||||
const maxPlayers = 2;
|
||||
|
||||
export class LobbyScene extends GameStateScene {
|
||||
private _table: ex.ScreenElement = null!;
|
||||
private _cups: ex.ScreenElement = null!;
|
||||
|
||||
private _bar1: ex.ScreenElement = null!;
|
||||
private _bar2: ex.ScreenElement = null!;
|
||||
private _bar3: ex.ScreenElement = null!;
|
||||
|
||||
private _title: Text = null!;
|
||||
private _subTitle: Text = null!;
|
||||
|
||||
private _playerList: PlayerListScreenElement = null!;
|
||||
private _spectatorsList: TitledListScreenElement = null!;
|
||||
|
||||
private _joinSpectatorButton: Button = null!;
|
||||
private _joinPlayerButton: Button = null!;
|
||||
|
||||
onInitialize(engine: ex.Engine): void {
|
||||
// Table background
|
||||
this._table = new ex.ScreenElement({
|
||||
anchor: ex.vec(0.5, 0)
|
||||
});
|
||||
this.add(this._table);
|
||||
|
||||
const s = 10;
|
||||
const points = [
|
||||
ex.vec(0, s),
|
||||
ex.vec(s, 0),
|
||||
ex.vec(tableWidth - s, 0),
|
||||
ex.vec(tableWidth, s),
|
||||
ex.vec(tableWidth, engine.screen.height),
|
||||
ex.vec(0, engine.screen.height),
|
||||
];
|
||||
const tableBackground = new ex.Polygon({
|
||||
points,
|
||||
color: ex.Color.fromHex("1971c2"),
|
||||
lineWidth: 16,
|
||||
strokeColor: ex.Color.White,
|
||||
});
|
||||
this._table.graphics.add(tableBackground);
|
||||
|
||||
this._bar1 = this._createBar();
|
||||
this._bar2 = this._createBar();
|
||||
this._bar3 = this._createBar();
|
||||
|
||||
// Cups
|
||||
this._cups = new ex.ScreenElement({})
|
||||
this._cups.anchor.setTo(0.5, 0);
|
||||
this._cups.graphics.add(new Cups());
|
||||
this.add(this._cups);
|
||||
|
||||
// Title
|
||||
this._title = new Text({
|
||||
text: "Auto Beer Pong",
|
||||
font: titleFont,
|
||||
});
|
||||
this._title.anchor.setTo(0.5, 0);
|
||||
this.add(this._title);
|
||||
|
||||
|
||||
// Sub title
|
||||
this._subTitle = new Text({
|
||||
text: "An auto battler with stupid people.",
|
||||
font: subTitleFont,
|
||||
});
|
||||
|
||||
this._subTitle.anchor.setTo(0.5, 0);
|
||||
this.add(this._subTitle);
|
||||
|
||||
|
||||
this._playerList = new PlayerListScreenElement("Players", maxPlayers);
|
||||
this._playerList.labels = ["Dubbel"];
|
||||
this._playerList.anchor.setTo(0.5, 0);
|
||||
this.add(this._playerList);
|
||||
|
||||
this._joinPlayerButton = new Button({
|
||||
text: "Join as player",
|
||||
anchor: ex.vec(0.5, 0),
|
||||
onClick: () => this._joinAsPlayer(),
|
||||
});
|
||||
this.add(this._joinPlayerButton);
|
||||
|
||||
|
||||
this._spectatorsList = new TitledListScreenElement("Spectators");
|
||||
this._spectatorsList.labels = ["Dubbel", "Cocksucker"];
|
||||
this._spectatorsList.anchor.setTo(0.5, 0);
|
||||
this.add(this._spectatorsList);
|
||||
|
||||
|
||||
this._joinSpectatorButton = new Button({
|
||||
text: "Join as spectator",
|
||||
anchor: ex.vec(0.5, 0),
|
||||
onClick: () => this._joinAsSpectator(),
|
||||
});
|
||||
this.add(this._joinSpectatorButton);
|
||||
|
||||
this._updatePositions(engine.screen);
|
||||
}
|
||||
|
||||
private _createBar(): ex.ScreenElement {
|
||||
const bar = new ex.ScreenElement({
|
||||
anchor: ex.vec(0.5, 0),
|
||||
})
|
||||
bar.graphics.add(new ex.Rectangle({
|
||||
width: tableWidth - 2 * spacingM,
|
||||
height: 5,
|
||||
color: ex.Color.White,
|
||||
}));
|
||||
this.add(bar);
|
||||
return bar;
|
||||
}
|
||||
|
||||
private _updatePositions(screen: ex.Screen): void {
|
||||
let y = spacingM;
|
||||
const halfWidth = screen.width / 2;
|
||||
|
||||
this._table.pos = ex.vec(halfWidth, y);
|
||||
y += spacingM;
|
||||
|
||||
this._cups.pos = ex.vec(halfWidth, y);
|
||||
const cups = this._cups.graphics.getGraphic('default') as Cups;
|
||||
y += cups.computeHeight! + spacingM;
|
||||
|
||||
this._bar1.pos = ex.vec(halfWidth, y);
|
||||
y += this._bar1.height + spacingM;
|
||||
|
||||
this._title.pos = ex.vec(halfWidth, y);
|
||||
y += this._title.font.size + spacingM;
|
||||
|
||||
this._subTitle.pos = ex.vec(halfWidth, y);
|
||||
y += this._subTitle.font.size + spacingM;
|
||||
|
||||
this._bar2.pos = ex.vec(halfWidth, y);
|
||||
y += this._bar2.height + spacingL;
|
||||
|
||||
this._playerList.pos = ex.vec(halfWidth, y);
|
||||
y += this._playerList.childrenHeight + spacingL;
|
||||
|
||||
this._joinPlayerButton.pos = ex.vec(halfWidth, y);
|
||||
y += this._joinPlayerButton.height + spacingL;
|
||||
|
||||
this._bar3.pos = ex.vec(halfWidth, y);
|
||||
y += this._bar3.height + spacingL;
|
||||
|
||||
|
||||
this._spectatorsList.pos = ex.vec(halfWidth, y);
|
||||
y += this._spectatorsList.childrenHeight + spacingL;
|
||||
|
||||
this._joinSpectatorButton.pos = ex.vec(halfWidth, y);
|
||||
y += this._spectatorsList.childrenHeight + spacingL;
|
||||
|
||||
}
|
||||
|
||||
public updateFromGameState(engine: ex.Engine, gameState: GameState): void {
|
||||
this._playerList.labels = gameState.players;
|
||||
this._spectatorsList.labels = gameState.spectators;
|
||||
this._updatePositions(engine.screen);
|
||||
}
|
||||
|
||||
private _joinAsPlayer(): void {
|
||||
// Send request
|
||||
}
|
||||
|
||||
private _joinAsSpectator(): void {
|
||||
// Send request
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
import * as ex from 'excalibur';
|
||||
import { Text } from './Text';
|
||||
import { paragraphFont } from '../utils/fontUtil';
|
||||
import { spacingS } from '../utils/formattingUtils';
|
||||
|
||||
interface ButtonProperties {
|
||||
text?: string;
|
||||
disabled?: boolean;
|
||||
onClick?: (event: ex.PointerEvent) => void;
|
||||
}
|
||||
type ConstructProperties = ex.ActorArgs & ButtonProperties;
|
||||
|
||||
export class Button extends ex.ScreenElement {
|
||||
private _text?: string;
|
||||
private _textElement: Text = null!;
|
||||
|
||||
private _disabled: boolean;
|
||||
|
||||
private _onClick?: (event: ex.PointerEvent) => void;
|
||||
|
||||
constructor(config?: ConstructProperties) {
|
||||
super(config);
|
||||
this._text = config?.text;
|
||||
this._disabled = config?.disabled ?? false;
|
||||
this._onClick = config?.onClick;
|
||||
}
|
||||
|
||||
onInitialize(_engine: ex.Engine): void {
|
||||
const margin = spacingS * 2;
|
||||
const width = paragraphFont.measureTextWithoutCache(this.text).width + margin;
|
||||
const height = paragraphFont.size + margin;
|
||||
|
||||
this._textElement = new Text({
|
||||
text: this._text,
|
||||
font: paragraphFont,
|
||||
})
|
||||
this._textElement.anchor = ex.vec(0.5, 0.5);
|
||||
this._textElement.pos = ex.vec(0, height / 2);
|
||||
this.addChild(this._textElement);
|
||||
|
||||
this.graphics.add('idle', new ex.Rectangle({
|
||||
width,
|
||||
height,
|
||||
color: ex.Color.fromHex("4788ff"),
|
||||
}));
|
||||
|
||||
this.graphics.add('hover', new ex.Rectangle({
|
||||
width,
|
||||
height,
|
||||
color: ex.Color.fromHex("bad2ff")
|
||||
}));
|
||||
this.graphics.use('idle');
|
||||
|
||||
this.graphics.add('disabled', new ex.Rectangle({
|
||||
width,
|
||||
height,
|
||||
color: ex.Color.Gray,
|
||||
}));
|
||||
this.graphics.use('idle');
|
||||
|
||||
this.on('pointerup', (e) => this.onPointerUp(e));
|
||||
this.on('pointerenter', (e) => this.onPointerEnter(e));
|
||||
this.on('pointerleave', (e) => this.onPointerLeave(e));
|
||||
}
|
||||
|
||||
get text(): string {
|
||||
return this._text ?? "";
|
||||
}
|
||||
|
||||
get disabled(): boolean {
|
||||
return this._disabled;
|
||||
}
|
||||
|
||||
set disabled(value: boolean) {
|
||||
this._disabled = value;
|
||||
this.graphics.use(value ? 'disabled' : 'idle')
|
||||
}
|
||||
|
||||
onPointerUp(event: ex.PointerEvent): void {
|
||||
if (this._disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { _onClick } = this;
|
||||
if (_onClick != null) {
|
||||
_onClick(event);
|
||||
}
|
||||
}
|
||||
|
||||
onPointerEnter(_event: ex.PointerEvent): void {
|
||||
if (this._disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.graphics.use('hover');
|
||||
}
|
||||
|
||||
onPointerLeave(_event: ex.PointerEvent): void {
|
||||
if (this._disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.graphics.use('idle');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import * as ex from 'excalibur';
|
||||
|
||||
import { TitledListScreenElement } from "./TitledListScreenElement";
|
||||
import { spacingS } from '../utils/formattingUtils';
|
||||
import { disabledFont, paragraphFont } from '../utils/fontUtil';
|
||||
import { Text } from './Text';
|
||||
|
||||
export class PlayerListScreenElement extends TitledListScreenElement {
|
||||
constructor(headingText: string, private _maxPlayers: number) {
|
||||
super(headingText);
|
||||
}
|
||||
|
||||
protected override updateList(): void {
|
||||
this.clearLabelEntities();
|
||||
|
||||
let y = this.heading.font.size + spacingS;
|
||||
|
||||
const labels = this._labels.slice(0, this._maxPlayers);
|
||||
|
||||
for(const labelText of labels) {
|
||||
const label = new Text({
|
||||
text: labelText,
|
||||
font: paragraphFont,
|
||||
})
|
||||
label.pos.setTo(0, y);
|
||||
label.anchor.setTo(0.5, 0);
|
||||
y += label.font.size + spacingS;
|
||||
this.addChild(label);
|
||||
this.labelsEntities.push(label);
|
||||
}
|
||||
|
||||
for(let i = labels.length; i < this._maxPlayers; i++) {
|
||||
const label = new Text({
|
||||
text: "Empty",
|
||||
font: disabledFont,
|
||||
})
|
||||
label.pos.setTo(0, y);
|
||||
label.anchor.setTo(0.5, 0);
|
||||
y += label.font.size + spacingS;
|
||||
this.addChild(label);
|
||||
this.labelsEntities.push(label);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
override get childrenHeight(): number {
|
||||
return this.computeChildrenHeight(this._maxPlayers);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import * as ex from 'excalibur';
|
||||
|
||||
type ConstructProperties = ex.LabelOptions & ex.ActorArgs;
|
||||
|
||||
export class Text extends ex.Label {
|
||||
constructor(options?: ConstructProperties) {
|
||||
super(options);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import * as ex from 'excalibur';
|
||||
|
||||
import { spacingS } from '../utils/formattingUtils';
|
||||
import { headingFont, paragraphFont } from '../utils/fontUtil';
|
||||
import { Text } from './Text';
|
||||
|
||||
export class TitledListScreenElement extends ex.ScreenElement {
|
||||
protected _labels: string[] = [];
|
||||
protected heading: Text = null!;
|
||||
protected labelsEntities: Text[] = [];
|
||||
|
||||
constructor(private _headingText: string) {
|
||||
super();
|
||||
}
|
||||
|
||||
override onInitialize(_engine: ex.Engine): void {
|
||||
this.heading = new Text({
|
||||
text: this._headingText,
|
||||
font: headingFont
|
||||
});
|
||||
this.heading.anchor.setTo(0.5, 0);
|
||||
this.addChild(this.heading);
|
||||
|
||||
this.updateList();
|
||||
}
|
||||
|
||||
get childrenHeight(): number {
|
||||
return this.computeChildrenHeight(this._labels.length);
|
||||
}
|
||||
|
||||
set labels(labels: string[]) {
|
||||
this._labels = labels;
|
||||
if (this.isInitialized) {
|
||||
this.updateList();
|
||||
}
|
||||
}
|
||||
|
||||
protected updateList(): void {
|
||||
this.clearLabelEntities();
|
||||
|
||||
let y = headingFont.size + spacingS;
|
||||
|
||||
for(const labelText of this._labels) {
|
||||
const label = new Text({
|
||||
text: labelText,
|
||||
font: paragraphFont,
|
||||
})
|
||||
label.pos.setTo(0, y);
|
||||
label.anchor.setTo(0.5, 0);
|
||||
y += label.font.size + spacingS;
|
||||
this.addChild(label);
|
||||
this.labelsEntities.push(label);
|
||||
}
|
||||
|
||||
if (this._labels.length === 0) {
|
||||
const label = new Text({
|
||||
text: "No one cares.",
|
||||
font: paragraphFont,
|
||||
});
|
||||
label.pos = ex.vec(0, y);
|
||||
label.anchor = ex.vec(0.5, 0);
|
||||
this.addChild(label);
|
||||
this.labelsEntities.push(label);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected computeChildrenHeight(numLabels: number): number {
|
||||
return headingFont.size + spacingS + numLabels * (spacingS + paragraphFont.size);
|
||||
}
|
||||
|
||||
protected clearLabelEntities(): void {
|
||||
for(const labelEntity of this.labelsEntities) {
|
||||
this.removeChild(labelEntity);
|
||||
}
|
||||
this.labelsEntities = [];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+21
-28
@@ -1,35 +1,28 @@
|
||||
import { Application, Assets, Sprite } from "pixi.js";
|
||||
import * as ex from 'excalibur';
|
||||
import { LobbyScene } from "./Scenes/LobbyScene";
|
||||
|
||||
(async () => {
|
||||
// Create a new application
|
||||
const app = new Application();
|
||||
const game = new ex.Engine({
|
||||
width: 0,
|
||||
height: 0,
|
||||
displayMode: ex.DisplayMode.FillScreen,
|
||||
scenes: { lobby: LobbyScene},
|
||||
backgroundColor: ex.Color.fromHex("23213b"),
|
||||
});
|
||||
game.toggleDebug();
|
||||
|
||||
// Initialize the application
|
||||
await app.init({ background: "#1099bb", resizeTo: window });
|
||||
game.start().then(async () => {
|
||||
await game.goToScene('lobby');
|
||||
|
||||
// Append the application canvas to the document body
|
||||
document.getElementById("pixi-container")!.appendChild(app.canvas);
|
||||
// Test update
|
||||
const gameState = {
|
||||
players: ["LoL"],
|
||||
spectators: [],
|
||||
}
|
||||
|
||||
// Load the bunny texture
|
||||
const texture = await Assets.load("/assets/bunny.png");
|
||||
|
||||
// Create a bunny Sprite
|
||||
const bunny = new Sprite(texture);
|
||||
|
||||
// Center the sprite's anchor point
|
||||
bunny.anchor.set(0.5);
|
||||
|
||||
// Move the sprite to the center of the screen
|
||||
bunny.position.set(app.screen.width / 2, app.screen.height / 2);
|
||||
|
||||
// Add the bunny to the stage
|
||||
app.stage.addChild(bunny);
|
||||
|
||||
// Listen for animate update
|
||||
app.ticker.add((time) => {
|
||||
// Just for fun, let's rotate mr rabbit a little.
|
||||
// * Delta is 1 if running at 100% performance *
|
||||
// * Creates frame-independent transformation *
|
||||
bunny.rotation += 0.1 * time.deltaTime;
|
||||
const lobbyScene = game.currentScene as LobbyScene;
|
||||
setTimeout(() => {
|
||||
lobbyScene.updateFromGameState(game, gameState);
|
||||
}, 2000);
|
||||
});
|
||||
})();
|
||||
@@ -0,0 +1,43 @@
|
||||
import * as ex from 'excalibur';
|
||||
|
||||
const fontFamily = "impact";
|
||||
const shadow = {
|
||||
color: ex.Color.Black,
|
||||
offset: ex.vec(4, 4),
|
||||
}
|
||||
|
||||
export const paragraphFont = new ex.Font({
|
||||
family: fontFamily,
|
||||
color: ex.Color.White,
|
||||
size: 20,
|
||||
shadow,
|
||||
});
|
||||
|
||||
export const headingFont = new ex.Font({
|
||||
family: fontFamily,
|
||||
color: ex.Color.White,
|
||||
size: 24,
|
||||
shadow,
|
||||
});
|
||||
|
||||
export const subTitleFont = new ex.Font({
|
||||
family: fontFamily,
|
||||
color: ex.Color.White,
|
||||
size: 20,
|
||||
shadow,
|
||||
});
|
||||
|
||||
export const titleFont = new ex.Font({
|
||||
family: fontFamily,
|
||||
color: ex.Color.White,
|
||||
size: 48,
|
||||
shadow,
|
||||
});
|
||||
|
||||
export const disabledFont = new ex.Font({
|
||||
family: fontFamily,
|
||||
color: ex.Color.Gray,
|
||||
size: 20,
|
||||
shadow,
|
||||
|
||||
})
|
||||
@@ -0,0 +1,3 @@
|
||||
export const spacingL = 40;
|
||||
export const spacingM = 20;
|
||||
export const spacingS = 5;
|
||||
Reference in new issue
Block a user