Skip to content

Commit

Permalink
Lint + fix
Browse files Browse the repository at this point in the history
  • Loading branch information
martinstarkov committed May 22, 2024
1 parent 337035b commit fc969a7
Show file tree
Hide file tree
Showing 25 changed files with 1,237 additions and 954 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"webpack/*",
"pwa/*",
"@types/*",
"typings/*",
"tsconfig.json",
],
"rules": {
Expand Down
73 changes: 38 additions & 35 deletions src/electron/main.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/* eslint-disable no-undef */
/* eslint @typescript-eslint/no-var-requires: "off" */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { app, protocol, BrowserWindow, ipcMain } = require('electron')
const path = require('path')
const { app, protocol, BrowserWindow, ipcMain } = require('electron');
const path = require('path');

process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';

// NOTE: Change these file paths if you change the file structure.
const packageJsonPath = '../../package.json'
const htmlEntryPath = '../../dist/index.html'
const electronPreloadPath = 'preload.js'
const packageJsonPath = '../../package.json';
const htmlEntryPath = '../../dist/index.html';
const electronPreloadPath = 'preload.js';

const localHostURL = 'http://localhost:3000'
const localHostURL = 'http://localhost:3000';

const packageJson = require(path.join(__dirname, packageJsonPath))
const packageJson = require(path.join(__dirname, packageJsonPath));

const capitalize = s => (s && s[0].toUpperCase() + s.slice(1)) || ''
const capitalize = s => (s && s[0].toUpperCase() + s.slice(1)) || '';

const windowProperties = {
title: capitalize(packageJson.name), // Use the name property of package.json as there window title.
Expand All @@ -27,8 +27,8 @@ const windowProperties = {
maximize: true,
center: true,
stealFocus: true, // Required otherwise alt-tabbing causes huge desync of audio and visuals.
openDevTools: false
}
openDevTools: false,
};

// At one point this was needed for something but now it seems obsolete.
// Leaving it in case commenting it broke something that will later need to be fixed.
Expand All @@ -39,18 +39,21 @@ protocol.registerSchemesAsPrivileged([
standard: true,
secure: true,
stream: true,
bypassCSP: true
}
}
])
bypassCSP: true,
},
},
]);

// Let electron reload by itself.
if (process.env.ELECTRON_DEBUG === 'true' || process.env.ELECTRON_DEBUG === 'vscode') {
const electronReload = require('electron-reload')
electronReload(__dirname, {})
if (
process.env.ELECTRON_DEBUG === 'true' ||
process.env.ELECTRON_DEBUG === 'vscode'
) {
const electronReload = require('electron-reload');
electronReload(__dirname, {});
}

let mainWindow = undefined
let mainWindow = undefined;

function createWindow() {
// Create the browser window.
Expand All @@ -69,50 +72,50 @@ function createWindow() {
preload: path.join(__dirname, electronPreloadPath),
contextIsolation: true,
nodeIntegration: true,
webSecurity: false
webSecurity: false,
// allowRunningInsecureContent: true,
}
})
},
});
if (windowProperties.maximize) {
mainWindow.maximize()
mainWindow.maximize();
}

// Hot reload.
if (process.env.ELECTRON_HOT === 'true') {
mainWindow.loadURL(localHostURL)
mainWindow.loadURL(localHostURL);
} else {
mainWindow.loadFile(path.join(__dirname, htmlEntryPath))
mainWindow.loadFile(path.join(__dirname, htmlEntryPath));
}

if (process.env.ELECTRON_DEBUG === 'true' && windowProperties.openDevTools) {
mainWindow.webContents.openDevTools()
mainWindow.webContents.openDevTools();
}

// Maintain aspect ratio when scaling.
mainWindow.setAspectRatio(windowProperties.aspectRatio)
app.focus({ steal: windowProperties.stealFocus })
mainWindow.setAspectRatio(windowProperties.aspectRatio);
app.focus({ steal: windowProperties.stealFocus });
}

// 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.on('ready', createWindow)
app.on('ready', createWindow);

// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On OS X 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()
app.quit();
}
})
});

app.on('activate', () => {
// On OS X it is 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()
})
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});

ipcMain.handle('get-app-path', () => {
return app.getAppPath()
})
return app.getAppPath();
});
12 changes: 7 additions & 5 deletions src/ts/core/common.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable no-async-promise-executor */
import { Vector2 } from '../core/phaserTypes';
import { debugMode } from './config';

export function initVariables(): Promise<void> {
return new Promise<void>((resolve, reject) => {
return new Promise<void>((resolve, _reject) => {
resolve();
});
}
Expand All @@ -16,16 +18,16 @@ export function isDebugMode(): boolean {
}

export function storeData(
filePath: string,
data: string | NodeJS.ArrayBufferView,
_filePath: string,
_data: string | NodeJS.ArrayBufferView,
): void {
// fs.mkdirSync(path.dirname(filePath), { recursive: true })
// fs.writeFileSync(filePath, data)
}

function makeRequest(method, url) {
return new Promise(function (resolve, reject) {
let xhr = new XMLHttpRequest();
const xhr = new XMLHttpRequest();
xhr.open(method, url);
xhr.onload = function () {
if (this.status >= 200 && this.status < 300) {
Expand Down Expand Up @@ -76,7 +78,7 @@ export function listLevelDirectories(
//return fs.readdirSync(parentDir, { withFileTypes: true }).filter(dirent => dirent.isDirectory()).map(dirent => dirent.name)
}

export function fileExists(absoluteFilePath: string): boolean {
export function fileExists(_absoluteFilePath: string): boolean {
return true;
//return fs.existsSync(absoluteFilePath)
}
Expand Down
35 changes: 22 additions & 13 deletions src/ts/core/game.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Phaser from 'phaser'
import { LoadingScene, ElectronScene } from '../scenes/loadingScene'
import LevelScene from '../scenes/levelScene'
import MainMenu from '../scenes/mainMenuScene'
import LevelSelect from '../scenes/levelSelectScene'
import Options from '../scenes/optionsScene'
import Scoreboard from '../scenes/scoreboardScene'
import Calibration from '../scenes/calibrationScene'
import Phaser from 'phaser';
import { LoadingScene, ElectronScene } from '../scenes/loadingScene';
import LevelScene from '../scenes/levelScene';
import MainMenu from '../scenes/mainMenuScene';
import LevelSelect from '../scenes/levelSelectScene';
import Options from '../scenes/optionsScene';
import Scoreboard from '../scenes/scoreboardScene';
import Calibration from '../scenes/calibrationScene';

/*
To add a new scene:
Expand All @@ -24,10 +24,19 @@ const config = {
default: 'matter',
matter: {
debug: false,
gravity: { x: 0, y: 0 }
}
gravity: { x: 0, y: 0 },
},
},
scene: [ElectronScene, LoadingScene, MainMenu, Options, LevelSelect, LevelScene, Scoreboard, Calibration]
}
scene: [
ElectronScene,
LoadingScene,
MainMenu,
Options,
LevelSelect,
LevelScene,
Scoreboard,
Calibration,
],
};

const _game = new Phaser.Game(config)
const _game = new Phaser.Game(config);
Loading

0 comments on commit fc969a7

Please sign in to comment.