Done for the night.

This commit is contained in:
Alexander Bass 2022-06-19 23:08:35 -04:00
parent c89f24a2a7
commit 3927b3963e
6 changed files with 20 additions and 13 deletions

View file

@ -1,13 +1,15 @@
const worldgen = require("./worldgen.js")
const util = require("./util.js")
const log = require("./log.js")
const {performance} = require('perf_hooks');
const gridSize = [18, 18];
const perlinScale = 3;
const perlinScale = 4;
const startTime = performance.now()
var express = require('express');
log.setMode(0);
process.title = "Server"
setInterval(function(){ updateInfo()},5000)
log.logRight(1, `Uptime: ${(performance.now() - startTime)/100}`);
function updateInfo() {
log.setInfo(server.games)
}
@ -43,6 +45,7 @@ class Server {
removeGame(name) {
this.games = this.games.filter(obj => obj.name != name);
log.log("removed game - " + name)
// Broken?
}
getAllIDs() {
@ -126,7 +129,7 @@ var app = express() //Static resources server
app.use(express.static(__dirname + '/www/'));
var webServer = app.listen(8082, function () {
var port = webServer.address().port;
log.log(`Server running at port ${port}`, "bright");
log.logRight(0, `Server running at port ${port}`, "bright");
});
var io = require('socket.io')(webServer);/* Connection events */

11
log.js
View file

@ -1,6 +1,7 @@
const os = require("os")
var mode = 0
var logs = []
var rightView = [0,1,2,3,4,5,6]
var info = [[],[]]
function setMode(type) {
@ -22,10 +23,11 @@ for (var i = 0; i < vertSplit; i++) {
process.stdout.write(`|`)
}
for (var i = 0; i < columns; i++) {
process.stdout.cursorTo(i, vertSplit)
process.stdout.cursorTo(i+1, vertSplit)
process.stdout.write(`=`)
}
process.stdout.cursorTo(0,0)
process.stdout.write("Players:")
const games = info[0]
@ -51,6 +53,11 @@ for (var i = 0; i < templogs.length; i++ ) {
}
}
function logRight(line, text) {
rightView[line] = text;
updateLog();
}
function log(string, color) {
if (mode) return console.log(string)
if (string == undefined) return;
@ -120,4 +127,4 @@ if (players != undefined) {
}
module.exports = {log, updateLog, setInfo, setMode}
module.exports = {log, updateLog, setInfo, setMode, logRight}

View file

@ -15,7 +15,7 @@ export function renderTiles() { // DRAW THE IMAGE TO THE CANVAS.
const tileSize = game.tileSize;
for(x = 0; x < gridSize[0]; x++){
for(y = 0; y < gridSize[1]; y++){
const xu = x*tileSize + animation.get();
const xu = x*tileSize;
const yu = y*tileSize;
const tempWorld = game.world;
// Draw buildings

View file

@ -40,8 +40,6 @@ function getMousePosition(canvas, event) {
const rect = canvas.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
// const xu = Math.floor(x/tileSize)
// const yu = Math.floor(y/tileSize)
const xu = cursor.x
const yu = cursor.y

View file

@ -56,8 +56,3 @@ socket.on('sync', function (sync){
game.world = sync.world;
render()
})
window.onbeforeunload = function(){
game.world = []
}

View file

@ -20,6 +20,7 @@ canvas {
width: 100px;
height: 437px;
background: darkolivegreen;
}
.right{
@ -29,6 +30,7 @@ canvas {
width: 100px;
height: 437px;
background: darkolivegreen;
}
.top {
@ -36,6 +38,7 @@ position: absolute;
background: salmon;
width: 632px;
height: 50px;
}
.bottom{
@ -44,6 +47,7 @@ height: 50px;
width:632px;
height:100px;
transform: translate(0, 486px);
}