Some checks failed
Build and Deploy / build-windows (CLANG64) (push) Has been cancelled
Build and Deploy / build-macos (push) Has been cancelled
Build and Deploy / build-linux (push) Has been cancelled
Build and Deploy / package-dist (push) Has been cancelled
Build and Deploy / deploy-itch (push) Has been cancelled
Build and Deploy / deploy-gitea (push) Has been cancelled
64 lines
2.0 KiB
C
64 lines
2.0 KiB
C
#include "qjs_sprite.h"
|
|
#include "jsffi.h"
|
|
#include "qjs_macros.h"
|
|
|
|
#include "sprite.h"
|
|
#include "HandmadeMath.h"
|
|
|
|
// Sprite class definitions
|
|
static JSClassID js_sprite_id;
|
|
static void js_sprite_mark(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func) {
|
|
sprite *sp = JS_GetOpaque(val, js_sprite_id);
|
|
if (!sp) return;
|
|
JS_MarkValue(rt, sp->image, mark_func);
|
|
}
|
|
|
|
// Class definition for sprite with mark function for GC
|
|
QJSCLASSMARK(sprite,)
|
|
|
|
// SPRITE GETTER/SETTER FUNCTIONS
|
|
JSC_GETSET(sprite, pos, vec2)
|
|
JSC_GETSET(sprite, center, vec2)
|
|
JSC_GETSET(sprite, layer, number)
|
|
JSC_GETSET(sprite, color, color)
|
|
JSC_GETSET(sprite, skew, vec2)
|
|
JSC_GETSET(sprite, scale, vec2)
|
|
JSC_GETSET(sprite, rotation, number)
|
|
|
|
// SPRITE ACTION FUNCTIONS
|
|
|
|
JSC_CCALL(sprite_move,
|
|
sprite *sp = js2sprite(js,self);
|
|
HMM_Vec2 mv = js2vec2(js,argv[0]);
|
|
sp->pos.x += mv.x;
|
|
sp->pos.y += mv.y;
|
|
)
|
|
|
|
JSC_CCALL(sprite_set_affine,
|
|
sprite *sp = js2sprite(js,self);
|
|
sprite_apply(sp);
|
|
)
|
|
|
|
JSC_CCALL(sprite_set_image,
|
|
sprite *sp = js2sprite(js,self);
|
|
if (!JS_IsUndefined(sp->image))
|
|
JS_FreeValue(js,sp->image);
|
|
sp->image = JS_DupValue(js, argv[0]);
|
|
)
|
|
|
|
static const JSCFunctionListEntry js_sprite_funcs[] = {
|
|
MIST_FUNC_DEF(sprite, set_affine, 0),
|
|
MIST_FUNC_DEF(sprite, set_image, 1),
|
|
MIST_FUNC_DEF(sprite, move, 1),
|
|
JS_CGETSET_DEF("pos", js_sprite_get_pos, js_sprite_set_pos),
|
|
JS_CGETSET_DEF("scale", js_sprite_get_scale, js_sprite_set_scale),
|
|
JS_CGETSET_DEF("skew", js_sprite_get_skew, js_sprite_set_skew),
|
|
JS_CGETSET_DEF("layer", js_sprite_get_layer, js_sprite_set_layer),
|
|
JS_CGETSET_DEF("color", js_sprite_get_color, js_sprite_set_color),
|
|
JS_CGETSET_DEF("center", js_sprite_get_center, js_sprite_set_center),
|
|
JS_CGETSET_DEF("rotation", js_sprite_get_rotation, js_sprite_set_rotation),
|
|
};
|
|
|
|
// Note: Like transform, sprite doesn't use MISTUSE because sprite is a C type created via os.make_sprite()
|
|
// The sprite functions are registered as methods on the sprite class prototype
|
|
// This would be handled in the main FFI loading where QJSCLASSPREP_FUNCS(sprite) is called
|