Skip to content

Commit a0cdf72

Browse files
committed
fixes: tests, editor
1 parent d665e7e commit a0cdf72

File tree

6 files changed

+57
-18
lines changed

6 files changed

+57
-18
lines changed

editor/scripts/game.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,6 @@ function loadResources()
1111
function loadScene()
1212
{
1313
game.debug = true;
14-
game.inputManager.setOnMouseDown(function() {
15-
if (game.inputManager.isKeyDown(__RECTANGLE_GRAB_BUTTON)) {
16-
var tb = game.getCurrentScene().getEntity(__GUIMANAGER_DEBUG_PANEL_NAME).getChildAt(6);
17-
var name = "";
18-
if (RectangleEditor.currently_selected)
19-
name = RectangleEditor.currently_selected.name;
20-
tb.getChildAt(0).textBox.value(name);
21-
}
22-
});
2314
editor.toggleDebugPanel();
2415
}
2516

editor/scripts/jscf-editor.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ function JSCFEditor (game)
4242
this.createEditor = function(editor_id, script_object, useWebWorker)
4343
{
4444
// fetch script
45-
const COMMENT = ""; // "// WARNING! scripting anonymous functions may be fatal here!\r\n";
46-
document.getElementById(editor_id).innerHTML = COMMENT + script_object;
45+
const COMMENT = ""; // "// this = " + script_object.constructor.name;
46+
document.getElementById(editor_id).innerHTML = COMMENT + "\n" + script_object;
4747

4848
//create editor
4949
var editor = ace.edit(editor_id);
@@ -389,6 +389,21 @@ function JSCFEditor (game)
389389
};
390390
panel.insertChild(addBtn);
391391

392+
// delete button
393+
var delBtn = guim.createDefaultButton(0, 0, "Delete");
394+
delBtn.getComponentOfType(ButtonHandler).onClick = function() {
395+
if (obj.constructor.component_name) {
396+
obj.parent.delComponent(obj.name);
397+
} else {
398+
if (obj.parent)
399+
obj.parent.delEntity(obj.name);
400+
else
401+
game.getCurrentScene().delEntity(obj.name);
402+
}
403+
SceneUtils.deleteParent(game, delBtn);
404+
};
405+
panel.insertChild(delBtn);
406+
392407
// close button
393408
var closeBtn = guim.createDefaultButton(0, 0, "Close");
394409
closeBtn.getComponentOfType(ButtonHandler).onClick = function() {
@@ -416,11 +431,13 @@ function JSCFEditor (game)
416431
var guim = game.guiManager;
417432

418433
const PANEL_WIDTH = guim.theme.getSize("panel", "width");
434+
const PANEL_HEIGHT = guim.theme.getSize("panel","height");
419435
const DP_WIDTH = PANEL_WIDTH + guim.theme.getSize("panel", "margin");
420436
const COMPONENT_LIST = [ LayoutHandler, ButtonHandler, Script, Collider, Rigidbody, RectangleEditor ];
421437

422438
var addWindow = guim.createDefaultWindow(DP_WIDTH*2, PANEL_WIDTH);
423439
addWindow.name = guim.generateUIName(__JSCFEDITOR_ADD_WINDOW_NAME);
440+
addWindow.setDimentions(PANEL_WIDTH,PANEL_HEIGHT/2);
424441
addWindow.addComponent(LayoutHandler);
425442
addWindow.getComponentOfType(LayoutHandler).layoutType = FitLayout;
426443

@@ -441,6 +458,14 @@ function JSCFEditor (game)
441458
addWindow.insertChild(btn);
442459
}
443460

461+
addWindow.insertChild(guim.createLabel(0,0,"prefabs"));
462+
463+
var entityBtn = guim.createDefaultButton(0,0,"Empty Entity",function() {
464+
obj.insertChild(new Entity(game, game.getCurrentScene().getEntityName(), true, 0,0, true));
465+
closeFn();
466+
});
467+
addWindow.insertChild(entityBtn);
468+
444469
var planeBtn = guim.createDefaultButton(0,0,"Plane",function() {
445470
obj.insertChild(new Plane(game,100,100,"black"));
446471
closeFn();
@@ -519,6 +544,16 @@ function JSCFEditor (game)
519544
game.inputManager.setOnKeyUpSpec(__JSCFEDITOR_KB_DEV_TOGGLE, function() {
520545
self.toggleDebugPanel();
521546
});
547+
548+
game.inputManager.setOnMouseDown(function() {
549+
if (game.inputManager.isKeyDown(__RECTANGLE_GRAB_BUTTON)) {
550+
var tb = game.getCurrentScene().getEntity(__GUIMANAGER_DEBUG_PANEL_NAME).getChildAt(6);
551+
var name = "";
552+
if (RectangleEditor.currently_selected)
553+
name = RectangleEditor.currently_selected.name;
554+
tb.getChildAt(0).textBox.value(name);
555+
}
556+
});
522557
}
523558

524559
this.init();

jscf/components/buttonHandler.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const __BUTTON_HANDLER_NAME = "[builtin_button_handler]";
66
const __BUTTON_HANDLER_HOVER_SPEED = 1.1;
77
const __BUTTON_HANDLER_HOVER_MAX = 1.5;
8+
const __BUTTON_HANDLER_ESCAPE_BUTTON = 17; // ctrl
89

910
/**
1011
* @class
@@ -47,6 +48,7 @@ function ButtonHandler(owner, speed)
4748
var mx = owner.game.inputManager.getMouseX();
4849
var my = owner.game.inputManager.getMouseY();
4950
var mDown = owner.game.inputManager.isMouseDown();
51+
var grabbed = owner.game.inputManager.isKeyDown(__BUTTON_HANDLER_ESCAPE_BUTTON);
5052

5153
if (this.bb.containsPoint(mx, my) && owner.game.guiManager.focus()) {
5254
if (transform.scale.length() < __BUTTON_HANDLER_HOVER_MAX)
@@ -60,7 +62,8 @@ function ButtonHandler(owner, speed)
6062

6163
if (this.pressed && !mDown) {
6264
this.pressed = false;
63-
this.onClick();
65+
if (!grabbed)
66+
this.onClick();
6467
}
6568
};
6669

jscf/components/layoutHandler.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ var LayoutHandler = function(owner)
3838
this.layoutType.doLayout(this.parent);
3939
this.update = null;
4040
};
41+
42+
/**
43+
* updates dimensions in a layout conserving way
44+
*
45+
* @param {Number} w width
46+
* @param {Number} h height
47+
*/
48+
this.setDimentions = function(w,h)
49+
{
50+
this.layoutType.doLayout(this.parent);
51+
};
4152
};
4253

4354
/**

jscf/scene/scene.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
function Scene(game)
99
{
1010

11+
this.max_euid = 0;
12+
this.entities = {};
13+
this.entities_keys = [];
14+
1115
/**
1216
* is scene paused
1317
*
@@ -266,10 +270,6 @@ function Scene(game)
266270

267271
this.init = function()
268272
{
269-
var self = this;
270-
this.max_euid = 0;
271-
this.entities = {};
272-
this.entities_keys = [];
273273
InputManager.droppedFileCallback = this.onFileDrop.bind(this);
274274
};
275275

jscf/ui/gui.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@ function GuiManager(game, utheme)
313313
if (!ents.hasOwnProperty(e))
314314
continue;
315315

316-
var hasComponent = (ents[e].hasComponentOfType(RectangleEditor));
317-
if (ents[e].name != __GUIMANAGER_DEBUG_PANEL_NAME && !hasComponent)
316+
if (!(ents[e].hasComponentOfType(RectangleEditor)))
318317
ents[e].addComponent(RectangleEditor);
319318
}
320319
};

0 commit comments

Comments
 (0)