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

2
.gitignore vendored
View file

@ -1,2 +1,2 @@
/dist
/node_modules
/dist/bundle.js

33
dist/index.html vendored
View file

@ -1,33 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>RPGedit</title>
<style type="text/css">
html, body {
width: 100%;
height: 100%;
}
body {
text-align: center;
}
canvas {
position: relative;
top: calc(50% - 384px);
}
* {
margin: 0px;
padding: 0px;
border: 0px;
background: #223;
}
</style>
</head>
<body>
<canvas id="rpgedit" width="1024" height="768"></canvas>
<script src="bundle.js"></script>
</body>
</html>

5
electron-webpack.json Normal file
View file

@ -0,0 +1,5 @@
{
"renderer": {
"webpackConfig": "webpack.renderer.js"
}
}

View file

@ -1,18 +1,18 @@
{
"private": true,
"main": "dist/main.js",
"scripts": {
"start": "webpack-dev-server",
"build": "webpack"
"start": "electron-webpack dev"
},
"devDependencies": {
"@types/gl-matrix": "^2.4.4",
"electron": "^4.0.0-beta.8",
"electron-webpack": "^2.6.1",
"electron-webpack-ts": "^3.1.0",
"raw-loader": "^0.5.1",
"ts-loader": "^5.3.1",
"tslint": "^5.11.0",
"typescript": "^3.2.2",
"webpack": "^4.27.1",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.10"
"webpack": "^4.27.1"
},
"dependencies": {
"gl-matrix": "^2.8.1"

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();
});

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) => {

View file

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View file

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

Before

Width:  |  Height:  |  Size: 155 B

After

Width:  |  Height:  |  Size: 155 B

View file

Before

Width:  |  Height:  |  Size: 528 B

After

Width:  |  Height:  |  Size: 528 B

View file

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

Before

Width:  |  Height:  |  Size: 1 KiB

After

Width:  |  Height:  |  Size: 1 KiB

View file

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

Before

Width:  |  Height:  |  Size: 930 B

After

Width:  |  Height:  |  Size: 930 B

View file

Before

Width:  |  Height:  |  Size: 927 B

After

Width:  |  Height:  |  Size: 927 B

View file

Before

Width:  |  Height:  |  Size: 765 B

After

Width:  |  Height:  |  Size: 765 B

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -1,8 +1,3 @@
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"target": "ES2015",
"strict": true
}
"extends": "./node_modules/electron-webpack/tsconfig-base.json"
}

View file

@ -1,38 +0,0 @@
const path = require('path');
module.exports = (env, argv) => {
let config = {
entry: './src/index.ts',
devServer: {
contentBase: './dist'
},
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.(vs|fs)$/,
use: [
'raw-loader'
]
}
]
},
resolve: {
extensions: [ ".ts", ".js" ]
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
};
if (argv.mode === 'development') {
config.devtool = 'eval-source-map';
}
return config;
};

12
webpack.renderer.js Normal file
View file

@ -0,0 +1,12 @@
module.exports = {
module: {
rules: [
{
test: /\.(vs|fs)$/,
use: [
'raw-loader'
]
}
]
}
}

2979
yarn.lock

File diff suppressed because it is too large Load diff