This commit is contained in:
John Alanbrook 2023-12-27 16:34:14 +00:00
parent 1b4a36f398
commit beee0c50f3
5 changed files with 24 additions and 9 deletions

View file

@ -1209,6 +1209,12 @@ Math.nearest = function(n, incr)
return Math.round(n/incr)*incr; return Math.round(n/incr)*incr;
} }
Math.places = function(n,digits)
{
var div = Math.pow(10,digits);
return Math.round(n*div)/div;
}
Number.hex = function(n) Number.hex = function(n)
{ {
var s = Math.floor(n).toString(16); var s = Math.floor(n).toString(16);
@ -1413,9 +1419,9 @@ var Vector = {
rotate(v,angle) { rotate(v,angle) {
var r = Vector.length(v); var r = Vector.length(v);
var p = Vector.angle(v) + angle; angle += Vector.angle(v);
p = Math.turn2rad(angle); angle = Math.turn2rad(angle);
return [r*Math.cos(p), r*Math.sin(p)]; return [r*Math.cos(angle), r*Math.sin(angle)];
}, },
equal(v1, v2, tol) { equal(v1, v2, tol) {

View file

@ -620,7 +620,7 @@ component.edge2d = Object.copy(collider2d, {
/* EDITOR */ /* EDITOR */
gizmo() { gizmo() {
if (this.type === Spline.type.catmull) { if (this.type === Spline.type.catmull || this.type === -1) {
this.spoints().forEach(x => Shape.point(this.gameobject.this2screen(x), 3, Color.teal)); this.spoints().forEach(x => Shape.point(this.gameobject.this2screen(x), 3, Color.teal));
this.cpoints.forEach((x,i) => Debug.numbered_point(this.gameobject.this2screen(x), i)); this.cpoints.forEach((x,i) => Debug.numbered_point(this.gameobject.this2screen(x), i));
} else { } else {
@ -643,7 +643,7 @@ component.edge2d = Object.copy(collider2d, {
var p = this.cpoints[i]; var p = this.cpoints[i];
if (!p) return undefined; if (!p) return undefined;
if (Spline.is_catmull(this.type)) if (Spline.is_catmull(this.type) || this.type === -1)
return make_point_obj(this,p); return make_point_obj(this,p);
var that = this.gameobject; var that = this.gameobject;
@ -691,7 +691,7 @@ component.edge2d = Object.copy(collider2d, {
add_node(pos) { add_node(pos) {
pos = this.gameobject.world2this(pos); pos = this.gameobject.world2this(pos);
var idx = 0; var idx = 0;
if (Spline.is_catmull(this.type)) { if (Spline.is_catmull(this.type) || this.type === -1) {
if (this.cpoints.length >= 2) if (this.cpoints.length >= 2)
idx = cmd(59, pos, this.cpoints, 400); idx = cmd(59, pos, this.cpoints, 400);

View file

@ -609,6 +609,9 @@ editor.inputs.f9 = function() {
editor.inputs.release_post = function() { editor.inputs.release_post = function() {
editor.snapshot(); editor.snapshot();
editor.edit_level.check_dirty(); editor.edit_level.check_dirty();
/* snap all objects to be pixel perfect */
editor.edit_level.obj_descend(o => o.pos = o.pos.map(x => Math.round(x)));
}; };
editor.inputs['C-a'] = function() { editor.inputs['C-a'] = function() {
if (!editor.selectlist.empty) { editor.unselect(); return; } if (!editor.selectlist.empty) { editor.unselect(); return; }

View file

@ -480,9 +480,10 @@ var gameobject = {
transform() { transform() {
var t = {}; var t = {};
t.pos = this.pos; t.pos = this.pos;
t.angle = this.angle; t.angle = Math.places(this.angle,4);
t.scale = this.scale; t.scale = this.scale;
t.scale = t.scale.map((x,i) => x/this.__proto__.scale[i]); t.scale = t.scale.map((x,i) => x/this.__proto__.scale[i]);
t.scale = t.scale.map(x => Math.places(x,3));
return t; return t;
}, },
@ -636,6 +637,12 @@ var gameobject = {
obj ??= this; obj ??= this;
Signal.obj_separate(fn,obj,this); Signal.obj_separate(fn,obj,this);
}, },
obj_descend(fn) {
fn(this);
for (var o in this.objects)
this.objects[o].obj_descend(fn);
},
} }
Object.mixin(gameobject,gameobject_impl); Object.mixin(gameobject,gameobject_impl);

View file

@ -550,8 +550,7 @@ void duk_call_phys_cb(HMM_Vec2 norm, struct callee c, gameobject *hit, cpArbiter
struct postphys_cb cb; struct postphys_cb cb;
cb.c = c; cb.c = c;
cb.send = obj; cb.send = obj;
script_callee(c, 1, &obj); arrput(begins, cb);
// arrput(begins, cb);
} }
#define CTYPE_BEGIN 0 #define CTYPE_BEGIN 0