some array fns

This commit is contained in:
John Alanbrook 2024-06-26 16:57:17 -05:00
parent 42db19d748
commit 829b6386da
2 changed files with 25 additions and 4 deletions

View file

@ -1184,6 +1184,9 @@ Object.defineProperty(Array.prototype, 'unique', {
} }
}); });
Object.defineProperty(Array.prototype, 'unduped', {
value: function() { return [... new Set(this)]; }
});
Object.defineProperty(Array.prototype, 'findIndex', { Object.defineProperty(Array.prototype, 'findIndex', {
value: function(fn) { value: function(fn) {
@ -1216,6 +1219,15 @@ Object.defineProperty(Array.prototype, 'find', {
return ret; return ret;
}}); }});
Object.defineProperty(Array.prototype, 'search', {
value: function(val) {
for (var i = 0; i < this.length; i++)
if (this[i] === val) return i;
return undefined;
}
});
Object.defineProperty(Array.prototype, 'last', { Object.defineProperty(Array.prototype, 'last', {
value: function() { return this[this.length-1]; }, value: function() { return this[this.length-1]; },
}); });

View file

@ -515,10 +515,19 @@ render.text = function(str, pos, size = 1, color = Color.white, wrap = -1, ancho
return bb; return bb;
}; };
render.image = function(tex, pos, rotation = 0, color = Color.white, dimensions = [tex.width, tex.height]) { render.image = function(tex, pos, scale = 1, rotation = 0, color = Color.white, dimensions = [tex.width, tex.height]) {
//var scale = [dimensions.x/tex.width, dimensions.y/tex.height]; var t = os.make_transform();
//gui.img(tex,pos, scale, 0.0, false, [0.0,0.0], color); t.pos = pos;
//return bbox.fromcwh([0,0], [tex.width,tex.height]); t.scale = [scale,scale];
render.setpipeline(render.spriteshader.pipe);
render.setunim4(0, render.spriteshader.vs.unimap.model.slot, t);
render.shader_apply_material(render.spriteshader, {
shade: color,
diffuse: tex
});
var bind = render.sg_bind(render.spriteshader, shape.quad, {diffuse:tex});
bind.inst = 1;
render.spdraw(bind);
} }
render.fontcache = {}; render.fontcache = {};