Initialized eslint and fixed linting issues

This commit is contained in:
corner 2020-03-15 17:31:32 +01:00
parent 1f055471d3
commit 98462b4c3f
8 changed files with 1175 additions and 132 deletions

34
.eslintrc.js Normal file
View File

@ -0,0 +1,34 @@
module.exports = {
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
]
}
};

32
main.js
View File

@ -1,8 +1,8 @@
const { app, BrowserWindow, ipcMain } = require('electron') const { app, BrowserWindow, ipcMain } = require("electron");
const path = require('path') const path = require("path");
require('electron-reload')(__dirname, { require("electron-reload")(__dirname, {
electron: path.join(__dirname, 'node_modules', '.bin', 'electron') electron: path.join(__dirname, "node_modules", ".bin", "electron")
}); });
function createWindow () { function createWindow () {
@ -10,7 +10,7 @@ function createWindow () {
const win = new BrowserWindow({ const win = new BrowserWindow({
width: 640, width: 640,
height: 320, height: 320,
backgroundColor: '#111', backgroundColor: "#111",
resizable: false, resizable: false,
frame: false, frame: false,
webPreferences: { webPreferences: {
@ -18,7 +18,7 @@ function createWindow () {
} }
}); });
ipcMain.on('resize', function (event, window) { ipcMain.on("resize", function (event, window) {
win.setSize( window.w, window.h); win.setSize( window.w, window.h);
}); });
@ -26,33 +26,33 @@ function createWindow () {
win.removeMenu(); win.removeMenu();
// and load the index.html of the app. // and load the index.html of the app.
win.loadFile(path.join('index.html')) win.loadFile(path.join("index.html"));
// Open the DevTools. // Open the DevTools.
win.webContents.openDevTools() win.webContents.openDevTools();
} }
// This method will be called when Electron has finished // This method will be called when Electron has finished
// initialization and is ready to create browser windows. // initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs. // Some APIs can only be used after this event occurs.
app.whenReady().then(createWindow) app.whenReady().then(createWindow);
// Quit when all windows are closed. // Quit when all windows are closed.
app.on('window-all-closed', () => { app.on("window-all-closed", () => {
// On macOS it is common for applications and their menu bar // On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q // to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') { if (process.platform !== "darwin") {
app.quit() app.quit();
} }
}) });
app.on('activate', () => { app.on("activate", () => {
// On macOS it's common to re-create a window in the app when the // On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open. // dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) { if (BrowserWindow.getAllWindows().length === 0) {
createWindow() createWindow();
} }
}) });
// In this file you can include the rest of your app's specific main process // In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here. // code. You can also put them in separate files and require them here.

1015
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,8 @@
"description": "", "description": "",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {
"start": "electron ." "start": "npm run lint && electron .",
"lint": "eslint ."
}, },
"author": "McArn", "author": "McArn",
"license": "ISC", "license": "ISC",
@ -13,6 +14,7 @@
}, },
"devDependencies": { "devDependencies": {
"electron": "^8.0.2", "electron": "^8.0.2",
"electron-reload": "^1.5.0" "electron-reload": "^1.5.0",
"eslint": "^6.8.0"
} }
} }

View File

@ -1,81 +1,81 @@
var asdf = require("asdf-games"); var asdf = require("asdf-games");
const { math, KeyControls, Texture, Sprite, TileSprite } = asdf; const { Texture, TileSprite } = asdf;
var texture = new Texture('./res/player.png'); var texture = new Texture("./res/player.png");
class Player extends TileSprite { class Player extends TileSprite {
constructor(keys, window) { constructor(keys, window) {
super(texture, 24, 24); super(texture, 24, 24);
this.scale = { x: 2, y: 2 }; this.scale = { x: 2, y: 2 };
this.window = window; this.window = window;
// Rate walking = 0.4 // Rate walking = 0.4
// Rate running = 0.08 // Rate running = 0.08
this.rate = 1; this.rate = 1;
this.direction = 1; this.direction = 1;
this.frames = [ this.frames = [
{ x: 0, y: 1 }, { x: 0, y: 1 },
{ x: 1, y: 1 }, { x: 1, y: 1 },
{ x: 2, y: 1 }, { x: 2, y: 1 },
{ x: 3, y: 1 } { x: 3, y: 1 }
]; ];
this.curTime = 0; this.curTime = 0;
this.curFrame = 0; this.curFrame = 0;
this.frame = this.frames[this.curFrame]; this.frame = this.frames[this.curFrame];
this.pos.x = (this.window.w / 2) - (24 * this.scale.x / 2); this.pos.x = (this.window.w / 2) - (24 * this.scale.x / 2);
this.pos.y = (this.window.h / 2) - (24 * this.scale.y / 2); this.pos.y = (this.window.h / 2) - (24 * this.scale.y / 2);
this.keys = keys; this.keys = keys;
} }
update(dt, t) { update(dt) {
const { rate, frames } = this; const { rate, frames } = this;
this.curTime += dt; this.curTime += dt;
// Change speed // Change speed
if (this.keys.x || this.keys.y) { if (this.keys.x || this.keys.y) {
// Walking // Walking
this.rate = 0.35; this.rate = 0.35;
} else { } else {
// Standstill // Standstill
this.curFrame = 0; this.curFrame = 0;
}
if (this.keys.action && (this.keys.x || this.keys.y)) {
// Running
this.rate = 0.08;
}
// Change walking direction
if (this.keys.x == -1) {
// Left
this.direction = 3;
}
if (this.keys.x == 1) {
// Right
this.direction = 2;
}
if (this.keys.y == -1) {
// Down
this.direction = 0;
}
if (this.keys.y == 1) {
// Up
this.direction = 1;
}
this.frames.forEach(element => {
element.y = this.direction;
});
// Animate
if (this.curTime > rate) {
this.frame = frames[this.curFrame++ % frames.length];
this.curTime -= rate;
}
} }
if (this.keys.action && (this.keys.x || this.keys.y)) {
// Running
this.rate = 0.08;
}
// Change walking direction
if (this.keys.x == -1) {
// Left
this.direction = 3;
}
if (this.keys.x == 1) {
// Right
this.direction = 2;
}
if (this.keys.y == -1) {
// Down
this.direction = 0;
}
if (this.keys.y == 1) {
// Up
this.direction = 1;
}
this.frames.forEach(element => {
element.y = this.direction;
});
// Animate
if (this.curTime > rate) {
this.frame = frames[this.curFrame++ % frames.length];
this.curTime -= rate;
}
}
} }
module.exports = Player; module.exports = Player;

View File

@ -1,19 +1,19 @@
const { ipcRenderer, remote } = require('electron') const { ipcRenderer, remote } = require("electron");
var asdf = require('asdf-games'); var asdf = require("asdf-games");
const { Game, Container, math, KeyControls, MouseControls, Text, Texture, TileMap, Sprite, TileSprite } = asdf; const { Game, KeyControls, MouseControls } = asdf;
const window = { w: 640, h: 320 }; const window = { w: 640, h: 320 };
const game = new Game(window.w, window.h, true); const game = new Game(window.w, window.h, true);
ipcRenderer.send('resize', window); ipcRenderer.send("resize", window);
const { scene, w, h } = game; const { scene } = game;
var Player = require("./src/entities/player.js") var Player = require("./src/entities/player.js");
var Level = require("./src/levels/level.js") var Level = require("./src/levels/level.js");
const mouseAim = new MouseControls(document.getElementById('board')); const mouseAim = new MouseControls(document.getElementById("board"));
const keys = new KeyControls(); const keys = new KeyControls();
var player = new Player(keys, window); var player = new Player(keys, window);
@ -22,9 +22,9 @@ var level = new Level(window, keys, player);
scene.add(level); scene.add(level);
scene.add(player); scene.add(player);
game.run((dt ,t) => { game.run(() => {
if (mouseAim.isDown) { if (mouseAim.isDown) {
console.log('cliccccccccccc'); console.log("cliccccccccccc");
} }
// Check gamestate // Check gamestate
@ -36,17 +36,17 @@ game.run((dt ,t) => {
********************************************************* */ ********************************************************* */
// Opening and closing of menu. // Opening and closing of menu.
document.getElementById('settings').addEventListener('click', () => { document.getElementById("settings").addEventListener("click", () => {
const menuRef = document.getElementById('menu'); const menuRef = document.getElementById("menu");
menuRef.style.display = menuRef.style.display === "block" ? "none" : "block"; menuRef.style.display = menuRef.style.display === "block" ? "none" : "block";
}); });
// Quit Game handling. // Quit Game handling.
document.getElementById('close').addEventListener('click', () => { document.getElementById("close").addEventListener("click", () => {
remote.app.quit(); remote.app.quit();
}); });
// Return to main menu button // Return to main menu button
document.getElementById('mainmenu').addEventListener('click', () => { document.getElementById("mainmenu").addEventListener("click", () => {
remote.getCurrentWindow().loadFile(__dirname + "/index.html"); remote.getCurrentWindow().loadFile(__dirname + "/index.html");
}); });

View File

@ -3,12 +3,12 @@ const { remote } = require("electron");
document.addEventListener("DOMContentLoaded", () => { document.addEventListener("DOMContentLoaded", () => {
// Start game // Start game
document.getElementById('resume').addEventListener("click", () => { document.getElementById("resume").addEventListener("click", () => {
remote.getCurrentWindow().loadFile(__dirname + "/game.html"); remote.getCurrentWindow().loadFile(__dirname + "/game.html");
}); });
// Quit game // Quit game
document.getElementById('quit').addEventListener("click", () => { document.getElementById("quit").addEventListener("click", () => {
remote.app.quit(); remote.app.quit();
}); });
}); });

View File

@ -1,44 +1,44 @@
var asdf = require("asdf-games"); var asdf = require("asdf-games");
const { math, KeyControls, Texture, Sprite, TileSprite, TileMap } = asdf; const { Texture, TileMap } = asdf;
const texture = new Texture('./res/placeholder.png'); const texture = new Texture("./res/placeholder.png");
const levelSize = { w: 640, h: 320 }; const levelSize = { w: 640, h: 320 };
var levelData = []; var levelData = [];
for (let index = 0; index < ((levelSize.w / 32) * (levelSize.h / 32)); index++) { for (let index = 0; index < ((levelSize.w / 32) * (levelSize.h / 32)); index++) {
levelData.push({ x: 0, y: 0 }); levelData.push({ x: 0, y: 0 });
} }
class Level extends TileMap { class Level extends TileMap {
constructor (window, keys, player) { constructor (window, keys, player) {
super(levelData, levelSize.w / 32, levelSize.h / 32, 32, 32, texture); super(levelData, levelSize.w / 32, levelSize.h / 32, 32, 32, texture);
this.pos.x = (window.w / 2) - (levelSize.w / 2); this.pos.x = (window.w / 2) - (levelSize.w / 2);
this.pos.y = (window.h / 2) - (levelSize.h / 2); this.pos.y = (window.h / 2) - (levelSize.h / 2);
this.keys = keys; this.keys = keys;
this.player = player this.player = player;
} }
update(dt, t) { update(dt) {
// Change walking direction // Change walking direction
if (this.keys.x == -1) { if (this.keys.x == -1) {
// Left // Left
this.pos.x = this.pos.x + dt * (1 / this.player.rate) * 10; this.pos.x = this.pos.x + dt * (1 / this.player.rate) * 10;
} }
if (this.keys.x == 1) { if (this.keys.x == 1) {
// Right // Right
this.pos.x = this.pos.x - dt * (1 / this.player.rate) * 10; this.pos.x = this.pos.x - dt * (1 / this.player.rate) * 10;
} }
if (this.keys.y == -1) { if (this.keys.y == -1) {
// Down // Down
this.pos.y = this.pos.y + dt * (1 / this.player.rate) * 10; this.pos.y = this.pos.y + dt * (1 / this.player.rate) * 10;
} }
if (this.keys.y == 1) { if (this.keys.y == 1) {
// Up // Up
this.pos.y = this.pos.y - dt * (1 / this.player.rate) * 10; this.pos.y = this.pos.y - dt * (1 / this.player.rate) * 10;
}
} }
}
} }
module.exports = Level; module.exports = Level;