Tidy unused code.

This commit is contained in:
Alexander Bass 2022-07-19 23:50:48 -04:00
parent 986dcc4dcd
commit 426cecd355
9 changed files with 67 additions and 27 deletions

View file

@ -0,0 +1,12 @@
import * as net from "../../net/netcode.js"
import {Picker} from "./picker.js"
import {tileArray, menuArray} from "../../display/tileRenderer.js"
import * as util from "../../util.js"
import {ID} from "../../util.js"
import * as status from "../../net/status.js"
var colorPicker;
export function init(){
colorPicker = new Picker("joinGameSelectColorBar", tileArray, [8, 16], null, 0, null)
}

View file

@ -1,7 +1,7 @@
import * as status from "../../net/status.js" import * as status from "../../net/status.js"
// import {joinGame, createGame} from "../../net/netcode.js" // import {joinGame, createGame} from "../../net/netcode.js"
import { changeScene } from "../scene.js" import { changeScene } from "../scene.js"
import * as createMenu from "./create.js"
import {ID} from "../../util.js" import {ID} from "../../util.js"
const joinType = ID("joinType") const joinType = ID("joinType")
@ -15,14 +15,12 @@ codeInput.addEventListener("input", e => {
ID("gotoCreate").addEventListener("click", e => { ID("gotoCreate").addEventListener("click", e => {
joinType.style.display = "none" changeScene("newgame")
createGameMenu.style.display = ""
createMenu.init()
}) })
ID("gotoJoin").addEventListener("click", e => { ID("gotoJoin").addEventListener("click", e => {
joinType.style.display = "none" if (codeInput.value.length !== 6) return console.log("error")
joinGameMenu.style.display = ""; net.initJoin(codeInput.value)
}) })
ID("joinGameButton").addEventListener("click", e => { ID("joinGameButton").addEventListener("click", e => {

View file

@ -1,13 +1,33 @@
import {ID} from "../util.js"
import * as createMenu from "./mainmenu/create.js"
import * as joinMenu from "./mainmenu/join.js"
const menu = ID('menu')
const game = ID('game')
const joinType = ID("joinType")
const joinGameMenu = ID("joinGame")
const createGameMenu = ID("createGame")
export function changeScene(scene) { export function changeScene(scene) {
if (scene == "game") { console.log(`Changing scene to ${scene}`)
document.getElementById('menu').style = "display: none;" switch (scene) {
document.getElementById('game').style = "" case "game":
// picker.create(); menu.style = "display: none;"
} game.style = ""
if (scene == "mainmenu") { break;
document.getElementById('menu').style = "" case "mainmenu":
document.getElementById('game').style = "display: none;" menu.style = ""
// picker.destroy(); game.style = "display: none;"
break;
case "newgame":
joinType.style.display = "none";
createGameMenu.style.display = "";
createMenu.init();
break;
case "joingame":
joinType.style.display = "none";
joinGameMenu.style.display = "";
joinMenu.init();
break;
} }
}; };

View file

@ -11,6 +11,10 @@ export function joinGame(data){
socket.emit('joinGame', data); socket.emit('joinGame', data);
} }
export function initJoin(code){
socket.emit('initJoin', code)
}
export function createGame(data){ export function createGame(data){
socket.emit('createGame', data); socket.emit('createGame', data);
} }

View file

@ -2,7 +2,6 @@
<html> <html>
<head> <head>
<title></title> <title></title>
<script src="http://localhost:35729/livereload.js" charset="utf-8"></script>
<script type="text/javascript" src="socket.io.min.js"></script> <script type="text/javascript" src="socket.io.min.js"></script>
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<script src='index.js' type="module"></script> <script src='index.js' type="module"></script>
@ -45,6 +44,8 @@
</div> </div>
<div id="joinGame" style="display: none;"> <div id="joinGame" style="display: none;">
<input type="text" id="joinGameCode" value=""> <input type="text" id="joinGameCode" value="">
<u>Color</u>
<div id="joinGameSelectColorBar"></div>
<input type="text" id="joinGameUsername" value=""> <input type="text" id="joinGameUsername" value="">
<button type="button" id="joinGameButton">Join</button> <button type="button" id="joinGameButton">Join</button>
</div> </div>

14
package-lock.json generated
View file

@ -11,7 +11,7 @@
"dependencies": { "dependencies": {
"express": "^4.18.1", "express": "^4.18.1",
"sass": "^1.52.3", "sass": "^1.52.3",
"socket.io": "^4.5.0", "socket.io": "^4.5.1",
"ts-node": "^10.8.1", "ts-node": "^10.8.1",
"typescript": "^4.7.4" "typescript": "^4.7.4"
}, },
@ -1039,9 +1039,9 @@
"integrity": "sha512-W4N+o69rkMEGVuk2D/cvca3uYsvGlMwsySWV447y99gUPghxq42BxqLNMndb+a1mm/5/7NeXVQS7RLa2XyXvYg==" "integrity": "sha512-W4N+o69rkMEGVuk2D/cvca3uYsvGlMwsySWV447y99gUPghxq42BxqLNMndb+a1mm/5/7NeXVQS7RLa2XyXvYg=="
}, },
"node_modules/socket.io-parser": { "node_modules/socket.io-parser": {
"version": "4.0.4", "version": "4.0.5",
"resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.0.4.tgz", "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.0.5.tgz",
"integrity": "sha512-t+b0SS+IxG7Rxzda2EVvyBZbvFPBCjJoyHuE0P//7OAsN23GItzDRdWa6ALxZI/8R5ygK7jAR6t028/z+7295g==", "integrity": "sha512-sNjbT9dX63nqUFIOv95tTVm6elyIU4RvB1m8dOeZt+IgWwcWklFDOdmGcfo3zSiRsnR/3pJkjY5lfoGqEe4Eig==",
"dependencies": { "dependencies": {
"@types/component-emitter": "^1.2.10", "@types/component-emitter": "^1.2.10",
"component-emitter": "~1.3.0", "component-emitter": "~1.3.0",
@ -2037,9 +2037,9 @@
"integrity": "sha512-W4N+o69rkMEGVuk2D/cvca3uYsvGlMwsySWV447y99gUPghxq42BxqLNMndb+a1mm/5/7NeXVQS7RLa2XyXvYg==" "integrity": "sha512-W4N+o69rkMEGVuk2D/cvca3uYsvGlMwsySWV447y99gUPghxq42BxqLNMndb+a1mm/5/7NeXVQS7RLa2XyXvYg=="
}, },
"socket.io-parser": { "socket.io-parser": {
"version": "4.0.4", "version": "4.0.5",
"resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.0.4.tgz", "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.0.5.tgz",
"integrity": "sha512-t+b0SS+IxG7Rxzda2EVvyBZbvFPBCjJoyHuE0P//7OAsN23GItzDRdWa6ALxZI/8R5ygK7jAR6t028/z+7295g==", "integrity": "sha512-sNjbT9dX63nqUFIOv95tTVm6elyIU4RvB1m8dOeZt+IgWwcWklFDOdmGcfo3zSiRsnR/3pJkjY5lfoGqEe4Eig==",
"requires": { "requires": {
"@types/component-emitter": "^1.2.10", "@types/component-emitter": "^1.2.10",
"component-emitter": "~1.3.0", "component-emitter": "~1.3.0",

View file

@ -16,14 +16,14 @@
"dependencies": { "dependencies": {
"express": "^4.18.1", "express": "^4.18.1",
"sass": "^1.52.3", "sass": "^1.52.3",
"socket.io": "^4.5.0", "socket.io": "^4.5.1",
"ts-node": "^10.8.1", "ts-node": "^10.8.1",
"typescript": "^4.7.4" "typescript": "^4.7.4"
}, },
"devDependencies": { "devDependencies": {
"@tsconfig/node16": "^1.0.3", "@tsconfig/node16": "^1.0.3",
"rollup": "^2.75.7",
"@types/express": "^4.17.13", "@types/express": "^4.17.13",
"@types/node": "^18.0.0" "@types/node": "^18.0.0",
"rollup": "^2.75.7"
} }
} }

View file

@ -6,6 +6,7 @@ class RoomManager {
constructor(){ constructor(){
this.games = []; this.games = [];
} }
getGameByID(id:string) { getGameByID(id:string) {
const game = this.games.filter(obj => obj.id == id)[0] const game = this.games.filter(obj => obj.id == id)[0]
return game return game
@ -16,9 +17,9 @@ class RoomManager {
this.games.push(game); this.games.push(game);
return game return game
} }
removeGameByID(id:string) { removeGameByID(id:string) {
this.games = this.games.filter(obj => obj.id != id); this.games = this.games.filter(obj => obj.id != id);
} }
getAllPlayerIDs() { getAllPlayerIDs() {

View file

@ -34,6 +34,10 @@ function connected(client:any) {
client.player = null client.player = null
}) })
client.on('initJoin', function(code:string){
if (roomManager.getGameByID(code).players.length >= 8) return new IllegalAction(client.id, 28)
})
client.on('joinGame', function(data:any){ client.on('joinGame', function(data:any){
const info = roomManager.playerJoinGame(data.room, data.name, data.color, client.id) const info = roomManager.playerJoinGame(data.room, data.name, data.color, client.id)
client.join(info[0].id) client.join(info[0].id)