fix actor deletion

This commit is contained in:
2025-01-19 17:20:06 -06:00
parent 8a063850a5
commit e628256f44
6 changed files with 27 additions and 36 deletions

View File

@@ -16,6 +16,8 @@ function use(file)
}
var script_fn = function script_fn(file) {
file = Resources.find_script(file)
if (!file) return
var content = Resources.replstrs(file);
var parsed = parse_file(content)
var module_name = file.name()
@@ -29,7 +31,8 @@ var script_fn = function script_fn(file) {
parsed.module_fn = module_fn;
parsed.module_ret = module_ret;
}
} else
parsed.module_ret = {}
if (parsed.program) {
var prog_script = `(function use_${module_name}() { var self = this; var $ = this.__proto__; ${parsed.program}})`;
@@ -66,27 +69,25 @@ globalThis.actor_use = function actor_use(script)
}
globalThis.class_use = function class_use(script, config, base = actor, callback, overling) {
var file = Resources.find_script(script);
if (!file) {
var prog = script_fn(script);
if (!prog) {
var ret = Object.create(base);
if (callback) callback(ret);
return ret;
}
var prog = script_fn(file);
var padawan;
if (prog.module_ret) {
prog.module_ret.__proto__ = base;
padawan = Object.create(prog.module_ret);
}
else
padawan = Object.create(base);
prog.module_ret.__proto__ = base;
padawan = Object.create(prog.module_ret);
padawan.overling = overling;
if (callback) callback(padawan)
prog.prog_fn.call(padawan)
if (typeof config === 'object') Object.assign(padawan,config);
if (!padawan.__reggies)
padawan.__proto__.__reggies = pull_registers(padawan)
return padawan;
};
@@ -147,12 +148,6 @@ actor.spawn = function (script, config) {
return padawan;
};
actor.tween = function (from, to, time, fn) {
var stop = tween(from, to, time, fn);
this.timers.push(stop);
return stop;
};
actor.spawn.doc = `Create a new actor, using this actor as the master, initializing it with 'script' and with data (as a JSON or Nota file) from 'config'.`;
actor.rm_pawn = function (pawn) {

View File

@@ -116,6 +116,10 @@ var entity = {
delete this[obj.name];
Object.unhide(this, obj.name);
},
aspawn(text, config) {
var e = class_use(text,config, actor, undefined, this)
},
spawn(text, config, callback) {
var ent = class_use(text, config, entity, function (ent) {

View File

@@ -4,7 +4,6 @@ global.pull_registers = function(obj)
{
var reggies = [];
for (var reg in Register.registries) {
if (!Register.registries[reg].register) return;
if (typeof obj[reg] === "function")
reggies.push(reg);
}
@@ -31,7 +30,6 @@ global.check_registers = function check_registers(obj) {
}
for (var reg in Register.registries) {
if (!Register.registries[reg].register) return;
if (typeof obj[reg] === "function")
register_obj(obj,reg);
}

View File

@@ -10,10 +10,8 @@ globalThis.so_sprite_qt = os.make_rtree();
anim_speed: 1,
play(str, loop = true, reverse = false, fn) {
if (!this.animset) {
// console.warn(`Sprite has no animset when trying to play ${str}`);
fn?.();
return;
// return parseq.imm();
}
if (typeof str === 'string') {
@@ -67,18 +65,10 @@ globalThis.so_sprite_qt = os.make_rtree();
stop = self.delay(advance, playing.frames[f].time/self.anim_speed);
advance();
},
tex_sync() {
if (this.anim) this.stop();
if (!this.image) return
this.play();
this.transform.scale = [this.image.texture.width, this.image.texture.height];
this._sprite.set_image(this.image);
},
stop() {
this.del_anim?.();
},
set path(p) {
var image = game.texture(p);
if (!image) {
console.warn(`Could not find image ${p}.`);
@@ -95,6 +85,7 @@ globalThis.so_sprite_qt = os.make_rtree();
this.anim = image;
this.image = image.frames[0];
this.animset = [this.anim]
this.play()
} else {
// Maybe an animset; try to grab the first one
for (var anim in image) {
@@ -102,12 +93,14 @@ globalThis.so_sprite_qt = os.make_rtree();
this.anim = image[anim];
this.image = image[anim].frames[0];
this.animset = image;
this.play()
break;
}
}
}
this.tex_sync();
this.transform.scale = this.image.texture.dim //[this.image.texture.width, this.image.texture.height]
this._sprite.set_image(this.image)
},
get path() {
return this._p;
@@ -195,13 +188,11 @@ sprite.inputs.kp1 = function () {
};
sprite.t_hook = function() {
console.log("SHIFT")
var msp = this.sprite;
so_sprite_qt.remove(msp);
msp.rect = this.torect()
msp.set_affine(this)
so_sprite_qt.insert(msp)
console.log("BOTTOM")
}
return sprite;
@@ -213,8 +204,8 @@ if (!this.overling.transform) throw new Error("Overling must have a transform to
this.transform = os.make_transform();
this.transform.parent = this.overling.transform;
this.transform.change_hook = $.t_hook;
var msp = os.make_sprite();
this._sprite = msp;
msp.color = Color.white;
this.transform.sprite = msp
so_sprite_qt.insert(msp)

View File

@@ -3681,6 +3681,7 @@ if (compress) {
ret = SDL_GPUTexture2js(js, tex);
JS_SetProperty(js, ret, width_atom, number2js(js, surf->w));
JS_SetProperty(js, ret, height_atom, number2js(js, surf->h));
JS_SetPropertyStr(js,ret,"dim", vec22js(js,(HMM_Vec2){surf->w,surf->h}));
if (dofree) SDL_DestroySurface(surf);
@@ -3942,6 +3943,7 @@ JSC_CCALL(gpu_texture,
JSValue jstex = SDL_GPUTexture2js(js,tex);
JS_SetPropertyStr(js,jstex,"width", number2js(js,info.width));
JS_SetPropertyStr(js,jstex,"height", number2js(js,info.height));
JS_SetPropertyStr(js,jstex,"dim", vec22js(js,(HMM_Vec2){info.width, info.height}));
return jstex;
)

View File

@@ -36,9 +36,8 @@ void transform_free(JSRuntime *rt, transform *t) {
arrfree(t->children);
free(t);
for (int i = arrlen(dirties)-1; i >= 0; i--) {
for (int i = arrlen(dirties)-1; i >= 0; i--)
if (dirties[i] == t) arrdelswap(dirties, i);
}
}
void transform_clean(transform *t)
@@ -66,6 +65,8 @@ void clean_all()
{
for (int i = 0; i < arrlen(dirties); i++)
transform_clean(dirties[i]);
arrsetlen(dirties,0);
}
void transform_move(transform *t, HMM_Vec3 v)