scale
This commit is contained in:
parent
2f086947b9
commit
885a2fd190
2
Makefile
2
Makefile
|
@ -53,7 +53,7 @@ endif
|
||||||
CPPFLAGS += -ffast-math
|
CPPFLAGS += -ffast-math
|
||||||
|
|
||||||
ifeq ($(DBG),1)
|
ifeq ($(DBG),1)
|
||||||
CPPFLAGS += -g #-fsanitize=address
|
CPPFLAGS += -g -fsanitize=address
|
||||||
INFO += _dbg
|
INFO += _dbg
|
||||||
else
|
else
|
||||||
CPPFLAGS += -DNDEBUG
|
CPPFLAGS += -DNDEBUG
|
||||||
|
|
|
@ -40,6 +40,13 @@ var component = {
|
||||||
enable() { this.enabled = true; },
|
enable() { this.enabled = true; },
|
||||||
disable() { this.enabled = false; },
|
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'],
|
hides: ['gameobject', 'id'],
|
||||||
|
|
||||||
make(go) {
|
make(go) {
|
||||||
|
@ -81,7 +88,9 @@ component.sprite.impl = {
|
||||||
cmd(12,this.id,x,this.rect);
|
cmd(12,this.id,x,this.rect);
|
||||||
},
|
},
|
||||||
get path() {
|
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));
|
//return prototypes.resavi(this.gameobject.__proto__.toString(), cmd(116,this.id));
|
||||||
},
|
},
|
||||||
toString() { return "sprite"; },
|
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.";
|
collider2d.inputs['M-t'].doc = "Toggle if this collider is enabled.";
|
||||||
|
|
||||||
component.polygon2d = Object.copy(collider2d, {
|
component.polygon2d = Object.copy(collider2d, {
|
||||||
toString() { return "poly2d"; },
|
toString() { return "polygon2d"; },
|
||||||
flipx: false,
|
flipx: false,
|
||||||
flipy: false,
|
flipy: false,
|
||||||
|
|
||||||
|
|
|
@ -38,13 +38,12 @@ var editor = {
|
||||||
/* Tries to select id */
|
/* Tries to select id */
|
||||||
do_select(obj) {
|
do_select(obj) {
|
||||||
if (!obj) return;
|
if (!obj) return;
|
||||||
// if (!obj || !obj._ed.selectable) return undefined;
|
if (!obj._ed.selectable) return undefined;
|
||||||
|
|
||||||
if (obj.level !== this.edit_level) {
|
if (obj.level !== this.edit_level) {
|
||||||
var testlevel = obj.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;
|
testlevel = testlevel.level;
|
||||||
|
|
||||||
return testlevel;
|
return testlevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,6 +226,7 @@ var editor = {
|
||||||
}
|
}
|
||||||
this.selectlist = [];
|
this.selectlist = [];
|
||||||
editor.camera = Primum.spawn(ur.camera2d);
|
editor.camera = Primum.spawn(ur.camera2d);
|
||||||
|
editor.camera._ed.selectable = false;
|
||||||
Game.view_camera(editor.camera);
|
Game.view_camera(editor.camera);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -583,7 +583,7 @@ editor.inputs.drop = function(str) {
|
||||||
return;
|
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['M-t'].doc = "Unlock all objects in current level.";
|
||||||
|
|
||||||
editor.inputs['C-n'] = function() {
|
editor.inputs['C-n'] = function() {
|
||||||
|
return;
|
||||||
gameobject.make(editor.edit_level);
|
gameobject.make(editor.edit_level);
|
||||||
console.warn("MADE A NEW OBJECT");
|
console.warn("MADE A NEW OBJECT");
|
||||||
/* if (editor.edit_level._ed.dirty) {
|
/* if (editor.edit_level._ed.dirty) {
|
||||||
|
@ -984,14 +985,7 @@ editor.inputs.lm.released = function() {
|
||||||
var obj = editor.do_select(x);
|
var obj = editor.do_select(x);
|
||||||
if (obj)
|
if (obj)
|
||||||
selects.push(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;
|
this.sel_start = undefined;
|
||||||
|
@ -1101,6 +1095,7 @@ editor.inputs.mouse.move = function(pos, dpos)
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.grabselect?.forEach(function(x) {
|
editor.grabselect?.forEach(function(x) {
|
||||||
|
if (!x) return;
|
||||||
x.move(Game.camera.dir_view2world(dpos));
|
x.move(Game.camera.dir_view2world(dpos));
|
||||||
if ('sync' in x)
|
if ('sync' in x)
|
||||||
x.sync();
|
x.sync();
|
||||||
|
@ -1186,7 +1181,7 @@ editor.inputs.g = function() {
|
||||||
var comp = editor.sel_comp;
|
var comp = editor.sel_comp;
|
||||||
var o = {
|
var o = {
|
||||||
pos: editor.sel_comp.pos,
|
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),
|
sync: comp.sync.bind(comp),
|
||||||
};
|
};
|
||||||
editor.grabselect = [o];
|
editor.grabselect = [o];
|
||||||
|
|
|
@ -173,6 +173,10 @@ var gameobject = {
|
||||||
else
|
else
|
||||||
this._ed.inst = false;
|
this._ed.inst = false;
|
||||||
},
|
},
|
||||||
|
_ed: {
|
||||||
|
selectable: false,
|
||||||
|
dirty: false
|
||||||
|
},
|
||||||
namestr() {
|
namestr() {
|
||||||
var s = this.toString();
|
var s = this.toString();
|
||||||
if (this._ed.dirty)
|
if (this._ed.dirty)
|
||||||
|
@ -334,7 +338,8 @@ var gameobject = {
|
||||||
return bb.t-bb.b;
|
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); },
|
rotate(x) { this.sworldangle(this.worldangle()+x); },
|
||||||
spread(vec) { this.sgscale(this.gscale().map((x,i)=>x*vec[i])); },
|
spread(vec) { this.sgscale(this.gscale().map((x,i)=>x*vec[i])); },
|
||||||
|
|
||||||
|
@ -467,6 +472,7 @@ var gameobject = {
|
||||||
t.pos = this.pos;
|
t.pos = this.pos;
|
||||||
t.angle = this.angle;
|
t.angle = this.angle;
|
||||||
t.scale = this.scale;
|
t.scale = this.scale;
|
||||||
|
t.scale = t.scale.map((x,i) => x/this.__proto__.scale[i]);
|
||||||
return t;
|
return t;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -548,7 +554,7 @@ var gameobject = {
|
||||||
|
|
||||||
for (var [prop,p] of Object.entries(this)) {
|
for (var [prop,p] of Object.entries(this)) {
|
||||||
if (!p) continue;
|
if (!p) continue;
|
||||||
if (typeof p.make === 'function') {
|
if (component.isComponent(p)) {
|
||||||
obj[prop] = p.make(obj);
|
obj[prop] = p.make(obj);
|
||||||
obj.components[prop] = obj[prop];
|
obj.components[prop] = obj[prop];
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,11 +240,9 @@ void phys2d_dbgdrawcircle(struct phys2d_circle *circle) {
|
||||||
|
|
||||||
void phys2d_applycircle(struct phys2d_circle *circle) {
|
void phys2d_applycircle(struct phys2d_circle *circle) {
|
||||||
gameobject *go = circle->shape.go;
|
gameobject *go = circle->shape.go;
|
||||||
|
|
||||||
float radius = circle->radius * HMM_MAX(HMM_ABS(go->scale.X), HMM_ABS(go->scale.Y));
|
float radius = circle->radius * HMM_MAX(HMM_ABS(go->scale.X), HMM_ABS(go->scale.Y));
|
||||||
cpCircleShapeSetRadius(circle->shape.shape, radius);
|
cpCircleShapeSetRadius(circle->shape.shape, radius);
|
||||||
|
cpCircleShapeSetOffset(circle->shape.shape, circle->offset.cp);
|
||||||
cpCircleShapeSetOffset(circle->shape.shape, HMM_MulV2(go->scale.XY, circle->offset).cp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/************** POLYGON ************/
|
/************** POLYGON ************/
|
||||||
|
|
Loading…
Reference in a new issue