Skip to content

Commit 33259c9

Browse files
Scene editor: improves painting handling.
1 parent 9eab94d commit 33259c9

File tree

8 files changed

+188953
-48
lines changed

8 files changed

+188953
-48
lines changed

source/v2/phasereditor/phasereditor.scene.ui.editor.html/html/Editor.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ namespace PhaserEditor2D {
3131
}
3232

3333
repaint() {
34-
this._game.loop.step(Date.now());
34+
consoleLog("repaint");
35+
this._game.loop.tick();
3536
}
3637

3738
stop() {
@@ -274,6 +275,9 @@ namespace PhaserEditor2D {
274275
}
275276

276277
private onCreateGame(msg: any) {
278+
279+
const self = this;
280+
277281
// update the model
278282

279283
this._webgl = msg.webgl;
@@ -301,6 +305,11 @@ namespace PhaserEditor2D {
301305
}
302306
});
303307

308+
(<any>this._game.config).postBoot = function (game : Phaser.Game) {
309+
consoleLog("Game booted");
310+
setTimeout(() => self.stop(), 500);
311+
};
312+
304313
this._objectScene = new ObjectScene();
305314

306315
this._game.scene.add("ObjectScene", this._objectScene);
@@ -313,8 +322,6 @@ namespace PhaserEditor2D {
313322

314323
this._resizeToken = 0;
315324

316-
const self = this;
317-
318325
window.addEventListener('resize', function (event) {
319326
if (self._closed) {
320327
return;
@@ -340,8 +347,6 @@ namespace PhaserEditor2D {
340347
});
341348

342349
this.updateBodyColor();
343-
344-
this.stop();
345350
}
346351

347352
snapValueX(x: number) {
@@ -363,11 +368,15 @@ namespace PhaserEditor2D {
363368
}
364369

365370
private onDropObjects(msg: any) {
371+
consoleLog("onDropObjects()");
372+
366373
const list = msg.list;
367374

368375
for (let model of list) {
369376
this._create.createObject(this.getObjectScene(), model);
370377
}
378+
379+
this.repaint();
371380
}
372381

373382
private onDeleteObjects(msg) {
@@ -416,37 +425,22 @@ namespace PhaserEditor2D {
416425

417426
};
418427

419-
private _loaderIntervalID: number;
420-
421428
private onLoadAssets(index: number, list: any[]) {
422429
let loadMsg = list[index];
423430
const self = this;
424431

425432
if (loadMsg.pack) {
426433
let scene = this.getObjectScene();
427434

428-
this._loaderIntervalID = setInterval(function () {
429-
self.repaint();
430-
}, 20);
431-
432-
setTimeout(() => self.stop(), 1500);
433-
434435
scene.load.once(Phaser.Loader.Events.COMPLETE,
435436

436437
(function (index2, list2) {
437438
return function () {
438439
consoleLog("Loader complete.");
439440

440-
consoleLog("Cancel " + self._loaderIntervalID);
441-
clearInterval(self._loaderIntervalID);
442-
443441
self.processMessageList(index2, list2);
444-
445-
self.repaint();
446442
};
447443
})(index + 1, list)
448-
449-
450444
, this);
451445
consoleLog("Load: ");
452446
consoleLog(loadMsg.pack);

source/v2/phasereditor/phasereditor.scene.ui.editor.html/html/ObjectScene.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ namespace PhaserEditor2D {
2020
consoleLog("preload()");
2121
this.load.setBaseURL(this._initData.projectUrl);
2222
this.load.pack("pack", this._initData.pack);
23-
setTimeout(() => Editor.getInstance().stop(), 500);
2423
}
2524

2625
create() {
@@ -42,9 +41,9 @@ namespace PhaserEditor2D {
4241

4342
editor.sceneCreated();
4443

45-
editor.repaint();
46-
47-
this.sendRecordCameraStateMessage();
44+
this.sendRecordCameraStateMessage();
45+
46+
editor.stop();
4847
}
4948

5049
updateBackground() {

source/v2/phasereditor/phasereditor.scene.ui.editor.html/html/ToolScene.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
namespace PhaserEditor2D {
22

3-
var TICK_COUNT = 0;
3+
var PAINT_COUNT = 0;
44

55
export class ToolScene extends Phaser.Scene {
66

77

88
private _selectedObjects: Phaser.GameObjects.GameObject[];
99
private _selectionGraphics: Phaser.GameObjects.Graphics;
1010
private _gridGraphics: Phaser.GameObjects.Graphics;
11-
private _tick: Phaser.GameObjects.Text;
11+
private _paintCallsLabel: Phaser.GameObjects.Text;
1212
private _tools: InteractiveTool[];
1313

1414

@@ -40,8 +40,8 @@ namespace PhaserEditor2D {
4040

4141
this._selectionGraphics.depth = -1;
4242

43-
this._tick = this.add.text(10, 10, "");
44-
this._tick.depth = -1;
43+
this._paintCallsLabel = this.add.text(10, 10, "", {"color": "black", "backgroundColor": "white"});
44+
this._paintCallsLabel.depth = 1000;
4545
}
4646

4747
initCamera() {
@@ -231,8 +231,8 @@ namespace PhaserEditor2D {
231231
this.renderSelection();
232232
this.updateTools();
233233

234-
this._tick.text = TICK_COUNT + "";
235-
TICK_COUNT += 1;
234+
this._paintCallsLabel.text = PAINT_COUNT.toString();
235+
PAINT_COUNT += 1;
236236
}
237237

238238
setTools(tools: InteractiveTool[]) {

source/v2/phasereditor/phasereditor.scene.ui.editor.html/html/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
<script src="out/workaround.js"></script>
1313

14-
<script src="phaser/phaser.min.js"></script>
14+
<!-- <script src="phaser/phaser.min.js"></script> -->
15+
<script src="phaser/phaser.js"></script>
1516
<script src="out/Messages.js"></script>
1617
<script src="out/Editor.js"></script>
1718
<script src="out/ObjectScene.js"></script>

source/v2/phasereditor/phasereditor.scene.ui.editor.html/html/out/Editor.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ var PhaserEditor2D;
1313
return Editor._instance;
1414
};
1515
Editor.prototype.repaint = function () {
16-
this._game.loop.step(Date.now());
16+
consoleLog("repaint");
17+
this._game.loop.tick();
1718
};
1819
Editor.prototype.stop = function () {
1920
consoleLog("loop.stop");
@@ -205,6 +206,7 @@ var PhaserEditor2D;
205206
body.style.backgroundColor = "rgb(" + PhaserEditor2D.ScenePropertiesComponent.get_backgroundColor(this.sceneProperties) + ")";
206207
};
207208
Editor.prototype.onCreateGame = function (msg) {
209+
var self = this;
208210
this._webgl = msg.webgl;
209211
this._sendKeyData = msg.sendKeyData || false;
210212
this.sceneProperties = msg.sceneProperties;
@@ -225,6 +227,10 @@ var PhaserEditor2D;
225227
mode: Phaser.Scale.RESIZE
226228
}
227229
});
230+
this._game.config.postBoot = function (game) {
231+
consoleLog("Game booted");
232+
setTimeout(function () { return self.stop(); }, 500);
233+
};
228234
this._objectScene = new PhaserEditor2D.ObjectScene();
229235
this._game.scene.add("ObjectScene", this._objectScene);
230236
this._game.scene.add("ToolScene", PhaserEditor2D.ToolScene);
@@ -234,7 +240,6 @@ var PhaserEditor2D;
234240
pack: msg.pack
235241
});
236242
this._resizeToken = 0;
237-
var self = this;
238243
window.addEventListener('resize', function (event) {
239244
if (self._closed) {
240245
return;
@@ -256,7 +261,6 @@ var PhaserEditor2D;
256261
self.repaint();
257262
});
258263
this.updateBodyColor();
259-
this.stop();
260264
};
261265
Editor.prototype.snapValueX = function (x) {
262266
var props = this.sceneProperties;
@@ -275,11 +279,13 @@ var PhaserEditor2D;
275279
return y;
276280
};
277281
Editor.prototype.onDropObjects = function (msg) {
282+
consoleLog("onDropObjects()");
278283
var list = msg.list;
279284
for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
280285
var model = list_1[_i];
281286
this._create.createObject(this.getObjectScene(), model);
282287
}
288+
this.repaint();
283289
};
284290
Editor.prototype.onDeleteObjects = function (msg) {
285291
var scene = this.getObjectScene();
@@ -322,17 +328,10 @@ var PhaserEditor2D;
322328
var self = this;
323329
if (loadMsg.pack) {
324330
var scene = this.getObjectScene();
325-
this._loaderIntervalID = setInterval(function () {
326-
self.repaint();
327-
}, 20);
328-
setTimeout(function () { return self.stop(); }, 1500);
329331
scene.load.once(Phaser.Loader.Events.COMPLETE, (function (index2, list2) {
330332
return function () {
331333
consoleLog("Loader complete.");
332-
consoleLog("Cancel " + self._loaderIntervalID);
333-
clearInterval(self._loaderIntervalID);
334334
self.processMessageList(index2, list2);
335-
self.repaint();
336335
};
337336
})(index + 1, list), this);
338337
consoleLog("Load: ");

source/v2/phasereditor/phasereditor.scene.ui.editor.html/html/out/ObjectScene.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ var PhaserEditor2D;
2222
consoleLog("preload()");
2323
this.load.setBaseURL(this._initData.projectUrl);
2424
this.load.pack("pack", this._initData.pack);
25-
setTimeout(function () { return PhaserEditor2D.Editor.getInstance().stop(); }, 500);
2625
};
2726
ObjectScene.prototype.create = function () {
2827
var editor = PhaserEditor2D.Editor.getInstance();
@@ -34,8 +33,8 @@ var PhaserEditor2D;
3433
this.initSelectionScene();
3534
editor.getCreate().createWorld(this, this._initData.displayList);
3635
editor.sceneCreated();
37-
editor.repaint();
3836
this.sendRecordCameraStateMessage();
37+
editor.stop();
3938
};
4039
ObjectScene.prototype.updateBackground = function () {
4140
var rgb = "rgb(" + PhaserEditor2D.ScenePropertiesComponent.get_backgroundColor(PhaserEditor2D.Editor.getInstance().sceneProperties) + ")";

source/v2/phasereditor/phasereditor.scene.ui.editor.html/html/out/ToolScene.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var __extends = (this && this.__extends) || (function () {
1010
})();
1111
var PhaserEditor2D;
1212
(function (PhaserEditor2D) {
13-
var TICK_COUNT = 0;
13+
var PAINT_COUNT = 0;
1414
var ToolScene = (function (_super) {
1515
__extends(ToolScene, _super);
1616
function ToolScene() {
@@ -43,8 +43,8 @@ var PhaserEditor2D;
4343
}
4444
});
4545
this._selectionGraphics.depth = -1;
46-
this._tick = this.add.text(10, 10, "");
47-
this._tick.depth = -1;
46+
this._paintCallsLabel = this.add.text(10, 10, "", { "color": "black", "backgroundColor": "white" });
47+
this._paintCallsLabel.depth = 1000;
4848
};
4949
ToolScene.prototype.initCamera = function () {
5050
this.cameras.main.setRoundPixels(true);
@@ -172,8 +172,8 @@ var PhaserEditor2D;
172172
this.renderAxis();
173173
this.renderSelection();
174174
this.updateTools();
175-
this._tick.text = TICK_COUNT + "";
176-
TICK_COUNT += 1;
175+
this._paintCallsLabel.text = PAINT_COUNT.toString();
176+
PAINT_COUNT += 1;
177177
};
178178
ToolScene.prototype.setTools = function (tools) {
179179
for (var _i = 0, _a = this._tools; _i < _a.length; _i++) {

0 commit comments

Comments
 (0)