Create Electron app

This commit is contained in:
Matthias Schiffer 2018-12-08 12:39:18 +01:00
parent 439dcf3917
commit b3950330e3
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
65 changed files with 3039 additions and 135 deletions

51
src/main/index.ts Normal file
View file

@ -0,0 +1,51 @@
import { app, BrowserWindow } from 'electron';
import * as path from 'path';
import { format as formatUrl } from 'url';
const isDevelopment = process.env.NODE_ENV !== 'production';
let mainWindow: BrowserWindow|null = null;
function getIndexURL(): string {
if (isDevelopment)
return `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`;
return formatUrl({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file',
slashes: true,
});
}
function createMainWindow(): BrowserWindow {
const window = new BrowserWindow();
if (isDevelopment)
window.webContents.openDevTools();
window.loadURL(getIndexURL());
window.on('closed', () => {
mainWindow = null;
});
window.webContents.on('devtools-opened', () => {
window.webContents.focus();
});
return window;
}
app.on('window-all-closed', () => {
if (process.platform !== 'darwin')
app.quit();
});
app.on('activate', () => {
if (!mainWindow)
mainWindow = createMainWindow();
});
app.on('ready', () => {
mainWindow = createMainWindow();
});

9
src/renderer/custom.d.ts vendored Normal file
View file

@ -0,0 +1,9 @@
declare module "*.vs" {
const content: string;
export default content;
}
declare module "*.fs" {
const content: string;
export default content;
}

20
src/renderer/index.css Normal file
View file

@ -0,0 +1,20 @@
html, body, div {
width: 100%;
height: 100%;
}
#app {
text-align: center;
}
canvas {
position: relative;
top: calc(50% - 384px);
}
* {
margin: 0px;
padding: 0px;
border: 0px;
background: #223;
}

View file

@ -1,12 +1,20 @@
import './index.css';
import { GameContext } from './controller/gamecontext';
import { Renderer } from './view/renderer/renderer';
window.onload = async () => {
const canvas = document.getElementById('rpgedit') as HTMLCanvasElement;
if (!canvas)
const app = document.getElementById('app');
if (!app)
return;
const canvas = document.createElement('canvas');
canvas.width = 1024;
canvas.height = 768;
app.append(canvas);
const renderer = new Renderer(canvas);
GameContext.load(renderer);

View file

@ -7,8 +7,6 @@ import { MapData } from '../model/data/map';
import { nextPowerOf2 } from '../util';
import { vec2 } from 'gl-matrix';
interface StaticMapTile {
type: 'static';
image: HTMLImageElement;

View file

@ -1,5 +1,4 @@
import { Renderer } from '../renderer/renderer';
import { SpriteCoords } from '../sprite';
export function loadImage(url: string): Promise<HTMLImageElement> {
return new Promise((resolve, reject) => {