Add better object updates

This commit is contained in:
schmelczerandras 2020-10-17 18:35:09 +02:00
parent fd80a299b6
commit e83c58e1a5
29 changed files with 289 additions and 123 deletions

View file

@ -1,7 +1,12 @@
import { glMatrix } from 'gl-matrix';
import { CharacterBase, LampBase, overrideDeserialization, PlanetBase } from 'shared';
import { ProjectileBase } from 'shared/src/objects/types/projectile-base';
import {
CharacterBase,
LampBase,
overrideDeserialization,
PlanetBase,
PlayerCharacterBase,
ProjectileBase,
} from 'shared';
import { CharacterView } from './scripts/objects/character-view';
import { LampView } from './scripts/objects/lamp-view';
import { ProjectileView } from './scripts/objects/projectile-view';
@ -10,43 +15,32 @@ import './styles/main.scss';
import { LandingPageBackground } from './scripts/landing-page-background';
import { JoinFormHandler } from './scripts/join-form-handler';
import { Game } from './scripts/game';
import { PlayerCharacterView } from './scripts/objects/player-character-view';
glMatrix.setMatrixArrayType(Array);
overrideDeserialization(CharacterBase, CharacterView);
overrideDeserialization(PlayerCharacterBase, PlayerCharacterView);
overrideDeserialization(PlanetBase, PlanetView);
overrideDeserialization(LampBase, LampView);
overrideDeserialization(ProjectileBase, ProjectileView);
const addSupportForTabNavigation = () =>
(document.onkeydown = (e) => {
if (e.key === ' ') {
(document.activeElement as HTMLElement)?.click();
e.preventDefault();
}
});
/*const removeUnnecessaryOutlines = () =>
(document.onclick = (e) => {
(e.target as HTMLElement)?.blur();
});
*/
addSupportForTabNavigation();
//removeUnnecessaryOutlines();
const main = async () => {
try {
const landingUI = document.querySelector('#landing-ui') as HTMLElement;
const background = new LandingPageBackground();
const joinHandler = new JoinFormHandler(
document.querySelector('#join-game-form') as HTMLFormElement,
document.querySelector('#server-container') as HTMLElement,
);
const joinGameForm = document.querySelector('#join-game-form') as HTMLFormElement;
const serverContainer = document.querySelector('#server-container') as HTMLElement;
const canvas = document.querySelector('canvas') as HTMLCanvasElement;
const overlay = document.querySelector('#overlay') as HTMLElement;
const background = new LandingPageBackground(canvas);
const joinHandler = new JoinFormHandler(joinGameForm, serverContainer);
const playerDecision = await joinHandler.getPlayerDecision();
landingUI.style.display = 'none';
console.log(playerDecision);
background.destroy();
await new Game(playerDecision).start();
await new Game(playerDecision, canvas, overlay).start();
} catch (e) {
console.error(e);
alert(e);