Skip to content

Commit

Permalink
Improve webpack. Use seperated phaser.min.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ganlvtech committed Jan 25, 2019
1 parent 1250c05 commit fcb5d3e
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 34 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "src/index.js",
"scripts": {
"build": "webpack --config webpack.config.js",
"build": "webpack --config webpack.config.js --mode=production",
"dev": "webpack-dev-server --config webpack.config.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
4 changes: 4 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
</style>
</head>
<body>
<script src="phaser.min.js"></script>
<script src="bundle.js"></script>
<script>
window.game = new CatchTheCatGame(11, 11, 20);
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class CatchTheCatGame extends Phaser.Game {
type: Phaser.AUTO,
parent: parent,
backgroundColor: 0xeeeeee,
scene: scene
scene: scene,
};
super(config);
this.mainScene = scene;
Expand Down
6 changes: 1 addition & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/// <reference path="./phaser.d.ts"/>

import "phaser";
import CatchTheCatGame from "./game";

window.addEventListener("load", () => {
let game = new CatchTheCatGame(11, 11, 20);
window["game"] = game;
});
window["CatchTheCatGame"] = CatchTheCatGame;
1 change: 0 additions & 1 deletion src/scenes/mainScene.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as Phaser from "phaser";
import data from "../data";
import Cat from "../sprites/cat";
import Block from "../sprites/block";
Expand Down
14 changes: 10 additions & 4 deletions src/solvers/defaultSolver.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import MainScene from "../scenes/mainScene";

export default function defaultSolver(blocksIsWall: boolean[][], i: number, j: number): number {
let result = -1;
let neighbours = MainScene.getNeighbours(i, j);
return neighbours.findIndex(neighbour => {
return (blocksIsWall[neighbour.i] !== undefined
&& blocksIsWall[neighbour.i][neighbour.j] !== undefined
&& !blocksIsWall[neighbour.i][neighbour.j]);
neighbours.forEach((neighbour, direction) => {
if (direction == -1) {
if (blocksIsWall[neighbour.i] !== undefined
&& blocksIsWall[neighbour.i][neighbour.j] !== undefined
&& !blocksIsWall[neighbour.i][neighbour.j]) {
result = direction;
}
}
});
return result;
}
5 changes: 2 additions & 3 deletions src/sprites/block.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as Phaser from 'phaser';
import MainScene from "../scenes/mainScene";

export default class Block extends Phaser.GameObjects.Arc {
Expand All @@ -17,8 +16,8 @@ export default class Block extends Phaser.GameObjects.Arc {

let shape = new Phaser.Geom.Circle(this.r / 2, this.r / 2, this.r);
this.setInteractive(shape, Phaser.Geom.Circle.Contains);
this.on('pointerdown', () => {
this.emit('player_click', this.i, this.j);
this.on("pointerdown", () => {
this.emit("player_click", this.i, this.j);
});
}

Expand Down
1 change: 0 additions & 1 deletion src/sprites/cat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as Phaser from "phaser";
import MainScene from "../scenes/mainScene";
import data from "../data";
import defaultSolver from "../solvers/defaultSolver";
Expand Down
1 change: 0 additions & 1 deletion src/sprites/resetButton.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as Phaser from 'phaser';
import MainScene from "../scenes/mainScene";
import _ from "../i18n";

Expand Down
1 change: 0 additions & 1 deletion src/sprites/statusBar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as Phaser from "phaser";
import MainScene from "../scenes/mainScene";

export default class StatusBar extends Phaser.GameObjects.Text {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "ES2017",
"target": "ES5",
"module": "CommonJs"
}
}
19 changes: 4 additions & 15 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const pathToPhaser = path.join(__dirname, '/node_modules/phaser/');
const phaser = path.join(pathToPhaser, 'dist/phaser.js');

module.exports = {
mode: 'development',
Expand All @@ -28,28 +25,20 @@ module.exports = {
presets: ['@babel/preset-env']
}
}
},
{
test: /\.svg$/,
loader: 'svg-inline-loader'
},
{
test: /phaser\.js$/,
loader: 'expose-loader?Phaser'
}
]
},
plugins: [
new CopyWebpackPlugin([
{
from: 'public'
},
{
from: 'node_modules/phaser/dist/phaser.min.js'
}
])
],
resolve: {
extensions: ['.ts', '.js'],
alias: {
phaser: phaser
}
extensions: ['.ts', '.js']
}
};

0 comments on commit fcb5d3e

Please sign in to comment.