This commit is contained in:
John Alanbrook 2023-12-24 17:50:01 +00:00
parent 2f086947b9
commit 885a2fd190
5 changed files with 29 additions and 21 deletions

View file

@ -53,7 +53,7 @@ endif
CPPFLAGS += -ffast-math
ifeq ($(DBG),1)
CPPFLAGS += -g #-fsanitize=address
CPPFLAGS += -g -fsanitize=address
INFO += _dbg
else
CPPFLAGS += -DNDEBUG

View file

@ -40,6 +40,13 @@ var component = {
enable() { this.enabled = true; },
disable() { this.enabled = false; },
isComponent(c) {
if (typeof c !== 'object') return false;
if (typeof c.toString !== 'function') return false;
if (typeof c.make !== 'function') return false;
return (typeof component[c.toString()] === 'object');
},
hides: ['gameobject', 'id'],
make(go) {
@ -81,7 +88,9 @@ component.sprite.impl = {
cmd(12,this.id,x,this.rect);
},
get path() {
return cmd(116,this.id);
var s = cmd(116,this.id);
if (s === "icons/no_tex.gif") return undefined;
return s;
//return prototypes.resavi(this.gameobject.__proto__.toString(), cmd(116,this.id));
},
toString() { return "sprite"; },
@ -427,7 +436,7 @@ collider2d.inputs['M-t'] = function() { this.enabled = !this.enabled; }
collider2d.inputs['M-t'].doc = "Toggle if this collider is enabled.";
component.polygon2d = Object.copy(collider2d, {
toString() { return "poly2d"; },
toString() { return "polygon2d"; },
flipx: false,
flipy: false,

View file

@ -38,13 +38,12 @@ var editor = {
/* Tries to select id */
do_select(obj) {
if (!obj) return;
// if (!obj || !obj._ed.selectable) return undefined;
if (!obj._ed.selectable) return undefined;
if (obj.level !== this.edit_level) {
var testlevel = obj.level;
while (testlevel && testlevel.level !== this.edit_level && testlevel !== testlevel.level)
while (testlevel && testlevel.level !== Primum && testlevel.level !== this.edit_level && testlevel !== testlevel.level)
testlevel = testlevel.level;
return testlevel;
}
@ -227,6 +226,7 @@ var editor = {
}
this.selectlist = [];
editor.camera = Primum.spawn(ur.camera2d);
editor.camera._ed.selectable = false;
Game.view_camera(editor.camera);
},
@ -583,7 +583,7 @@ editor.inputs.drop = function(str) {
return;
}
if (this.selected.length === 0) {
if (this.selectlist.length === 0) {
}
@ -869,6 +869,7 @@ editor.inputs['M-t'] = function() { editor.edit_level.objects.forEach(function(x
editor.inputs['M-t'].doc = "Unlock all objects in current level.";
editor.inputs['C-n'] = function() {
return;
gameobject.make(editor.edit_level);
console.warn("MADE A NEW OBJECT");
/* if (editor.edit_level._ed.dirty) {
@ -984,14 +985,7 @@ editor.inputs.lm.released = function() {
var obj = editor.do_select(x);
if (obj)
selects.push(obj);
},editor);
var levels = editor.edit_level.objects.filter(function(x) { return x.file; });
var lvlpos = [];
levels.forEach(function(x) { lvlpos.push(x.pos); });
var lvlhits = physics.box_point_query(box, lvlpos);
lvlhits.forEach(function(x) { selects.push(levels[x]); });
});
}
this.sel_start = undefined;
@ -1101,6 +1095,7 @@ editor.inputs.mouse.move = function(pos, dpos)
}
editor.grabselect?.forEach(function(x) {
if (!x) return;
x.move(Game.camera.dir_view2world(dpos));
if ('sync' in x)
x.sync();
@ -1186,7 +1181,7 @@ editor.inputs.g = function() {
var comp = editor.sel_comp;
var o = {
pos: editor.sel_comp.pos,
move(d) { comp.pos = comp.pos.add(d); },
move(d) { comp.pos = comp.pos.add(comp.gameobject.dir_world2this(d)); },
sync: comp.sync.bind(comp),
};
editor.grabselect = [o];

View file

@ -173,6 +173,10 @@ var gameobject = {
else
this._ed.inst = false;
},
_ed: {
selectable: false,
dirty: false
},
namestr() {
var s = this.toString();
if (this._ed.dirty)
@ -334,7 +338,8 @@ var gameobject = {
return bb.t-bb.b;
},
move(vec) { this.pos = this.pos.add(vec); },
/* Moving, rotating, scaling functions, world relative */
move(vec) { this.set_worldpos(this.worldpos().add(vec)); },
rotate(x) { this.sworldangle(this.worldangle()+x); },
spread(vec) { this.sgscale(this.gscale().map((x,i)=>x*vec[i])); },
@ -467,6 +472,7 @@ var gameobject = {
t.pos = this.pos;
t.angle = this.angle;
t.scale = this.scale;
t.scale = t.scale.map((x,i) => x/this.__proto__.scale[i]);
return t;
},
@ -548,7 +554,7 @@ var gameobject = {
for (var [prop,p] of Object.entries(this)) {
if (!p) continue;
if (typeof p.make === 'function') {
if (component.isComponent(p)) {
obj[prop] = p.make(obj);
obj.components[prop] = obj[prop];
}

View file

@ -240,11 +240,9 @@ void phys2d_dbgdrawcircle(struct phys2d_circle *circle) {
void phys2d_applycircle(struct phys2d_circle *circle) {
gameobject *go = circle->shape.go;
float radius = circle->radius * HMM_MAX(HMM_ABS(go->scale.X), HMM_ABS(go->scale.Y));
cpCircleShapeSetRadius(circle->shape.shape, radius);
cpCircleShapeSetOffset(circle->shape.shape, HMM_MulV2(go->scale.XY, circle->offset).cp);
cpCircleShapeSetOffset(circle->shape.shape, circle->offset.cp);
}
/************** POLYGON ************/