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 path = require('path')
const { app, BrowserWindow, ipcMain } = require("electron");
const path = require("path");
require('electron-reload')(__dirname, {
electron: path.join(__dirname, 'node_modules', '.bin', 'electron')
require("electron-reload")(__dirname, {
electron: path.join(__dirname, "node_modules", ".bin", "electron")
});
function createWindow () {
@ -10,7 +10,7 @@ function createWindow () {
const win = new BrowserWindow({
width: 640,
height: 320,
backgroundColor: '#111',
backgroundColor: "#111",
resizable: false,
frame: false,
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);
});
@ -26,33 +26,33 @@ function createWindow () {
win.removeMenu();
// and load the index.html of the app.
win.loadFile(path.join('index.html'))
win.loadFile(path.join("index.html"));
// Open the DevTools.
win.webContents.openDevTools()
win.webContents.openDevTools();
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(createWindow)
app.whenReady().then(createWindow);
// 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
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
if (process.platform !== "darwin") {
app.quit();
}
})
});
app.on('activate', () => {
app.on("activate", () => {
// 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.
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
createWindow();
}
})
});
// 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.

1015
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,8 @@
"description": "",
"main": "main.js",
"scripts": {
"start": "electron ."
"start": "npm run lint && electron .",
"lint": "eslint ."
},
"author": "McArn",
"license": "ISC",
@ -13,6 +14,7 @@
},
"devDependencies": {
"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");
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 {
constructor(keys, window) {
super(texture, 24, 24);
this.scale = { x: 2, y: 2 };
constructor(keys, window) {
super(texture, 24, 24);
this.scale = { x: 2, y: 2 };
this.window = window;
this.window = window;
// Rate walking = 0.4
// Rate running = 0.08
// Rate walking = 0.4
// Rate running = 0.08
this.rate = 1;
this.direction = 1;
this.frames = [
{ x: 0, y: 1 },
{ x: 1, y: 1 },
{ x: 2, y: 1 },
{ x: 3, y: 1 }
];
this.curTime = 0;
this.curFrame = 0;
this.frame = this.frames[this.curFrame];
this.rate = 1;
this.direction = 1;
this.frames = [
{ x: 0, y: 1 },
{ x: 1, y: 1 },
{ x: 2, y: 1 },
{ x: 3, y: 1 }
];
this.curTime = 0;
this.curFrame = 0;
this.frame = this.frames[this.curFrame];
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.x = (this.window.w / 2) - (24 * this.scale.x / 2);
this.pos.y = (this.window.h / 2) - (24 * this.scale.y / 2);
this.keys = keys;
}
this.keys = keys;
}
update(dt, t) {
const { rate, frames } = this;
this.curTime += dt;
update(dt) {
const { rate, frames } = this;
this.curTime += dt;
// Change speed
if (this.keys.x || this.keys.y) {
// Walking
this.rate = 0.35;
} else {
// Standstill
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;
}
// Change speed
if (this.keys.x || this.keys.y) {
// Walking
this.rate = 0.35;
} else {
// Standstill
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;
}
}
}
module.exports = Player;

View File

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

View File

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

View File

@ -1,44 +1,44 @@
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 };
var levelData = [];
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 {
constructor (window, keys, player) {
super(levelData, levelSize.w / 32, levelSize.h / 32, 32, 32, texture);
this.pos.x = (window.w / 2) - (levelSize.w / 2);
this.pos.y = (window.h / 2) - (levelSize.h / 2);
constructor (window, keys, player) {
super(levelData, levelSize.w / 32, levelSize.h / 32, 32, 32, texture);
this.pos.x = (window.w / 2) - (levelSize.w / 2);
this.pos.y = (window.h / 2) - (levelSize.h / 2);
this.keys = keys;
this.player = player
}
this.keys = keys;
this.player = player;
}
update(dt, t) {
// Change walking direction
if (this.keys.x == -1) {
// Left
this.pos.x = this.pos.x + dt * (1 / this.player.rate) * 10;
}
if (this.keys.x == 1) {
// Right
this.pos.x = this.pos.x - dt * (1 / this.player.rate) * 10;
}
if (this.keys.y == -1) {
// Down
this.pos.y = this.pos.y + dt * (1 / this.player.rate) * 10;
}
if (this.keys.y == 1) {
// Up
this.pos.y = this.pos.y - dt * (1 / this.player.rate) * 10;
}
update(dt) {
// Change walking direction
if (this.keys.x == -1) {
// Left
this.pos.x = this.pos.x + dt * (1 / this.player.rate) * 10;
}
if (this.keys.x == 1) {
// Right
this.pos.x = this.pos.x - dt * (1 / this.player.rate) * 10;
}
if (this.keys.y == -1) {
// Down
this.pos.y = this.pos.y + dt * (1 / this.player.rate) * 10;
}
if (this.keys.y == 1) {
// Up
this.pos.y = this.pos.y - dt * (1 / this.player.rate) * 10;
}
}
}
module.exports = Level;