fix image finding

This commit is contained in:
John Alanbrook 2024-08-30 14:17:37 -05:00
parent 2c1f34177b
commit dc59f0642c
7 changed files with 30 additions and 12 deletions

View file

@ -556,8 +556,9 @@ Object.defineProperty(Object.prototype, 'obscure', {
Object.defineProperty(Object.prototype, 'mixin', {
value: function(obj) {
if (typeof obj === 'string')
if (typeof obj === 'string') {
obj = use(obj);
}
if (obj)
Object.mixin(this, obj);

View file

@ -66,7 +66,6 @@ Resources.replpath = function replpath(str, path) {
if (io.exists(tr)) return tr;
stem = stem.updir();
}
return str;
};
@ -74,9 +73,9 @@ Resources.replstrs = function replstrs(path) {
if (!path) return;
var script = io.slurp(path);
var regexp = /"[^"\s]*?\.[^"\s]+?"/g;
var stem = path.dir();
// remove console statements
if (!console.enabled)
script = Resources.rm_fn(/console\.(spam|info|warn|error)/, script);
@ -88,6 +87,7 @@ Resources.replstrs = function replstrs(path) {
script = Resources.rm_fn(/debug\.(build|fn_break)/, script);
}
script = script.replace(regexp, function (str) {
var newstr = Resources.replpath(str.trimchr('"'), path);
return `"${newstr}"`;
@ -160,11 +160,13 @@ function find_ext(file, ext, root = "") {
return nf;
}
var all_files = io.glob(`**${file}.*`);
var all_files = io.glob(`**/${file}.*`);
var find = undefined;
for (var e of ext) {
var finds = all_files.filter(x => x.ext() === e);
if (finds.length === 1) {
if (finds.length > 1)
console.warn(`Found conflicting files when searching for '${file}': ${json.encode(finds)}. Returning the first one.`);
if (finds.length > 0) {
find = finds[0];
break;
}
@ -290,7 +292,6 @@ globalThis.use = function use(file) {
profile.endcache(" [cached]");
return ret;
}
var script = Resources.replstrs(file);
script = `(function() { var self = this; ${script}; })`;
var fn = os.eval(file, script);

View file

@ -1,3 +1,4 @@
globalThis.entityreport = {};
var timer_update = function(dt)

View file

@ -60,7 +60,7 @@ game.engine_start = function (s) {
function () {
global.mixin("scripts/sound.js");
world_start();
window.set_icon(os.make_texture("icons/moon.gif"));
window.set_icon(game.texture("moon"));
Object.readonly(window.__proto__, "vsync");
Object.readonly(window.__proto__, "enable_dragndrop");
Object.readonly(window.__proto__, "enable_clipboard");
@ -314,7 +314,7 @@ global.mixin("scripts/tween");
global.mixin("scripts/ai");
global.mixin("scripts/particle");
global.mixin("scripts/physics");
global.mixin("scripts/geometry");
global.mixin("scripts/geometry")
/*
Factory for creating registries. Register one with 'X.register',
@ -398,7 +398,9 @@ var Event = {
global.mixin("scripts/spline");
global.mixin("scripts/components");
global.mixin("scripts/actor");
global.mixin("scripts/entity");
function world_start() {

View file

@ -155,13 +155,14 @@ static const JSCFunctionListEntry js_imgui_funcs[] = {
MIST_FUNC_DEF(imgui, menubar, 1),
MIST_FUNC_DEF(imgui, mainmenubar, 1),
MIST_FUNC_DEF(imgui, menuitem, 3),
// MIST_FUNC_DEF(imgui, radio,
MIST_FUNC_DEF(imgui, image, 1),
MIST_FUNC_DEF(imgui, textinput, 2),
MIST_FUNC_DEF(imgui, button, 2),
MIST_FUNC_DEF(imgui, checkbox, 2),
MIST_FUNC_DEF(imgui, text, 1),
MIST_FUNC_DEF(imgui, plot,1),
MIST_FUNC_DEF(imgui,lineplot,2),
MIST_FUNC_DEF(imgui, lineplot,2),
MIST_FUNC_DEF(imgui, sokol_gfx, 0),
MIST_FUNC_DEF(imgui, columns, 2),
MIST_FUNC_DEF(imgui, nextcolumn, 0),

View file

@ -1717,6 +1717,7 @@ JSValue js_io_slurpbytes(JSContext *js, JSValue self, int argc, JSValue *argv)
JSValue js_io_slurp(JSContext *js, JSValue self, int argc, JSValue *argv)
{
char *f = js2str(argv[0]);
size_t len;

View file

@ -292,11 +292,21 @@ void texture_save(texture *tex, const char *file)
stbi_write_jpg(file, tex->width, tex->height, 4, tex->data, 5);
}
// all coordinates start at bottom left
// src and dest, width, height are pixel buffers and their widths and heights
// sx the x coordinate of the destination to copy to
// sy the y coordinate of the destination to copy to
// sw the width of the destination to take in pixels
// sh the height of the destination to take in pixels
void blit_image(uint8_t* src, uint8_t* dest, int src_width, int src_height, int dest_width, int dest_height, int sx, int sy, int sw, int sh) {
if (sx + sw > dest_width) return;
if (sy + sh > dest_height) return;
if (sx < 0) return;
if (sy < 0) return;
int src_stride = src_width * 4;
int dest_stride = dest_width * 4;
int dest_pixels = dest_width*dest_height*4;
int src_pixels = src_width*src_height*4;
for (int y = 0; y < sw; y++) {
for (int x = 0; x < sh; x++) {
@ -317,6 +327,7 @@ void blit_image(uint8_t* src, uint8_t* dest, int src_width, int src_height, int
uint8_t result_green = (src[src_index + 1] * src_alpha + dest[dest_index + 1] * (255 - src_alpha) * dest_alpha / 255) / result_alpha;
uint8_t result_blue = (src[src_index + 2] * src_alpha + dest[dest_index + 2] * (255 - src_alpha) * dest_alpha / 255) / result_alpha;
if (dest_index+3 > dest_pixels-3) return;
// Set the resulting pixel values
dest[dest_index + 0] = result_red;
dest[dest_index + 1] = result_green;
@ -326,10 +337,10 @@ void blit_image(uint8_t* src, uint8_t* dest, int src_width, int src_height, int
}
}
// Function to draw source image pixels on top of a destination image
void texture_blit(texture *dest, texture *src, int x, int y, int w, int h) {
if (x + w >= dest->width) return;
if (y + h >= dest->height) return;
blit_image(src->data, dest->data, src->width, src->height, dest->height, dest->width, x, y, w, h);
}