luce bree
This commit is contained in:
@@ -7,10 +7,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "script/module/modulebase.h"
|
#include "script/module/modulebase.h"
|
||||||
|
#include "script/module/display/modulecolor.h"
|
||||||
#include "script/scriptproto.h"
|
#include "script/scriptproto.h"
|
||||||
#include "entity/entity.h"
|
#include "entity/entity.h"
|
||||||
#include "entity/component/display/entitymaterial.h"
|
#include "entity/component/display/entitymaterial.h"
|
||||||
#include "display/color.h"
|
|
||||||
#include "moduleentityposition.h"
|
#include "moduleentityposition.h"
|
||||||
|
|
||||||
static scriptproto_t MODULE_ENTITY_MATERIAL_PROTO;
|
static scriptproto_t MODULE_ENTITY_MATERIAL_PROTO;
|
||||||
@@ -27,52 +27,30 @@ static entitymaterial_t * moduleEntityMaterialGet(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
moduleBaseFunction(moduleEntityMaterialGetColor) {
|
||||||
|
entitymaterial_t *mat = moduleEntityMaterialGet(callInfo);
|
||||||
|
if(!mat) return jerry_undefined();
|
||||||
|
return moduleColorMakeObject(mat->material.unlit.color);
|
||||||
|
}
|
||||||
|
|
||||||
moduleBaseFunction(moduleEntityMaterialSetColor) {
|
moduleBaseFunction(moduleEntityMaterialSetColor) {
|
||||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
if(argc < 1 || !jerry_value_is_object(args[0])) {
|
||||||
if(!jerry_value_is_object(args[0])) {
|
return moduleBaseThrow("Material.color: expected color object");
|
||||||
return moduleBaseThrow("expected color object");
|
}
|
||||||
|
color_t *color = (color_t*)scriptProtoGetValue(&MODULE_COLOR_PROTO, args[0]);
|
||||||
|
if(!color) {
|
||||||
|
return moduleBaseThrow("Material.color: expected valid color object");
|
||||||
}
|
}
|
||||||
entitymaterial_t *mat = moduleEntityMaterialGet(callInfo);
|
entitymaterial_t *mat = moduleEntityMaterialGet(callInfo);
|
||||||
if(!mat) return jerry_undefined();
|
if(!mat) return jerry_undefined();
|
||||||
|
memoryCopy(&mat->material.unlit.color, color, sizeof(color_t));
|
||||||
jerry_value_t key;
|
|
||||||
jerry_value_t v;
|
|
||||||
color_t col;
|
|
||||||
|
|
||||||
key = jerry_string_sz("r");
|
|
||||||
v = jerry_object_get(args[0], key);
|
|
||||||
jerry_value_free(key);
|
|
||||||
col.r = (colorchannel8_t)jerry_value_as_number(v);
|
|
||||||
jerry_value_free(v);
|
|
||||||
|
|
||||||
key = jerry_string_sz("g");
|
|
||||||
v = jerry_object_get(args[0], key);
|
|
||||||
jerry_value_free(key);
|
|
||||||
col.g = (colorchannel8_t)jerry_value_as_number(v);
|
|
||||||
jerry_value_free(v);
|
|
||||||
|
|
||||||
key = jerry_string_sz("b");
|
|
||||||
v = jerry_object_get(args[0], key);
|
|
||||||
jerry_value_free(key);
|
|
||||||
col.b = (colorchannel8_t)jerry_value_as_number(v);
|
|
||||||
jerry_value_free(v);
|
|
||||||
|
|
||||||
key = jerry_string_sz("a");
|
|
||||||
v = jerry_object_get(args[0], key);
|
|
||||||
jerry_value_free(key);
|
|
||||||
col.a = (colorchannel8_t)jerry_value_as_number(v);
|
|
||||||
jerry_value_free(v);
|
|
||||||
|
|
||||||
mat->material.unlit.color = col;
|
|
||||||
return jerry_undefined();
|
return jerry_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
moduleBaseFunction(moduleEntityMaterialAdd) {
|
moduleBaseFunction(moduleEntityMaterialAdd) {
|
||||||
if(argc < 1) {
|
if(argc < 1 || !jerry_value_is_number(args[0])) {
|
||||||
return moduleBaseThrow("Expected at least 1 argument");
|
return moduleBaseThrow("Expected at least 1 argument");
|
||||||
}
|
}
|
||||||
moduleBaseRequireNumber(0);
|
|
||||||
|
|
||||||
entityid_t id = (entityid_t)jerry_value_as_number(args[0]);
|
entityid_t id = (entityid_t)jerry_value_as_number(args[0]);
|
||||||
componentid_t comp = entityAddComponent(id, COMPONENT_TYPE_MATERIAL);
|
componentid_t comp = entityAddComponent(id, COMPONENT_TYPE_MATERIAL);
|
||||||
componenthandle_t h = { .eid = id, .cid = comp };
|
componenthandle_t h = { .eid = id, .cid = comp };
|
||||||
@@ -87,9 +65,8 @@ static void moduleEntityMATERIAL(void) {
|
|||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
scriptProtoDefineFunc(
|
scriptProtoDefineProp(
|
||||||
&MODULE_ENTITY_MATERIAL_PROTO,
|
&MODULE_ENTITY_MATERIAL_PROTO, "color",
|
||||||
"setColor",
|
moduleEntityMaterialGetColor, moduleEntityMaterialSetColor
|
||||||
moduleEntityMaterialSetColor
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,14 +36,12 @@ moduleBaseFunction(moduleEntityMeshSetMesh) {
|
|||||||
entitymesh_t *comp = moduleEntityMeshGet(callInfo);
|
entitymesh_t *comp = moduleEntityMeshGet(callInfo);
|
||||||
if(!comp) return jerry_undefined();
|
if(!comp) return jerry_undefined();
|
||||||
|
|
||||||
// User-created Mesh JS object (meshscript_t)
|
|
||||||
meshscript_t *ms = moduleMeshFrom(args[0]);
|
meshscript_t *ms = moduleMeshFrom(args[0]);
|
||||||
if(ms) {
|
if(ms) {
|
||||||
comp->mesh = &ms->mesh;
|
comp->mesh = &ms->mesh;
|
||||||
return jerry_undefined();
|
return jerry_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Engine-owned default mesh (Mesh.DEFAULT_CUBE etc.) — raw mesh_t*
|
|
||||||
mesh_t *raw = (mesh_t*)moduleBaseUnwrapPointer(args[0]);
|
mesh_t *raw = (mesh_t*)moduleBaseUnwrapPointer(args[0]);
|
||||||
if(raw) {
|
if(raw) {
|
||||||
comp->mesh = raw;
|
comp->mesh = raw;
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ moduleBaseFunction(moduleEntityPhysicsGetOnGround) {
|
|||||||
moduleBaseFunction(moduleEntityPhysicsGetBodyType) {
|
moduleBaseFunction(moduleEntityPhysicsGetBodyType) {
|
||||||
entityphysics_t *phys = moduleEntityPhysicsGet(callInfo);
|
entityphysics_t *phys = moduleEntityPhysicsGet(callInfo);
|
||||||
if(!phys) return jerry_undefined();
|
if(!phys) return jerry_undefined();
|
||||||
return jerry_number((double)phys->type);
|
return jerry_number(phys->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
moduleBaseFunction(moduleEntityPhysicsSetBodyType) {
|
moduleBaseFunction(moduleEntityPhysicsSetBodyType) {
|
||||||
|
|||||||
Reference in New Issue
Block a user