add network

This commit is contained in:
ez_lcw 2023-07-04 20:20:07 +08:00
parent 67ea971f4f
commit e434449e93
18 changed files with 18386 additions and 14 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

BIN
.parcel-cache/data.mdb Normal file

Binary file not shown.

File diff suppressed because it is too large Load Diff

BIN
.parcel-cache/lock.mdb Normal file

Binary file not shown.

13
client/index.html Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>openarras</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<canvas width="1000" height="700" id="board"></canvas>
<p id="raw-info"></p>
<script src="./index.js" type="module"></script>
</body>
</html>

7
client/index.js Normal file
View File

@ -0,0 +1,7 @@
import { io } from "socket.io-client";
const socket = io();
socket.on("update",(tank_info) => {
document.querySelector("#raw-info").innerHTML = tank_info;
});

2
dist/index.5e4f646d.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/index.5e4f646d.js.map vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/index.html vendored Normal file
View File

@ -0,0 +1 @@
<!DOCTYPE html><html><head><title>openarras</title><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"></head><body> <canvas width="1000" height="700" id="board"></canvas> <p id="raw-info"></p> <script src="/index.5e4f646d.js" type="module"></script> </body></html>

4030
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
"name": "openarras",
"version": "0.1.0",
"description": "",
"main": "src/index.js",
"source": "client/index.html",
"scripts": {
"test": "mocha tests/"
},
@ -14,6 +14,13 @@
"license": "Apache-2.0",
"type": "module",
"devDependencies": {
"mocha": "^10.2.0"
"buffer": "^6.0.3",
"mocha": "^10.2.0",
"parcel": "^2.9.3"
},
"dependencies": {
"express": "^4.18.2",
"socket.io": "^4.7.1",
"socket.io-client": "^4.7.1"
}
}

View File

@ -1,16 +1,53 @@
import { Vec2 } from '../src/2d.js';
import { Motion, CollisionBox } from '../src/components.js';
import { EntityRegistry } from '../src/ecs.js';
import {Server} from 'socket.io';
import Express from 'express';
import http_server from 'http';
import path from 'path';
const app = Express();
const http = new http_server.Server(app);
const io = new Server(http);
io.on("connection", (socket) => {
});
function main() {
app.use('/', Express.static(path.join('.','./dist')));
const server_port = parseInt(process.env.PORT) | 3000;
http.listen(server_port, () => {
console.log(`Server started on port ${server_port}.`);
});
process.on('SIGINT', () => {
console.log('\nShutting server...');
users.forEach(u => {
u.socket.disconnect();
console.log(`Disconnected user ${u.name}.`);
});
http.close(() => {
console.log('Closed.');
process.exit(0);
});
});
let registry = new EntityRegistry();
let tank = registry.create();
registry.assign(tank, new Motion(new Vec2(0, 0), new Vec2(1, 1)));
registry.assign(tank, new CollisionBox(1));
registry.forEach([Motion], (id, motion) => {
motion.position.addTo(motion.velocity);
});
console.log(`motion: ${JSON.stringify(registry.get(tank, Motion))}`);
setInterval(() => {
registry.forEach([Motion], (id, motion) => {
motion.position.addTo(motion.velocity);
});
}, 1000/60);
setInterval(() => {
io.emit("update",JSON.stringify(registry.get(tank, Motion)))
}, 50);
}
main();