Compare commits
2 Commits
4a4adeb3c8
...
0e94c1fa6d
| Author | SHA1 | Date | |
|---|---|---|---|
| 0e94c1fa6d | |||
| 6d9e2dd3e1 |
@@ -1,13 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef struct {
|
||||
void *nothing;
|
||||
} inventory_t;
|
||||
@@ -0,0 +1,6 @@
|
||||
module = {
|
||||
render() {
|
||||
Text.draw(0, 0, "Hello World");
|
||||
SpriteBatch.flush();
|
||||
}
|
||||
};
|
||||
@@ -146,7 +146,9 @@ size_t assetFileLineReaderUnreadBytes(const assetfilelinereader_t *reader) {
|
||||
return reader->bufferEnd - reader->bufferStart;
|
||||
}
|
||||
|
||||
const uint8_t *assetFileLineReaderUnreadPtr(const assetfilelinereader_t *reader) {
|
||||
const uint8_t *assetFileLineReaderUnreadPtr(
|
||||
const assetfilelinereader_t *reader
|
||||
) {
|
||||
assertNotNull(reader, "Reader cannot be NULL.");
|
||||
assertNotNull(reader->readBuffer, "Read buffer cannot be NULL.");
|
||||
return reader->readBuffer + reader->bufferStart;
|
||||
@@ -177,11 +179,16 @@ static errorret_t assetFileLineReaderAppend(
|
||||
static void assetFileLineReaderTerminate(assetfilelinereader_t *reader) {
|
||||
assertNotNull(reader, "Reader cannot be NULL.");
|
||||
assertNotNull(reader->outBuffer, "Out buffer cannot be NULL.");
|
||||
assertTrue(reader->lineLength < reader->outBufferSize, "Line length exceeds out buffer.");
|
||||
assertTrue(
|
||||
reader->lineLength < reader->outBufferSize,
|
||||
"Line length exceeds out buffer."
|
||||
);
|
||||
reader->outBuffer[reader->lineLength] = '\0';
|
||||
}
|
||||
|
||||
static ssize_t assetFileLineReaderFindNewline(const assetfilelinereader_t *reader) {
|
||||
static ssize_t assetFileLineReaderFindNewline(
|
||||
const assetfilelinereader_t *reader
|
||||
) {
|
||||
size_t i;
|
||||
|
||||
assertNotNull(reader, "Reader cannot be NULL.");
|
||||
@@ -276,7 +283,7 @@ errorret_t assetFileLineReaderNext(assetfilelinereader_t *reader) {
|
||||
|
||||
reader->lineLength = 0;
|
||||
|
||||
for(;;) {
|
||||
for(;) {
|
||||
ssize_t newlineIndex = assetFileLineReaderFindNewline(reader);
|
||||
|
||||
if(newlineIndex >= 0) {
|
||||
@@ -284,7 +291,10 @@ errorret_t assetFileLineReaderNext(assetfilelinereader_t *reader) {
|
||||
errorret_t ret;
|
||||
|
||||
/* strip CR in CRLF */
|
||||
if(chunkLength > 0 && reader->readBuffer[(size_t)newlineIndex - 1] == '\r') {
|
||||
if(
|
||||
chunkLength > 0 &&
|
||||
reader->readBuffer[(size_t)newlineIndex - 1] == '\r'
|
||||
) {
|
||||
chunkLength--;
|
||||
}
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ errorret_t assetLocaleParseHeader(
|
||||
|
||||
if(pluralIndex >= localeFile->pluralStateCount - 1) {
|
||||
errorThrow(
|
||||
"Too many plural conditions. Expected %d conditional clauses for nplurals=%d.",
|
||||
"Too many plural conditions. Expected %d clauses for nplurals=%d.",
|
||||
localeFile->pluralStateCount - 1,
|
||||
localeFile->pluralStateCount
|
||||
);
|
||||
|
||||
@@ -136,7 +136,7 @@ errorret_t consoleDraw(void) {
|
||||
&FONT_TEXTURE_DEFAULT
|
||||
));
|
||||
}
|
||||
errorOk();
|
||||
return spriteBatchFlush();
|
||||
}
|
||||
|
||||
void consoleDispose(void) {
|
||||
|
||||
@@ -119,8 +119,12 @@ void capsuleBuffer(
|
||||
{
|
||||
const float_t yTop = cy + halfHeight;
|
||||
const float_t yBot = cy - halfHeight;
|
||||
const float_t vTop = 1.0f - (float_t)capRings / (float_t)(2 * capRings + 1);
|
||||
const float_t vBot = 1.0f - (float_t)(capRings + 1) / (float_t)(2 * capRings + 1);
|
||||
const float_t vTop = (
|
||||
1.0f - (float_t)capRings / (float_t)(2 * capRings + 1)
|
||||
);
|
||||
const float_t vBot = (
|
||||
1.0f - (float_t)(capRings + 1) / (float_t)(2 * capRings + 1)
|
||||
);
|
||||
|
||||
for(int32_t j = 0; j < sectors; j++) {
|
||||
const float_t t1 = (float_t)j * sectorStep;
|
||||
@@ -152,8 +156,12 @@ void capsuleBuffer(
|
||||
const float_t lxz1 = radius * cosf(phi1);
|
||||
const float_t lxz2 = radius * cosf(phi2);
|
||||
|
||||
const float_t v1 = 1.0f - (float_t)(capRings + 1 + i) / (float_t)(2 * capRings + 1);
|
||||
const float_t v2 = 1.0f - (float_t)(capRings + 1 + i + 1) / (float_t)(2 * capRings + 1);
|
||||
const float_t v1 = (
|
||||
1.0f - (float_t)(capRings + 1 + i) / (float_t)(2 * capRings + 1)
|
||||
);
|
||||
const float_t v2 = (
|
||||
1.0f - (float_t)(capRings + 1 + i + 1) / (float_t)(2 * capRings + 1)
|
||||
);
|
||||
|
||||
for(int32_t j = 0; j < sectors; j++) {
|
||||
const float_t t1 = (float_t)j * sectorStep;
|
||||
|
||||
@@ -28,7 +28,7 @@ errorret_t cubeInit();
|
||||
* Buffers a 3D axis-aligned cube into the provided vertex array.
|
||||
* Writes CUBE_VERTEX_COUNT vertices (6 faces x 6 vertices, CCW winding).
|
||||
*
|
||||
* @param vertices The vertex array to buffer into (must hold CUBE_VERTEX_COUNT).
|
||||
* @param vertices The vertex array to buffer into.
|
||||
* @param min The minimum XYZ corner of the cube.
|
||||
* @param max The maximum XYZ corner of the cube.
|
||||
* @param color The color applied to all vertices.
|
||||
|
||||
@@ -34,10 +34,14 @@ errorret_t meshFlush(
|
||||
#ifdef meshFlushPlatform
|
||||
assertNotNull(mesh, "Mesh cannot be NULL");
|
||||
assertTrue(vertexOffset >= 0, "Vertex offset must be non-negative.");
|
||||
assertTrue(vertexCount == -1 || vertexCount > 0, "Vertex count incorrect.");
|
||||
assertTrue(
|
||||
vertexCount == -1 || vertexCount > 0, "Vertex count incorrect."
|
||||
);
|
||||
|
||||
int32_t vertCount = meshGetVertexCount(mesh);
|
||||
assertTrue(vertexOffset < (vertCount - 1), "Need at least one vert to draw");
|
||||
assertTrue(
|
||||
vertexOffset < (vertCount - 1), "Need at least one vert to draw"
|
||||
);
|
||||
|
||||
int32_t drawCount = vertexCount;
|
||||
if(vertexCount == -1) {
|
||||
|
||||
@@ -9,12 +9,6 @@
|
||||
#include "display/mesh/mesh.h"
|
||||
#include "display/color.h"
|
||||
|
||||
/**
|
||||
* Vertex layout:
|
||||
* 2 triangular end-caps (3 verts each) = 6
|
||||
* 3 rectangular side faces (6 verts each) = 18
|
||||
* Total = 24
|
||||
*/
|
||||
#define TRIPRISM_VERTEX_COUNT 24
|
||||
#define TRIPRISM_PRIMITIVE_TYPE MESH_PRIMITIVE_TYPE_TRIANGLES
|
||||
|
||||
@@ -35,13 +29,13 @@ errorret_t triPrismInit();
|
||||
* the prism is extruded along the Z axis between minZ and maxZ.
|
||||
* Writes TRIPRISM_VERTEX_COUNT (24) vertices (CCW winding).
|
||||
*
|
||||
* @param vertices Vertex array to write into (must hold TRIPRISM_VERTEX_COUNT).
|
||||
* @param x0,y0 First triangle vertex (XY).
|
||||
* @param x1,y1 Second triangle vertex (XY).
|
||||
* @param x2,y2 Third triangle vertex (XY).
|
||||
* @param minZ Near Z extent of the prism.
|
||||
* @param maxZ Far Z extent of the prism.
|
||||
* @param color Color applied to all vertices.
|
||||
* @param vertices Vertex array to write into.
|
||||
* @param x0,y0 First triangle vertex (XY).
|
||||
* @param x1,y1 Second triangle vertex (XY).
|
||||
* @param x2,y2 Third triangle vertex (XY).
|
||||
* @param minZ Near Z extent of the prism.
|
||||
* @param maxZ Far Z extent of the prism.
|
||||
* @param color Color applied to all vertices.
|
||||
*/
|
||||
void triPrismBuffer(
|
||||
meshvertex_t *vertices,
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
#pragma once
|
||||
#include "display/mesh/quad.h"
|
||||
|
||||
#define SPRITEBATCH_SPRITES_MAX 32
|
||||
#define SPRITEBATCH_SPRITES_MAX 256
|
||||
#define SPRITEBATCH_VERTEX_COUNT (SPRITEBATCH_SPRITES_MAX * QUAD_VERTEX_COUNT)
|
||||
#define SPRITEBATCH_FLUSH_COUNT 4
|
||||
#define SPRITEBATCH_FLUSH_COUNT 8
|
||||
#define SPRITEBATCH_SPRITES_MAX_PER_FLUSH (\
|
||||
SPRITEBATCH_SPRITES_MAX / SPRITEBATCH_FLUSH_COUNT \
|
||||
)
|
||||
|
||||
@@ -101,7 +101,7 @@ entityid_t componentGetEntitiesWithComponent(
|
||||
"Component ID OOB in entitiesWithComponent lookup"
|
||||
);
|
||||
assertTrue(
|
||||
componentGetIndex(i, used) < ENTITY_COUNT_MAX * ENTITY_COMPONENT_COUNT_MAX,
|
||||
componentGetIndex(i,used) < ENTITY_COUNT_MAX*ENTITY_COMPONENT_COUNT_MAX,
|
||||
"Component index OOB in entitiesWithComponent lookup"
|
||||
);
|
||||
assertTrue(
|
||||
|
||||
@@ -73,7 +73,8 @@ entityid_t entityCameraGetCurrent(void) {
|
||||
void entityCameraGetForward(const entityid_t entityId, vec2 out) {
|
||||
componentid_t posComp = entityGetComponent(entityId, COMPONENT_TYPE_POSITION);
|
||||
entityposition_t *pos = entityPositionGet(entityId, posComp);
|
||||
// View matrix column layout: M[col][row], forward = {-M[0][2], -M[1][2], -M[2][2]}
|
||||
// View matrix column layout: M[col][row],
|
||||
// forward = {-M[0][2], -M[1][2], -M[2][2]}
|
||||
float_t fx = -pos->transform[0][2];
|
||||
float_t fz = -pos->transform[2][2];
|
||||
float_t len = sqrtf(fx * fx + fz * fz);
|
||||
|
||||
@@ -55,7 +55,8 @@ void entityCameraGetProjection(
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns the entity ID of the first active camera, or ENTITY_COUNT_MAX if none.
|
||||
* Returns the entity ID of the first active camera, or ENTITY_COUNT_MAX if
|
||||
* none are active.
|
||||
*/
|
||||
entityid_t entityCameraGetCurrent(void);
|
||||
|
||||
|
||||
@@ -72,7 +72,9 @@ errorret_t entityMeshGeneratePlane(
|
||||
);
|
||||
entityMeshDispose(entityId, componentId);
|
||||
|
||||
comp->ownedVertices = memoryAllocate(PLANE_VERTEX_COUNT * sizeof(meshvertex_t));
|
||||
comp->ownedVertices = memoryAllocate(
|
||||
PLANE_VERTEX_COUNT * sizeof(meshvertex_t)
|
||||
);
|
||||
assertNotNull(comp->ownedVertices, "Failed to allocate plane vertices");
|
||||
|
||||
vec3 min = { -width * 0.5f, 0.0f, -height * 0.5f };
|
||||
@@ -114,7 +116,9 @@ errorret_t entityMeshGenerateCapsule(
|
||||
);
|
||||
entityMeshDispose(entityId, componentId);
|
||||
|
||||
comp->ownedVertices = memoryAllocate(CAPSULE_VERTEX_COUNT * sizeof(meshvertex_t));
|
||||
comp->ownedVertices = memoryAllocate(
|
||||
CAPSULE_VERTEX_COUNT * sizeof(meshvertex_t)
|
||||
);
|
||||
assertNotNull(comp->ownedVertices, "Failed to allocate capsule vertices");
|
||||
|
||||
vec3 center = { 0.0f, 0.0f, 0.0f };
|
||||
|
||||
@@ -44,7 +44,7 @@ mesh_t * entityMeshGetMesh(
|
||||
*
|
||||
* @param entityId The entity ID.
|
||||
* @param componentId The component ID.
|
||||
* @param mesh A pointer to the mesh to associate with the entity mesh component.
|
||||
* @param mesh A pointer to the mesh to associate.
|
||||
*/
|
||||
void entityMeshSetMesh(
|
||||
const entityid_t entityId,
|
||||
|
||||
@@ -83,7 +83,9 @@ errorret_t errorChainImpl(
|
||||
assertNotNull(retval.state->message, "Message cannot be NULL");
|
||||
|
||||
// Create a new line string.
|
||||
int32_t newLineLen = snprintf(NULL, 0, ERROR_LINE_FORMAT, file, line, function);
|
||||
int32_t newLineLen = snprintf(
|
||||
NULL, 0, ERROR_LINE_FORMAT, file, line, function
|
||||
);
|
||||
assertTrue(newLineLen >= 0, "Line formatting failed");
|
||||
char_t *newLine = (char_t *)memoryAllocate(newLineLen + 1);
|
||||
snprintf(newLine, newLineLen + 1, ERROR_LINE_FORMAT, file, line, function);
|
||||
|
||||
@@ -25,17 +25,11 @@ typedef enum {
|
||||
|
||||
typedef struct {
|
||||
uint8_t ip[NETWORK_INFO_IPV4_OCTET_COUNT];
|
||||
// uint8_t subnet[NETWORK_INFO_IPV4_OCTET_COUNT];
|
||||
// uint8_t gateway[NETWORK_INFO_IPV4_OCTET_COUNT];
|
||||
// uint8_t dns[NETWORK_INFO_IPV4_OCTET_COUNT][NETWORK_INFO_IPV4_DNS_COUNT_MAX];
|
||||
} networkinfoipv4_t;
|
||||
|
||||
#ifdef DUSK_NETWORK_IPV6
|
||||
typedef struct {
|
||||
uint8_t ip[NETWORK_INFO_IPV6_OCTET_COUNT];
|
||||
// uint8_t subnet[NETWORK_INFO_IPV6_OCTET_COUNT];
|
||||
// uint8_t gateway[NETWORK_INFO_IPV6_OCTET_COUNT];
|
||||
// uint8_t dns[NETWORK_INFO_IPV6_OCTET_COUNT][NETWORK_INFO_IPV6_DNS_COUNT_MAX];
|
||||
} networkinfoipv6_t;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ void physicsWorldStep(const float_t dt) {
|
||||
}
|
||||
|
||||
/* Phase 1: integrate dynamic bodies (gravity + velocity → position).
|
||||
* Writes directly to pos->position — matrix rebuilt at end. */
|
||||
* Writes directly to pos->position, matrix rebuilt at end. */
|
||||
for(entityid_t i = 0; i < physCount; i++) {
|
||||
if(!positions[i]) continue;
|
||||
entityphysics_t *phys = physBodies[i];
|
||||
|
||||
@@ -43,7 +43,7 @@ moduleBaseFunction(moduleConsoleGetVisible) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleConsoleSetVisible) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
if(!jerry_value_is_boolean(args[0])) {
|
||||
return moduleBaseThrow("Console.visible: expected boolean");
|
||||
}
|
||||
|
||||
@@ -42,7 +42,11 @@ moduleBaseFunction(moduleColorGetA) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleColorSetR) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
if(argc < 1) {
|
||||
return moduleBaseThrow("Expected at least 1 argument");
|
||||
}
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
color_t *c = moduleColorGet(callInfo);
|
||||
if(!c) return jerry_undefined();
|
||||
c->r = (colorchannel8_t)jerry_value_as_number(args[0]);
|
||||
@@ -50,7 +54,11 @@ moduleBaseFunction(moduleColorSetR) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleColorSetG) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
if(argc < 1) {
|
||||
return moduleBaseThrow("Expected at least 1 argument");
|
||||
}
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
color_t *c = moduleColorGet(callInfo);
|
||||
if(!c) return jerry_undefined();
|
||||
c->g = (colorchannel8_t)jerry_value_as_number(args[0]);
|
||||
@@ -58,7 +66,11 @@ moduleBaseFunction(moduleColorSetG) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleColorSetB) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
if(argc < 1) {
|
||||
return moduleBaseThrow("Expected at least 1 argument");
|
||||
}
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
color_t *c = moduleColorGet(callInfo);
|
||||
if(!c) return jerry_undefined();
|
||||
c->b = (colorchannel8_t)jerry_value_as_number(args[0]);
|
||||
@@ -66,7 +78,11 @@ moduleBaseFunction(moduleColorSetB) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleColorSetA) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
if(argc < 1) {
|
||||
return moduleBaseThrow("Expected at least 1 argument");
|
||||
}
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
color_t *c = moduleColorGet(callInfo);
|
||||
if(!c) return jerry_undefined();
|
||||
c->a = (colorchannel8_t)jerry_value_as_number(args[0]);
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "script/module/modulebase.h"
|
||||
#include "script/scriptproto.h"
|
||||
#include "script/module/display/modulecolor.h"
|
||||
#include "script/module/math/modulevec2.h"
|
||||
#include "script/module/math/modulevec3.h"
|
||||
#include "display/spritebatch/spritebatch.h"
|
||||
|
||||
static scriptproto_t MODULE_SPRITEBATCH_PROTO;
|
||||
|
||||
moduleBaseFunction(moduleSpriteBatchGetSpriteCount) {
|
||||
return jerry_number(SPRITEBATCH.spriteCount);
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleSpriteBatchPush) {
|
||||
#if MESH_ENABLE_COLOR
|
||||
if(argc < 9) return moduleBaseThrow("expected 9 arguments");
|
||||
#else
|
||||
if(argc < 8) return moduleBaseThrow("expected 8 arguments");
|
||||
#endif
|
||||
|
||||
moduleBaseRequireNumber(0);
|
||||
moduleBaseRequireNumber(1);
|
||||
moduleBaseRequireNumber(2);
|
||||
moduleBaseRequireNumber(3);
|
||||
|
||||
#if MESH_ENABLE_COLOR
|
||||
if(!jerry_value_is_object(args[4])) {
|
||||
return moduleBaseThrow("color must be a Color object");
|
||||
}
|
||||
color_t *col = (color_t *)scriptProtoGetValue(&MODULE_COLOR_PROTO, args[4]);
|
||||
if(!col) {
|
||||
return moduleBaseThrow("color must be a Color object");
|
||||
}
|
||||
moduleBaseRequireNumber(5);
|
||||
moduleBaseRequireNumber(6);
|
||||
moduleBaseRequireNumber(7);
|
||||
moduleBaseRequireNumber(8);
|
||||
spriteBatchPush(
|
||||
(float_t)jerry_value_as_number(args[0]),
|
||||
(float_t)jerry_value_as_number(args[1]),
|
||||
(float_t)jerry_value_as_number(args[2]),
|
||||
(float_t)jerry_value_as_number(args[3]),
|
||||
*col,
|
||||
(float_t)jerry_value_as_number(args[5]),
|
||||
(float_t)jerry_value_as_number(args[6]),
|
||||
(float_t)jerry_value_as_number(args[7]),
|
||||
(float_t)jerry_value_as_number(args[8])
|
||||
);
|
||||
#else
|
||||
moduleBaseRequireNumber(4);
|
||||
moduleBaseRequireNumber(5);
|
||||
moduleBaseRequireNumber(6);
|
||||
moduleBaseRequireNumber(7);
|
||||
spriteBatchPush(
|
||||
(float_t)jerry_value_as_number(args[0]),
|
||||
(float_t)jerry_value_as_number(args[1]),
|
||||
(float_t)jerry_value_as_number(args[2]),
|
||||
(float_t)jerry_value_as_number(args[3]),
|
||||
(float_t)jerry_value_as_number(args[4]),
|
||||
(float_t)jerry_value_as_number(args[5]),
|
||||
(float_t)jerry_value_as_number(args[6]),
|
||||
(float_t)jerry_value_as_number(args[7])
|
||||
);
|
||||
#endif
|
||||
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleSpriteBatchPush3D) {
|
||||
#if MESH_ENABLE_COLOR
|
||||
if(argc < 5) return moduleBaseThrow("expected 5 arguments");
|
||||
#else
|
||||
if(argc < 4) return moduleBaseThrow("expected 4 arguments");
|
||||
#endif
|
||||
|
||||
if(!jerry_value_is_object(args[0])) {
|
||||
return moduleBaseThrow("min must be a Vec3");
|
||||
}
|
||||
float_t *min = moduleVec3From(args[0]);
|
||||
if(!min) return moduleBaseThrow("min must be a Vec3");
|
||||
|
||||
if(!jerry_value_is_object(args[1])) {
|
||||
return moduleBaseThrow("max must be a Vec3");
|
||||
}
|
||||
float_t *max = moduleVec3From(args[1]);
|
||||
if(!max) return moduleBaseThrow("max must be a Vec3");
|
||||
|
||||
#if MESH_ENABLE_COLOR
|
||||
if(!jerry_value_is_object(args[2])) {
|
||||
return moduleBaseThrow("color must be a Color object");
|
||||
}
|
||||
color_t *col = (color_t *)scriptProtoGetValue(&MODULE_COLOR_PROTO, args[2]);
|
||||
if(!col) {
|
||||
return moduleBaseThrow("color must be a Color object");
|
||||
}
|
||||
|
||||
if(!jerry_value_is_object(args[3])) {
|
||||
return moduleBaseThrow("uvMin must be a Vec2");
|
||||
}
|
||||
float_t *uvMin = moduleVec2From(args[3]);
|
||||
if(!uvMin) return moduleBaseThrow("uvMin must be a Vec2");
|
||||
|
||||
if(!jerry_value_is_object(args[4])) {
|
||||
return moduleBaseThrow("uvMax must be a Vec2");
|
||||
}
|
||||
float_t *uvMax = moduleVec2From(args[4]);
|
||||
if(!uvMax) return moduleBaseThrow("uvMax must be a Vec2");
|
||||
|
||||
spriteBatchPush3D(min, max, *col, uvMin, uvMax);
|
||||
#else
|
||||
if(!jerry_value_is_object(args[2])) {
|
||||
return moduleBaseThrow("uvMin must be a Vec2");
|
||||
}
|
||||
float_t *uvMin = moduleVec2From(args[2]);
|
||||
if(!uvMin) return moduleBaseThrow("uvMin must be a Vec2");
|
||||
|
||||
if(!jerry_value_is_object(args[3])) {
|
||||
return moduleBaseThrow("uvMax must be a Vec2");
|
||||
}
|
||||
float_t *uvMax = moduleVec2From(args[3]);
|
||||
if(!uvMax) return moduleBaseThrow("uvMax must be a Vec2");
|
||||
|
||||
spriteBatchPush3D(min, max, uvMin, uvMax);
|
||||
#endif
|
||||
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleSpriteBatchClear) {
|
||||
spriteBatchClear();
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleSpriteBatchFlush) {
|
||||
spriteBatchFlush();
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
static void moduleSpriteBatch(void) {
|
||||
scriptProtoInit(
|
||||
&MODULE_SPRITEBATCH_PROTO, "SpriteBatch", sizeof(uint8_t), NULL
|
||||
);
|
||||
|
||||
scriptProtoDefineStaticProp(
|
||||
&MODULE_SPRITEBATCH_PROTO, "spriteCount",
|
||||
moduleSpriteBatchGetSpriteCount, NULL
|
||||
);
|
||||
|
||||
scriptProtoDefineStaticFunc(
|
||||
&MODULE_SPRITEBATCH_PROTO, "push", moduleSpriteBatchPush
|
||||
);
|
||||
scriptProtoDefineStaticFunc(
|
||||
&MODULE_SPRITEBATCH_PROTO, "push3D", moduleSpriteBatchPush3D
|
||||
);
|
||||
scriptProtoDefineStaticFunc(
|
||||
&MODULE_SPRITEBATCH_PROTO, "clear", moduleSpriteBatchClear
|
||||
);
|
||||
scriptProtoDefineStaticFunc(
|
||||
&MODULE_SPRITEBATCH_PROTO, "flush", moduleSpriteBatchFlush
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "script/module/modulebase.h"
|
||||
#include "script/scriptproto.h"
|
||||
#include "script/module/display/modulecolor.h"
|
||||
#include "display/text/text.h"
|
||||
|
||||
static scriptproto_t MODULE_TEXT_PROTO;
|
||||
|
||||
moduleBaseFunction(moduleTextDraw) {
|
||||
if(argc < 3) return moduleBaseThrow("expected at least 3 arguments");
|
||||
moduleBaseRequireNumber(0);
|
||||
moduleBaseRequireNumber(1);
|
||||
if(!jerry_value_is_string(args[2])) {
|
||||
return moduleBaseThrow("text must be a string");
|
||||
}
|
||||
|
||||
float_t x = (float_t)jerry_value_as_number(args[0]);
|
||||
float_t y = (float_t)jerry_value_as_number(args[1]);
|
||||
|
||||
char_t text[1024];
|
||||
moduleBaseToString(args[2], text, sizeof(text));
|
||||
|
||||
color_t col = COLOR_WHITE;
|
||||
if(argc >= 4 && jerry_value_is_object(args[3])) {
|
||||
color_t *c = (color_t *)scriptProtoGetValue(&MODULE_COLOR_PROTO, args[3]);
|
||||
if(c) col = *c;
|
||||
}
|
||||
|
||||
errorret_t err = textDraw(
|
||||
x, y, text, col, &FONT_TILESET_DEFAULT, &FONT_TEXTURE_DEFAULT
|
||||
);
|
||||
if(err.code != ERROR_OK) {
|
||||
errorCatch(errorPrint(err));
|
||||
return moduleBaseThrow("Text draw failed");
|
||||
}
|
||||
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleTextMeasure) {
|
||||
if(argc < 1) return moduleBaseThrow("expected at least 1 argument");
|
||||
if(!jerry_value_is_string(args[0])) {
|
||||
return moduleBaseThrow("text must be a string");
|
||||
}
|
||||
|
||||
char_t text[1024];
|
||||
moduleBaseToString(args[0], text, sizeof(text));
|
||||
|
||||
int32_t w, h;
|
||||
textMeasure(text, &FONT_TILESET_DEFAULT, &w, &h);
|
||||
|
||||
jerry_value_t obj = jerry_object();
|
||||
jerry_value_t wKey = jerry_string_sz("width");
|
||||
jerry_value_t hKey = jerry_string_sz("height");
|
||||
jerry_value_t wVal = jerry_number(w);
|
||||
jerry_value_t hVal = jerry_number(h);
|
||||
jerry_object_set(obj, wKey, wVal);
|
||||
jerry_object_set(obj, hKey, hVal);
|
||||
jerry_value_free(wKey);
|
||||
jerry_value_free(hKey);
|
||||
jerry_value_free(wVal);
|
||||
jerry_value_free(hVal);
|
||||
return obj;
|
||||
}
|
||||
|
||||
static void moduleText(void) {
|
||||
scriptProtoInit(&MODULE_TEXT_PROTO, "Text", sizeof(uint8_t), NULL);
|
||||
scriptProtoDefineStaticFunc(&MODULE_TEXT_PROTO, "draw", moduleTextDraw);
|
||||
scriptProtoDefineStaticFunc(&MODULE_TEXT_PROTO, "measure", moduleTextMeasure);
|
||||
}
|
||||
@@ -188,7 +188,9 @@ moduleBaseFunction(moduleEntityCameraSetProjectionType) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleEntityCameraAdd) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
entityid_t id = (entityid_t)jerry_value_as_number(args[0]);
|
||||
componentid_t comp = entityAddComponent(id, COMPONENT_TYPE_CAMERA);
|
||||
componenthandle_t h = { .eid = id, .cid = comp };
|
||||
|
||||
@@ -28,7 +28,7 @@ static entitymaterial_t * moduleEntityMaterialGet(
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleEntityMaterialSetColor) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
if(!jerry_value_is_object(args[0])) {
|
||||
return moduleBaseThrow("expected color object");
|
||||
}
|
||||
@@ -68,7 +68,11 @@ moduleBaseFunction(moduleEntityMaterialSetColor) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleEntityMaterialAdd) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
if(argc < 1) {
|
||||
return moduleBaseThrow("Expected at least 1 argument");
|
||||
}
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
entityid_t id = (entityid_t)jerry_value_as_number(args[0]);
|
||||
componentid_t comp = entityAddComponent(id, COMPONENT_TYPE_MATERIAL);
|
||||
componenthandle_t h = { .eid = id, .cid = comp };
|
||||
|
||||
@@ -25,7 +25,11 @@ static entitymesh_t * moduleEntityMeshGet(
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleEntityMeshAdd) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
if(argc < 1) {
|
||||
return moduleBaseThrow("Expected at least 1 argument");
|
||||
}
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
entityid_t id = (entityid_t)jerry_value_as_number(args[0]);
|
||||
componentid_t comp = entityAddComponent(id, COMPONENT_TYPE_MESH);
|
||||
componenthandle_t h = { .eid = id, .cid = comp };
|
||||
|
||||
@@ -32,7 +32,7 @@ moduleBaseFunction(moduleEntityPhysicsGetVelocity) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleEntityPhysicsSetVelocity) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
entityphysics_t *phys = moduleEntityPhysicsGet(callInfo);
|
||||
if(!phys) return jerry_undefined();
|
||||
vec3 v;
|
||||
@@ -56,7 +56,11 @@ moduleBaseFunction(moduleEntityPhysicsGetBodyType) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleEntityPhysicsSetBodyType) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
if(argc < 1) {
|
||||
return moduleBaseThrow("Expected at least 1 argument");
|
||||
}
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
entityphysics_t *phys = moduleEntityPhysicsGet(callInfo);
|
||||
if(!phys) return jerry_undefined();
|
||||
phys->type = (physicsbodytype_t)(int32_t)jerry_value_as_number(args[0]);
|
||||
@@ -64,7 +68,7 @@ moduleBaseFunction(moduleEntityPhysicsSetBodyType) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleEntityPhysicsApplyImpulse) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
entityphysics_t *phys = moduleEntityPhysicsGet(callInfo);
|
||||
if(!phys) return jerry_undefined();
|
||||
if(phys->type == PHYSICS_BODY_STATIC) return jerry_undefined();
|
||||
@@ -77,7 +81,7 @@ moduleBaseFunction(moduleEntityPhysicsApplyImpulse) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleEntityPhysicsSetShapeCube) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
entityphysics_t *phys = moduleEntityPhysicsGet(callInfo);
|
||||
if(!phys) return jerry_undefined();
|
||||
vec3 half;
|
||||
@@ -90,7 +94,11 @@ moduleBaseFunction(moduleEntityPhysicsSetShapeCube) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleEntityPhysicsSetShapeSphere) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
if(argc < 1) {
|
||||
return moduleBaseThrow("Expected at least 1 argument");
|
||||
}
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
entityphysics_t *phys = moduleEntityPhysicsGet(callInfo);
|
||||
if(!phys) return jerry_undefined();
|
||||
phys->shape.type = PHYSICS_SHAPE_SPHERE;
|
||||
@@ -99,7 +107,7 @@ moduleBaseFunction(moduleEntityPhysicsSetShapeSphere) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleEntityPhysicsSetShapeCapsule) {
|
||||
moduleBaseRequireArgs(2);
|
||||
if(argc < 2) return moduleBaseThrow("Expected at least 2 arguments");
|
||||
moduleBaseRequireNumber(0); moduleBaseRequireNumber(1);
|
||||
entityphysics_t *phys = moduleEntityPhysicsGet(callInfo);
|
||||
if(!phys) return jerry_undefined();
|
||||
@@ -111,7 +119,11 @@ moduleBaseFunction(moduleEntityPhysicsSetShapeCapsule) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleEntityPhysicsSetShapePlane) {
|
||||
moduleBaseRequireArgs(2); moduleBaseRequireNumber(1);
|
||||
if(argc < 2) {
|
||||
return moduleBaseThrow("Expected at least 2 arguments");
|
||||
}
|
||||
moduleBaseRequireNumber(1);
|
||||
|
||||
entityphysics_t *phys = moduleEntityPhysicsGet(callInfo);
|
||||
if(!phys) return jerry_undefined();
|
||||
vec3 normal;
|
||||
@@ -125,7 +137,11 @@ moduleBaseFunction(moduleEntityPhysicsSetShapePlane) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleEntityPhysicsAdd) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
if(argc < 1) {
|
||||
return moduleBaseThrow("Expected at least 1 argument");
|
||||
}
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
entityid_t id = (entityid_t)jerry_value_as_number(args[0]);
|
||||
componentid_t comp = entityAddComponent(id, COMPONENT_TYPE_PHYSICS);
|
||||
componenthandle_t h = { .eid = id, .cid = comp };
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include "entity/entity.h"
|
||||
#include "entity/component/display/entityposition.h"
|
||||
|
||||
// Shared component handle struct — defined once, used by all component modules.
|
||||
#ifndef COMPONENT_HANDLE_DEFINED
|
||||
#define COMPONENT_HANDLE_DEFINED
|
||||
typedef struct {
|
||||
@@ -42,7 +41,7 @@ moduleBaseFunction(moduleEntityPositionGetPosition) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleEntityPositionSetPosition) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
entityposition_t *pos = moduleEntityPositionGet(callInfo);
|
||||
if(!pos) return jerry_undefined();
|
||||
vec3 v;
|
||||
@@ -63,7 +62,7 @@ moduleBaseFunction(moduleEntityPositionGetRotation) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleEntityPositionSetRotation) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
entityposition_t *pos = moduleEntityPositionGet(callInfo);
|
||||
if(!pos) return jerry_undefined();
|
||||
vec3 v;
|
||||
@@ -84,7 +83,7 @@ moduleBaseFunction(moduleEntityPositionGetScale) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleEntityPositionSetScale) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
entityposition_t *pos = moduleEntityPositionGet(callInfo);
|
||||
if(!pos) return jerry_undefined();
|
||||
vec3 v;
|
||||
@@ -97,7 +96,7 @@ moduleBaseFunction(moduleEntityPositionSetScale) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleEntityPositionLookAt) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
entityposition_t *pos = moduleEntityPositionGet(callInfo);
|
||||
if(!pos) return jerry_undefined();
|
||||
vec3 target;
|
||||
@@ -114,7 +113,11 @@ moduleBaseFunction(moduleEntityPositionLookAt) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleEntityPositionAdd) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
if(argc < 1) {
|
||||
return moduleBaseThrow("Expected at least 1 argument");
|
||||
}
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
entityid_t id = (entityid_t)jerry_value_as_number(args[0]);
|
||||
componentid_t comp = entityAddComponent(id, COMPONENT_TYPE_POSITION);
|
||||
componenthandle_t h = { .eid = id, .cid = comp };
|
||||
|
||||
@@ -15,7 +15,7 @@ static scriptproto_t MODULE_INPUT_PROTO;
|
||||
|
||||
// Static Methods
|
||||
moduleBaseFunction(moduleInputBind) {
|
||||
moduleBaseRequireArgs(2);
|
||||
if(argc < 2) return moduleBaseThrow("Expected at least 2 arguments");
|
||||
moduleBaseRequireString(0);
|
||||
moduleBaseRequireNumber(1);
|
||||
|
||||
@@ -40,7 +40,11 @@ moduleBaseFunction(moduleInputBind) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleInputIsDown) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
if(argc < 1) {
|
||||
return moduleBaseThrow("Expected at least 1 argument");
|
||||
}
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
const inputaction_t action = (inputaction_t)jerry_value_as_number(args[0]);
|
||||
if(action <= INPUT_ACTION_NULL || action >= INPUT_ACTION_COUNT) {
|
||||
return moduleBaseThrow("Input.isDown: invalid action");
|
||||
@@ -49,7 +53,11 @@ moduleBaseFunction(moduleInputIsDown) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleInputPressed) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
if(argc < 1) {
|
||||
return moduleBaseThrow("Expected at least 1 argument");
|
||||
}
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
const inputaction_t action = (inputaction_t)jerry_value_as_number(args[0]);
|
||||
if(action <= INPUT_ACTION_NULL || action >= INPUT_ACTION_COUNT) {
|
||||
return moduleBaseThrow("Input.pressed: invalid action");
|
||||
@@ -58,7 +66,11 @@ moduleBaseFunction(moduleInputPressed) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleInputReleased) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
if(argc < 1) {
|
||||
return moduleBaseThrow("Expected at least 1 argument");
|
||||
}
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
const inputaction_t action = (inputaction_t)jerry_value_as_number(args[0]);
|
||||
if(action <= INPUT_ACTION_NULL || action >= INPUT_ACTION_COUNT) {
|
||||
return moduleBaseThrow("Input.released: invalid action");
|
||||
@@ -67,7 +79,11 @@ moduleBaseFunction(moduleInputReleased) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleInputGetValue) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
if(argc < 1) {
|
||||
return moduleBaseThrow("Expected at least 1 argument");
|
||||
}
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
const inputaction_t action = (inputaction_t)jerry_value_as_number(args[0]);
|
||||
if(action <= INPUT_ACTION_NULL || action >= INPUT_ACTION_COUNT) {
|
||||
return moduleBaseThrow("Input.getValue: invalid action");
|
||||
@@ -76,7 +92,7 @@ moduleBaseFunction(moduleInputGetValue) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleInputAxis) {
|
||||
moduleBaseRequireArgs(2);
|
||||
if(argc < 2) return moduleBaseThrow("Expected at least 2 arguments");
|
||||
moduleBaseRequireNumber(0); moduleBaseRequireNumber(1);
|
||||
const inputaction_t neg = (inputaction_t)jerry_value_as_number(args[0]);
|
||||
const inputaction_t pos = (inputaction_t)jerry_value_as_number(args[1]);
|
||||
@@ -90,7 +106,7 @@ moduleBaseFunction(moduleInputAxis) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleInputAxis2D) {
|
||||
moduleBaseRequireArgs(4);
|
||||
if(argc < 4) return moduleBaseThrow("Expected at least 4 arguments");
|
||||
moduleBaseRequireNumber(0); moduleBaseRequireNumber(1);
|
||||
moduleBaseRequireNumber(2); moduleBaseRequireNumber(3);
|
||||
const inputaction_t negX = (inputaction_t)jerry_value_as_number(args[0]);
|
||||
|
||||
@@ -28,7 +28,7 @@ moduleBaseFunction(moduleMatConstructor) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleMatMul) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
float_t (*a)[4] = (float_t (*)[4])moduleMatGet(callInfo);
|
||||
if(!a) return moduleBaseThrow("Mat4.mul: invalid this");
|
||||
float_t (*b)[4] = (float_t (*)[4])scriptProtoGetValue(
|
||||
@@ -63,7 +63,7 @@ moduleBaseFunction(moduleMatDeterminant) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleMatMulVec3) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
float_t (*m)[4] = (float_t (*)[4])moduleMatGet(callInfo);
|
||||
if(!m) return moduleBaseThrow("Mat4.mulVec3: invalid this");
|
||||
vec3 vin;
|
||||
@@ -78,7 +78,7 @@ moduleBaseFunction(moduleMatMulVec3) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleMatMulVec4) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
float_t (*m)[4] = (float_t (*)[4])moduleMatGet(callInfo);
|
||||
if(!m) return moduleBaseThrow("Mat4.mulVec4: invalid this");
|
||||
vec4 vin;
|
||||
@@ -91,7 +91,7 @@ moduleBaseFunction(moduleMatMulVec4) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleMatTranslate) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
float_t (*m)[4] = (float_t (*)[4])moduleMatGet(callInfo);
|
||||
if(!m) return moduleBaseThrow("Mat4.translate: invalid this");
|
||||
vec3 tv;
|
||||
@@ -105,7 +105,7 @@ moduleBaseFunction(moduleMatTranslate) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleMatScale) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
float_t (*m)[4] = (float_t (*)[4])moduleMatGet(callInfo);
|
||||
if(!m) return moduleBaseThrow("Mat4.scale: invalid this");
|
||||
vec3 sv;
|
||||
@@ -125,7 +125,7 @@ moduleBaseFunction(moduleMatStaticIdentity) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleMatStaticPerspective) {
|
||||
moduleBaseRequireArgs(4);
|
||||
if(argc < 4) return moduleBaseThrow("Expected at least 4 arguments");
|
||||
moduleBaseRequireNumber(0); moduleBaseRequireNumber(1);
|
||||
moduleBaseRequireNumber(2); moduleBaseRequireNumber(3);
|
||||
mat4 r;
|
||||
@@ -140,7 +140,7 @@ moduleBaseFunction(moduleMatStaticPerspective) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleMatStaticLookAt) {
|
||||
moduleBaseRequireArgs(3);
|
||||
if(argc < 3) return moduleBaseThrow("Expected at least 3 arguments");
|
||||
vec3 eye, center, up;
|
||||
if(!moduleVec3Check(args[0], eye)) {
|
||||
return moduleBaseThrow("Mat4.lookAt: eye must be a Vec3");
|
||||
|
||||
@@ -55,7 +55,7 @@ moduleBaseFunction(moduleVec2SetY) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleVec2Dot) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
float_t *a = moduleVec2Get(callInfo);
|
||||
if(!a) return moduleBaseThrow("Vec2.dot: invalid this");
|
||||
float_t *b = moduleVec2From(args[0]);
|
||||
@@ -92,7 +92,7 @@ moduleBaseFunction(moduleVec2Negate) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleVec2Add) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
float_t *a = moduleVec2Get(callInfo);
|
||||
if(!a) return moduleBaseThrow("Vec2.add: invalid this");
|
||||
float_t *b = moduleVec2From(args[0]);
|
||||
@@ -103,7 +103,7 @@ moduleBaseFunction(moduleVec2Add) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleVec2Sub) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
float_t *a = moduleVec2Get(callInfo);
|
||||
if(!a) return moduleBaseThrow("Vec2.sub: invalid this");
|
||||
float_t *b = moduleVec2From(args[0]);
|
||||
@@ -114,7 +114,11 @@ moduleBaseFunction(moduleVec2Sub) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleVec2Scale) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
if(argc < 1) {
|
||||
return moduleBaseThrow("Expected at least 1 argument");
|
||||
}
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
float_t *v = moduleVec2Get(callInfo);
|
||||
if(!v) return moduleBaseThrow("Vec2.scale: invalid this");
|
||||
vec2 r;
|
||||
@@ -123,7 +127,11 @@ moduleBaseFunction(moduleVec2Scale) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleVec2Lerp) {
|
||||
moduleBaseRequireArgs(2); moduleBaseRequireNumber(1);
|
||||
if(argc < 2) {
|
||||
return moduleBaseThrow("Expected at least 2 arguments");
|
||||
}
|
||||
moduleBaseRequireNumber(1);
|
||||
|
||||
float_t *a = moduleVec2Get(callInfo);
|
||||
if(!a) return moduleBaseThrow("Vec2.lerp: invalid this");
|
||||
float_t *b = moduleVec2From(args[0]);
|
||||
@@ -134,7 +142,7 @@ moduleBaseFunction(moduleVec2Lerp) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleVec2Distance) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
float_t *a = moduleVec2Get(callInfo);
|
||||
if(!a) return moduleBaseThrow("Vec2.distance: invalid this");
|
||||
float_t *b = moduleVec2From(args[0]);
|
||||
@@ -176,14 +184,14 @@ static void moduleVec2(void) {
|
||||
|
||||
scriptProtoDefineToString(&MODULE_VEC2_PROTO, moduleVec2ToString);
|
||||
|
||||
scriptProtoDefineFunc(&MODULE_VEC2_PROTO, "dot", moduleVec2Dot);
|
||||
scriptProtoDefineFunc(&MODULE_VEC2_PROTO, "length", moduleVec2Length);
|
||||
scriptProtoDefineFunc(&MODULE_VEC2_PROTO, "lengthSq", moduleVec2LengthSq);
|
||||
scriptProtoDefineFunc(&MODULE_VEC2_PROTO, "dot", moduleVec2Dot);
|
||||
scriptProtoDefineFunc(&MODULE_VEC2_PROTO, "length", moduleVec2Length);
|
||||
scriptProtoDefineFunc(&MODULE_VEC2_PROTO, "lengthSq", moduleVec2LengthSq);
|
||||
scriptProtoDefineFunc(&MODULE_VEC2_PROTO, "normalize", moduleVec2Normalize);
|
||||
scriptProtoDefineFunc(&MODULE_VEC2_PROTO, "negate", moduleVec2Negate);
|
||||
scriptProtoDefineFunc(&MODULE_VEC2_PROTO, "add", moduleVec2Add);
|
||||
scriptProtoDefineFunc(&MODULE_VEC2_PROTO, "sub", moduleVec2Sub);
|
||||
scriptProtoDefineFunc(&MODULE_VEC2_PROTO, "scale", moduleVec2Scale);
|
||||
scriptProtoDefineFunc(&MODULE_VEC2_PROTO, "lerp", moduleVec2Lerp);
|
||||
scriptProtoDefineFunc(&MODULE_VEC2_PROTO, "distance", moduleVec2Distance);
|
||||
scriptProtoDefineFunc(&MODULE_VEC2_PROTO, "negate", moduleVec2Negate);
|
||||
scriptProtoDefineFunc(&MODULE_VEC2_PROTO, "add", moduleVec2Add);
|
||||
scriptProtoDefineFunc(&MODULE_VEC2_PROTO, "sub", moduleVec2Sub);
|
||||
scriptProtoDefineFunc(&MODULE_VEC2_PROTO, "scale", moduleVec2Scale);
|
||||
scriptProtoDefineFunc(&MODULE_VEC2_PROTO, "lerp", moduleVec2Lerp);
|
||||
scriptProtoDefineFunc(&MODULE_VEC2_PROTO, "distance", moduleVec2Distance);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ moduleBaseFunction(moduleVec3SetZ) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleVec3Dot) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
float_t *a = moduleVec3Get(callInfo);
|
||||
if(!a) return moduleBaseThrow("Vec3.dot: invalid this");
|
||||
float_t *b = moduleVec3From(args[0]);
|
||||
@@ -76,7 +76,7 @@ moduleBaseFunction(moduleVec3Dot) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleVec3Cross) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
float_t *a = moduleVec3Get(callInfo);
|
||||
if(!a) return moduleBaseThrow("Vec3.cross: invalid this");
|
||||
float_t *b = moduleVec3From(args[0]);
|
||||
@@ -115,7 +115,7 @@ moduleBaseFunction(moduleVec3Negate) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleVec3Add) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
float_t *a = moduleVec3Get(callInfo);
|
||||
if(!a) return moduleBaseThrow("Vec3.add: invalid this");
|
||||
float_t *b = moduleVec3From(args[0]);
|
||||
@@ -126,7 +126,7 @@ moduleBaseFunction(moduleVec3Add) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleVec3Sub) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
float_t *a = moduleVec3Get(callInfo);
|
||||
if(!a) return moduleBaseThrow("Vec3.sub: invalid this");
|
||||
float_t *b = moduleVec3From(args[0]);
|
||||
@@ -137,7 +137,11 @@ moduleBaseFunction(moduleVec3Sub) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleVec3Scale) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
if(argc < 1) {
|
||||
return moduleBaseThrow("Expected at least 1 argument");
|
||||
}
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
float_t *v = moduleVec3Get(callInfo);
|
||||
if(!v) return moduleBaseThrow("Vec3.scale: invalid this");
|
||||
vec3 r;
|
||||
@@ -146,7 +150,11 @@ moduleBaseFunction(moduleVec3Scale) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleVec3Lerp) {
|
||||
moduleBaseRequireArgs(2); moduleBaseRequireNumber(1);
|
||||
if(argc < 2) {
|
||||
return moduleBaseThrow("Expected at least 2 arguments");
|
||||
}
|
||||
moduleBaseRequireNumber(1);
|
||||
|
||||
float_t *a = moduleVec3Get(callInfo);
|
||||
if(!a) return moduleBaseThrow("Vec3.lerp: invalid this");
|
||||
float_t *b = moduleVec3From(args[0]);
|
||||
@@ -157,7 +165,7 @@ moduleBaseFunction(moduleVec3Lerp) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleVec3Distance) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
float_t *a = moduleVec3Get(callInfo);
|
||||
if(!a) return moduleBaseThrow("Vec3.distance: invalid this");
|
||||
float_t *b = moduleVec3From(args[0]);
|
||||
|
||||
@@ -121,7 +121,7 @@ moduleBaseFunction(moduleVec4SetV1) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleVec4Dot) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
float_t *a = moduleVec4Get(callInfo);
|
||||
if(!a) return moduleBaseThrow("Vec4.dot: invalid this");
|
||||
float_t *b = moduleVec4From(args[0]);
|
||||
@@ -158,7 +158,7 @@ moduleBaseFunction(moduleVec4Negate) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleVec4Add) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
float_t *a = moduleVec4Get(callInfo);
|
||||
if(!a) return moduleBaseThrow("Vec4.add: invalid this");
|
||||
float_t *b = moduleVec4From(args[0]);
|
||||
@@ -169,7 +169,7 @@ moduleBaseFunction(moduleVec4Add) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleVec4Sub) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
float_t *a = moduleVec4Get(callInfo);
|
||||
if(!a) return moduleBaseThrow("Vec4.sub: invalid this");
|
||||
float_t *b = moduleVec4From(args[0]);
|
||||
@@ -180,7 +180,11 @@ moduleBaseFunction(moduleVec4Sub) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleVec4Scale) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
if(argc < 1) {
|
||||
return moduleBaseThrow("Expected at least 1 argument");
|
||||
}
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
float_t *v = moduleVec4Get(callInfo);
|
||||
if(!v) return moduleBaseThrow("Vec4.scale: invalid this");
|
||||
vec4 r;
|
||||
@@ -189,7 +193,11 @@ moduleBaseFunction(moduleVec4Scale) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleVec4Lerp) {
|
||||
moduleBaseRequireArgs(2); moduleBaseRequireNumber(1);
|
||||
if(argc < 2) {
|
||||
return moduleBaseThrow("Expected at least 2 arguments");
|
||||
}
|
||||
moduleBaseRequireNumber(1);
|
||||
|
||||
float_t *a = moduleVec4Get(callInfo);
|
||||
if(!a) return moduleBaseThrow("Vec4.lerp: invalid this");
|
||||
float_t *b = moduleVec4From(args[0]);
|
||||
@@ -256,13 +264,13 @@ static void moduleVec4(void) {
|
||||
|
||||
scriptProtoDefineToString(&MODULE_VEC4_PROTO, moduleVec4ToString);
|
||||
|
||||
scriptProtoDefineFunc(&MODULE_VEC4_PROTO, "dot", moduleVec4Dot);
|
||||
scriptProtoDefineFunc(&MODULE_VEC4_PROTO, "length", moduleVec4Length);
|
||||
scriptProtoDefineFunc(&MODULE_VEC4_PROTO, "lengthSq", moduleVec4LengthSq);
|
||||
scriptProtoDefineFunc(&MODULE_VEC4_PROTO, "dot", moduleVec4Dot);
|
||||
scriptProtoDefineFunc(&MODULE_VEC4_PROTO, "length", moduleVec4Length);
|
||||
scriptProtoDefineFunc(&MODULE_VEC4_PROTO, "lengthSq", moduleVec4LengthSq);
|
||||
scriptProtoDefineFunc(&MODULE_VEC4_PROTO, "normalize", moduleVec4Normalize);
|
||||
scriptProtoDefineFunc(&MODULE_VEC4_PROTO, "negate", moduleVec4Negate);
|
||||
scriptProtoDefineFunc(&MODULE_VEC4_PROTO, "add", moduleVec4Add);
|
||||
scriptProtoDefineFunc(&MODULE_VEC4_PROTO, "sub", moduleVec4Sub);
|
||||
scriptProtoDefineFunc(&MODULE_VEC4_PROTO, "scale", moduleVec4Scale);
|
||||
scriptProtoDefineFunc(&MODULE_VEC4_PROTO, "lerp", moduleVec4Lerp);
|
||||
scriptProtoDefineFunc(&MODULE_VEC4_PROTO, "negate", moduleVec4Negate);
|
||||
scriptProtoDefineFunc(&MODULE_VEC4_PROTO, "add", moduleVec4Add);
|
||||
scriptProtoDefineFunc(&MODULE_VEC4_PROTO, "sub", moduleVec4Sub);
|
||||
scriptProtoDefineFunc(&MODULE_VEC4_PROTO, "scale", moduleVec4Scale);
|
||||
scriptProtoDefineFunc(&MODULE_VEC4_PROTO, "lerp", moduleVec4Lerp);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "script/module/time/moduletime.h"
|
||||
#include "script/module/display/modulecolor.h"
|
||||
#include "script/module/display/modulescreen.h"
|
||||
#include "script/module/display/modulespritebatch.h"
|
||||
#include "script/module/display/moduletext.h"
|
||||
#include "script/module/scene/modulescene.h"
|
||||
#include "script/module/console/moduleconsole.h"
|
||||
#include "script/module/engine/moduleengine.h"
|
||||
@@ -27,6 +29,8 @@ static void moduleRegister(void) {
|
||||
moduleTime();
|
||||
moduleColor();
|
||||
moduleScreen();
|
||||
moduleSpriteBatch();
|
||||
moduleText();
|
||||
moduleScene();
|
||||
moduleConsole();
|
||||
moduleEngine();
|
||||
|
||||
@@ -213,14 +213,6 @@ static void moduleBaseCreateGlobalObject(
|
||||
jerry_value_free(global);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert at least n arguments were passed; return type error if not.
|
||||
*/
|
||||
#define moduleBaseRequireArgs(n) \
|
||||
if((argc) < (n)) { \
|
||||
return moduleBaseThrow("Expected at least " #n " arguments"); \
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert an argument is a number; return type error if not.
|
||||
*/
|
||||
|
||||
@@ -25,7 +25,7 @@ moduleBaseFunction(moduleSceneDefaultConstructor) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleSceneSet) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(argc < 1) return moduleBaseThrow("Expected at least 1 argument");
|
||||
moduleBaseRequireString(0);
|
||||
|
||||
char_t name[ASSET_FILE_PATH_MAX];
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "script/module/modulebase.h"
|
||||
#include "script/scriptmanager.h"
|
||||
|
||||
moduleBaseFunction(moduleIncludeInclude) {
|
||||
if(argc < 1 || !jerry_value_is_string(args[0])) {
|
||||
@@ -25,32 +26,9 @@ moduleBaseFunction(moduleIncludeInclude) {
|
||||
return moduleBaseThrow("include: filename must end with .js");
|
||||
}
|
||||
|
||||
char_t buffer[1024];
|
||||
stringCopy(buffer, filename, sizeof(buffer));
|
||||
|
||||
// Save and reset 'export' so the included module gets a clean undefined
|
||||
// default. Saving lets nested includes each have their own export scope.
|
||||
jerry_value_t global = jerry_current_realm();
|
||||
jerry_value_t moduleKey = jerry_string_sz("module");
|
||||
jerry_value_t prevModule = jerry_object_get(global, moduleKey);
|
||||
jerry_value_t undef = jerry_undefined();
|
||||
jerry_object_set(global, moduleKey, undef);
|
||||
jerry_value_free(undef);
|
||||
|
||||
jerry_value_t result = 0;
|
||||
errorret_t err = scriptManagerExecFile(buffer, &result);
|
||||
if(result != 0) jerry_value_free(result);
|
||||
|
||||
// Capture whatever the module assigned to 'module', then restore the
|
||||
// caller's value so nested includes don't clobber each other.
|
||||
jerry_value_t moduleVal = jerry_object_get(global, moduleKey);
|
||||
jerry_object_set(global, moduleKey, prevModule);
|
||||
jerry_value_free(prevModule);
|
||||
jerry_value_free(moduleKey);
|
||||
jerry_value_free(global);
|
||||
|
||||
jerry_value_t moduleVal = 0;
|
||||
errorret_t err = scriptInclude(filename, &moduleVal);
|
||||
if(err.code != ERROR_OK) {
|
||||
jerry_value_free(moduleVal);
|
||||
errorCatch(errorPrint(err));
|
||||
return moduleBaseThrow("Failed to include script file");
|
||||
}
|
||||
|
||||
@@ -77,6 +77,40 @@ errorret_t scriptManagerExecFile(
|
||||
return assetScriptLoad(fname, resultOut);
|
||||
}
|
||||
|
||||
errorret_t scriptInclude(const char_t *filename, jerry_value_t *out) {
|
||||
assertNotNull(filename, "Filename cannot be NULL");
|
||||
|
||||
jerry_value_t global = jerry_current_realm();
|
||||
jerry_value_t moduleKey = jerry_string_sz("module");
|
||||
|
||||
jerry_value_t prevModule = jerry_object_get(global, moduleKey);
|
||||
jerry_value_t undef = jerry_undefined();
|
||||
jerry_object_set(global, moduleKey, undef);
|
||||
jerry_value_free(undef);
|
||||
|
||||
jerry_value_t execResult = 0;
|
||||
errorret_t err = scriptManagerExecFile(filename, &execResult);
|
||||
if(execResult != 0) jerry_value_free(execResult);
|
||||
|
||||
jerry_value_t moduleVal = jerry_object_get(global, moduleKey);
|
||||
jerry_object_set(global, moduleKey, prevModule);
|
||||
jerry_value_free(prevModule);
|
||||
jerry_value_free(moduleKey);
|
||||
jerry_value_free(global);
|
||||
|
||||
if(err.code != ERROR_OK) {
|
||||
jerry_value_free(moduleVal);
|
||||
return err;
|
||||
}
|
||||
|
||||
if(out != NULL) {
|
||||
*out = moduleVal;
|
||||
} else {
|
||||
jerry_value_free(moduleVal);
|
||||
}
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t scriptManagerDispose(void) {
|
||||
jerry_cleanup();
|
||||
errorOk();
|
||||
|
||||
@@ -56,6 +56,18 @@ errorret_t scriptManagerExecFile(
|
||||
jerry_value_t *result
|
||||
);
|
||||
|
||||
/**
|
||||
* Execute a JS file using the module-export pattern and return the exported
|
||||
* value. The script is expected to assign its public API to the global
|
||||
* `module` variable. The caller owns the returned jerry_value_t and must
|
||||
* call jerry_value_free() on it when done.
|
||||
*
|
||||
* @param filename Path to the .js asset file.
|
||||
* @param out Receives the value assigned to `module` by the script.
|
||||
* @return The error return value.
|
||||
*/
|
||||
errorret_t scriptInclude(const char_t *filename, jerry_value_t *out);
|
||||
|
||||
/**
|
||||
* Dispose of the script manager.
|
||||
*
|
||||
|
||||
@@ -78,7 +78,9 @@ void scriptProtoDefineProp(
|
||||
}
|
||||
|
||||
jerry_value_t key = jerry_string_sz(name);
|
||||
jerry_value_t result = jerry_object_define_own_prop(proto->prototype, key, &desc);
|
||||
jerry_value_t result = jerry_object_define_own_prop(
|
||||
proto->prototype, key, &desc
|
||||
);
|
||||
jerry_value_free(result);
|
||||
jerry_value_free(key);
|
||||
jerry_value_free(desc.getter);
|
||||
@@ -111,7 +113,9 @@ void scriptProtoDefineStaticProp(
|
||||
assertStrLenMin(name, 1, "Property name must not be empty");
|
||||
assertNotNull(getter, "Getter must not be null");
|
||||
|
||||
jerry_value_t target = proto->constructor ? proto->constructor : proto->prototype;
|
||||
jerry_value_t target = (
|
||||
proto->constructor ? proto->constructor : proto->prototype
|
||||
);
|
||||
|
||||
jerry_property_descriptor_t desc;
|
||||
memoryZero(&desc, sizeof(desc));
|
||||
@@ -145,7 +149,9 @@ void scriptProtoDefineStaticFunc(
|
||||
assertStrLenMin(name, 1, "Method name must not be empty");
|
||||
assertNotNull(fn, "Function handler must not be null");
|
||||
|
||||
jerry_value_t target = proto->constructor ? proto->constructor : proto->prototype;
|
||||
jerry_value_t target = (
|
||||
proto->constructor ? proto->constructor : proto->prototype
|
||||
);
|
||||
jerry_value_t key = jerry_string_sz(name);
|
||||
jerry_value_t func = jerry_function_external(fn);
|
||||
jerry_object_set(target, key, func);
|
||||
|
||||
@@ -8,4 +8,5 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
ui.c
|
||||
uifps.c
|
||||
uielement.c
|
||||
)
|
||||
+19
-6
@@ -10,13 +10,20 @@
|
||||
#include "assert/assert.h"
|
||||
#include "display/spritebatch/spritebatch.h"
|
||||
#include "display/screen/screen.h"
|
||||
#include "ui/uifps.h"
|
||||
#include "console/console.h"
|
||||
#include "ui/uielement.h"
|
||||
#include "log/log.h"
|
||||
|
||||
ui_t UI;
|
||||
|
||||
errorret_t uiInit(void) {
|
||||
memoryZero(&UI, sizeof(ui_t));
|
||||
|
||||
uielement_t *element = &UI_ELEMENTS[0];
|
||||
while(element->type != UI_ELEMENT_TYPE_NULL) {
|
||||
errorChain(uiElementInit(element));
|
||||
element++;
|
||||
}
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
@@ -24,10 +31,16 @@ void uiUpdate(void) {
|
||||
}
|
||||
|
||||
errorret_t uiRender(void) {
|
||||
errorChain(uiFPSDraw());
|
||||
errorChain(spriteBatchFlush());
|
||||
errorChain(consoleDraw());
|
||||
errorChain(spriteBatchFlush());
|
||||
const uielement_t *element = &UI_ELEMENTS[0];
|
||||
while(element->type != UI_ELEMENT_TYPE_NULL) {
|
||||
errorChain(uiElementDraw(element));
|
||||
|
||||
if(SPRITEBATCH.spriteCount > 0) {
|
||||
logDebug("Finished UI element but unflushed sprites remain.\n");
|
||||
}
|
||||
|
||||
element++;
|
||||
}
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "uielement.h"
|
||||
#include "assert/assert.h"
|
||||
#include "script/scriptmanager.h"
|
||||
#include "console/console.h"
|
||||
#include "ui/uifps.h"
|
||||
|
||||
uielement_t UI_ELEMENTS[] = {
|
||||
{ .type = UI_ELEMENT_TYPE_NATIVE, .native = { .draw = consoleDraw } },
|
||||
{ .type = UI_ELEMENT_TYPE_NATIVE, .native = { .draw = uiFPSDraw } },
|
||||
{ .type = UI_ELEMENT_TYPE_SCRIPT, .script = { .script = "ui/test.js" } },
|
||||
|
||||
{ .type = UI_ELEMENT_TYPE_NULL },
|
||||
};
|
||||
|
||||
errorret_t uiElementInit(uielement_t *element) {
|
||||
assertNotNull(element, "element must not be NULL");
|
||||
|
||||
if(element->type == UI_ELEMENT_TYPE_SCRIPT) {
|
||||
errorChain(scriptInclude(element->script.script, &element->script.module));
|
||||
}
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t uiElementDraw(const uielement_t *element) {
|
||||
switch(element->type) {
|
||||
case UI_ELEMENT_TYPE_NATIVE:
|
||||
errorChain(element->native.draw());
|
||||
break;
|
||||
|
||||
case UI_ELEMENT_TYPE_SCRIPT: {
|
||||
jerry_value_t renderKey = jerry_string_sz("render");
|
||||
jerry_value_t renderFn = jerry_object_get(
|
||||
element->script.module, renderKey
|
||||
);
|
||||
jerry_value_free(renderKey);
|
||||
|
||||
if(!jerry_value_is_function(renderFn)) {
|
||||
jerry_value_free(renderFn);
|
||||
errorThrow("UI script module has no render function");
|
||||
}
|
||||
|
||||
jerry_value_t ret = jerry_call(renderFn, element->script.module, NULL, 0);
|
||||
jerry_value_free(renderFn);
|
||||
|
||||
if(jerry_value_is_exception(ret)) {
|
||||
jerry_value_t errVal = jerry_exception_value(ret, false);
|
||||
jerry_value_t errStr = jerry_value_to_string(errVal);
|
||||
char_t buf[256];
|
||||
jerry_size_t len = jerry_string_to_buffer(
|
||||
errStr, JERRY_ENCODING_UTF8, (jerry_char_t *)buf, sizeof(buf) - 1
|
||||
);
|
||||
buf[len] = '\0';
|
||||
jerry_value_free(errStr);
|
||||
jerry_value_free(errVal);
|
||||
jerry_value_free(ret);
|
||||
errorThrow("UI script render error: %s", buf);
|
||||
}
|
||||
|
||||
jerry_value_free(ret);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
assertUnreachable("Invalid UI element type");
|
||||
}
|
||||
|
||||
errorOk();
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
|
||||
typedef enum {
|
||||
UI_ELEMENT_TYPE_NULL,
|
||||
UI_ELEMENT_TYPE_NATIVE,
|
||||
UI_ELEMENT_TYPE_SCRIPT,
|
||||
UI_ELEMENT_TYPE_COUNT
|
||||
} uielementtype_t;
|
||||
|
||||
typedef struct {
|
||||
uielementtype_t type;
|
||||
|
||||
union {
|
||||
struct {
|
||||
errorret_t (*draw)();
|
||||
} native;
|
||||
|
||||
struct {
|
||||
const char_t *script;
|
||||
jerry_value_t module;
|
||||
} script;
|
||||
};
|
||||
} uielement_t;
|
||||
|
||||
extern uielement_t UI_ELEMENTS[];
|
||||
|
||||
/**
|
||||
* Initializes a UI element.
|
||||
*/
|
||||
errorret_t uiElementInit(uielement_t *element);
|
||||
|
||||
/**
|
||||
* Draws a UI element.
|
||||
*
|
||||
* @param element The element to render.
|
||||
* @return Any error that occurs.
|
||||
*/
|
||||
errorret_t uiElementDraw(const uielement_t *element);
|
||||
+2
-2
@@ -53,6 +53,6 @@ errorret_t uiFPSDraw() {
|
||||
fpsText, textColor,
|
||||
&FONT_TILESET_DEFAULT, &FONT_TEXTURE_DEFAULT
|
||||
));
|
||||
|
||||
errorOk();
|
||||
|
||||
return spriteBatchFlush();
|
||||
}
|
||||
@@ -163,7 +163,12 @@ bool_t stringToI16(const char_t *str, int16_t *out) {
|
||||
char_t *endptr;
|
||||
errno = 0;
|
||||
long int result = strtol(str, &endptr, 10);
|
||||
if(errno != 0 || *endptr != '\0' || result < INT16_MIN || result > INT16_MAX) {
|
||||
if(
|
||||
errno != 0 ||
|
||||
*endptr != '\0' ||
|
||||
result < INT16_MIN ||
|
||||
result > INT16_MAX
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
*out = (int16_t)result;
|
||||
|
||||
@@ -146,7 +146,12 @@ errorret_t shaderSetTextureDolphin(
|
||||
GX_TEXMAP0,
|
||||
GX_COLOR0A0
|
||||
);
|
||||
GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
|
||||
GX_SetBlendMode(
|
||||
GX_BM_BLEND,
|
||||
GX_BL_SRCALPHA,
|
||||
GX_BL_INVSRCALPHA,
|
||||
GX_LO_CLEAR
|
||||
);
|
||||
GX_SetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0);
|
||||
break;
|
||||
|
||||
@@ -226,7 +231,9 @@ errorret_t shaderUpdateMVPDolphin() {
|
||||
|
||||
// Set Model/View Matrix
|
||||
if(mvDirt) {
|
||||
glm_mat4_mul(SHADER_BOUND->view, SHADER_BOUND->model, SHADER_BOUND->modelView);
|
||||
glm_mat4_mul(
|
||||
SHADER_BOUND->view, SHADER_BOUND->model, SHADER_BOUND->modelView
|
||||
);
|
||||
shaderMat4ToMtx(SHADER_BOUND->modelView, SHADER_BOUND->dolphinModelView);
|
||||
GX_LoadPosMtxImm(SHADER_BOUND->dolphinModelView, GX_PNMTX0);
|
||||
}
|
||||
|
||||
@@ -107,9 +107,9 @@ void frameBufferGLClear(const uint8_t flags, const color_t color) {
|
||||
assertTrue(width > 0 && height > 0, "W/H must be greater than 0");
|
||||
|
||||
memoryZero(fb, sizeof(framebuffer_t));
|
||||
textureInit(&fb->texture, width, height, TEXTURE_FORMAT_RGBA,(texturedata_t){
|
||||
.rgbaColors = NULL
|
||||
});
|
||||
textureInit(&fb->texture, width, height, TEXTURE_FORMAT_RGBA,
|
||||
(texturedata_t){ .rgbaColors = NULL }
|
||||
);
|
||||
errorChain(errorGLCheck());
|
||||
|
||||
glGenFramebuffersEXT(1, &fb->id);
|
||||
|
||||
@@ -61,7 +61,7 @@ errorret_t assetInitLinux(void) {
|
||||
// Ensure combined length does not exceed ASSET_FILE_PATH_MAX
|
||||
size_t syslen = strlen(ASSET.platform.systemPath);
|
||||
size_t slashlen = 1; // for '/'
|
||||
size_t max_temp = ASSET_FILE_PATH_MAX - syslen - slashlen - 1; // -1 for null terminator
|
||||
size_t max_temp = ASSET_FILE_PATH_MAX - syslen - slashlen - 1;
|
||||
if(strlen(temp) > max_temp) {
|
||||
temp[max_temp] = '\0';
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ errorret_t networkLinuxInit();
|
||||
errorret_t networkLinuxUpdate();
|
||||
|
||||
/**
|
||||
* Returns true — Linux uses the OS network stack which is always available.
|
||||
* Returns true, Linux uses the OS network stack which is always available.
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
|
||||
@@ -73,7 +73,9 @@ errorret_t assetInitPBP(const char_t *pbpPath) {
|
||||
errorThrow("Failed to seek to PSAR offset in PBP file: %s", pbpPath);
|
||||
}
|
||||
|
||||
zip_uint64_t zipPsarOffset = (zip_uint64_t)ASSET.platform.pbpHeader.psarOffset;
|
||||
zip_uint64_t zipPsarOffset = (zip_uint64_t)(
|
||||
ASSET.platform.pbpHeader.psarOffset
|
||||
);
|
||||
zip_int64_t zipPsarSize = (zip_int64_t)(
|
||||
pbpSize - ASSET.platform.pbpHeader.psarOffset
|
||||
);
|
||||
|
||||
@@ -116,7 +116,9 @@ errorret_t networkPSPUpdate() {
|
||||
break;
|
||||
|
||||
default:
|
||||
errorThrow("Unknown PSP Netconf dialog status: %d", sceUtilityNetconfGetStatus());
|
||||
errorThrow(
|
||||
"Unknown PSP Netconf dialog status: %d", sceUtilityNetconfGetStatus()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ void networkPSPRequestConnection(
|
||||
);
|
||||
|
||||
/**
|
||||
* Requests the PSP to disconnect from the network (Shows the Wi-Fi disconnecting).
|
||||
* Requests the PSP to disconnect from the network.
|
||||
*
|
||||
* @param onComplete Callback when disconnection is complete.
|
||||
* @param user User data to pass to the callback.
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(module)
|
||||
@@ -1,8 +0,0 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Subdirectories
|
||||
add_subdirectory(item)
|
||||
add_subdirectory(story)
|
||||
@@ -1,5 +0,0 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
@@ -1,200 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "script/module/modulebase.h"
|
||||
#include "item/inventory.h"
|
||||
#include "item/backpack.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
JS_FUNC(moduleInventoryItemExists) {
|
||||
if(!jerry_value_is_object(args_p[0])) {
|
||||
return JS_THROW("inventoryItemExists: Expected inventory pointer as first argument");
|
||||
}
|
||||
|
||||
if(!jerry_value_is_number(args_p[1])) {
|
||||
return JS_THROW("inventoryItemExists: Expected item ID as second argument");
|
||||
}
|
||||
|
||||
inventory_t *inventory = (inventory_t *)jsUnwrapPointer(args_p[0]);
|
||||
itemid_t item = (itemid_t)jerry_value_as_number(args_p[1]);
|
||||
|
||||
assertNotNull(inventory, "Inventory pointer cannot be NULL.");
|
||||
|
||||
if(item == ITEM_ID_NULL) {
|
||||
return JS_THROW("inventoryItemExists: Item ID cannot be ITEM_ID_NULL");
|
||||
}
|
||||
|
||||
bool_t hasItem = inventoryItemExists(inventory, item);
|
||||
return jerry_boolean(hasItem);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleInventorySet) {
|
||||
if(!jerry_value_is_object(args_p[0])) {
|
||||
return JS_THROW("inventorySet: Expected inventory pointer as first argument");
|
||||
}
|
||||
|
||||
if(!jerry_value_is_number(args_p[1])) {
|
||||
return JS_THROW("inventorySet: Expected item ID as second argument");
|
||||
}
|
||||
|
||||
if(!jerry_value_is_number(args_p[2])) {
|
||||
return JS_THROW("inventorySet: Expected quantity as third argument");
|
||||
}
|
||||
|
||||
inventory_t *inventory = (inventory_t *)jsUnwrapPointer(args_p[0]);
|
||||
itemid_t item = (itemid_t)jerry_value_as_number(args_p[1]);
|
||||
uint8_t quantity = (uint8_t)jerry_value_as_number(args_p[2]);
|
||||
|
||||
assertNotNull(inventory, "Inventory pointer cannot be NULL.");
|
||||
inventorySet(inventory, item, quantity);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleInventoryAdd) {
|
||||
if(!jerry_value_is_object(args_p[0])) {
|
||||
return JS_THROW("inventoryAdd: Expected inventory pointer as first argument");
|
||||
}
|
||||
|
||||
if(!jerry_value_is_number(args_p[1])) {
|
||||
return JS_THROW("inventoryAdd: Expected item ID as second argument");
|
||||
}
|
||||
|
||||
if(!jerry_value_is_number(args_p[2])) {
|
||||
return JS_THROW("inventoryAdd: Expected quantity as third argument");
|
||||
}
|
||||
|
||||
inventory_t *inventory = (inventory_t *)jsUnwrapPointer(args_p[0]);
|
||||
itemid_t item = (itemid_t)jerry_value_as_number(args_p[1]);
|
||||
uint8_t quantity = (uint8_t)jerry_value_as_number(args_p[2]);
|
||||
|
||||
assertNotNull(inventory, "Inventory pointer cannot be NULL.");
|
||||
inventoryAdd(inventory, item, quantity);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleInventoryRemove) {
|
||||
if(!jerry_value_is_object(args_p[0])) {
|
||||
return JS_THROW("inventoryRemove: Expected inventory pointer as first argument");
|
||||
}
|
||||
|
||||
if(!jerry_value_is_number(args_p[1])) {
|
||||
return JS_THROW("inventoryRemove: Expected item ID as second argument");
|
||||
}
|
||||
|
||||
inventory_t *inventory = (inventory_t *)jsUnwrapPointer(args_p[0]);
|
||||
itemid_t item = (itemid_t)jerry_value_as_number(args_p[1]);
|
||||
assertNotNull(inventory, "Inventory pointer cannot be NULL.");
|
||||
|
||||
if(args_count >= 3) {
|
||||
if(!jerry_value_is_number(args_p[2])) {
|
||||
return JS_THROW("inventoryRemove: Expected quantity as third argument");
|
||||
}
|
||||
uint8_t amount = (uint8_t)jerry_value_as_number(args_p[2]);
|
||||
uint8_t currentQuantity = inventoryGetCount(inventory, item);
|
||||
if(amount >= currentQuantity) {
|
||||
inventoryRemove(inventory, item);
|
||||
return jerry_undefined();
|
||||
}
|
||||
inventorySet(inventory, item, currentQuantity - amount);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
inventoryRemove(inventory, item);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleInventoryGetCount) {
|
||||
if(!jerry_value_is_object(args_p[0])) {
|
||||
return JS_THROW("inventoryGetCount: Expected inventory pointer as first argument");
|
||||
}
|
||||
|
||||
if(!jerry_value_is_number(args_p[1])) {
|
||||
return JS_THROW("inventoryGetCount: Expected item ID as second argument");
|
||||
}
|
||||
|
||||
inventory_t *inventory = (inventory_t *)jsUnwrapPointer(args_p[0]);
|
||||
itemid_t item = (itemid_t)jerry_value_as_number(args_p[1]);
|
||||
|
||||
assertNotNull(inventory, "Inventory pointer cannot be NULL.");
|
||||
|
||||
uint8_t count = inventoryGetCount(inventory, item);
|
||||
return jerry_number(count);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleInventoryIsFull) {
|
||||
if(!jerry_value_is_object(args_p[0])) {
|
||||
return JS_THROW("inventoryIsFull: Expected inventory pointer as first argument");
|
||||
}
|
||||
|
||||
inventory_t *inventory = (inventory_t *)jsUnwrapPointer(args_p[0]);
|
||||
|
||||
assertNotNull(inventory, "Inventory pointer cannot be NULL.");
|
||||
|
||||
bool_t isFull = inventoryIsFull(inventory);
|
||||
return jerry_boolean(isFull);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleInventoryItemFull) {
|
||||
if(!jerry_value_is_object(args_p[0])) {
|
||||
return JS_THROW("inventoryItemFull: Expected inventory pointer as first argument");
|
||||
}
|
||||
|
||||
if(!jerry_value_is_number(args_p[1])) {
|
||||
return JS_THROW("inventoryItemFull: Expected item ID as second argument");
|
||||
}
|
||||
|
||||
inventory_t *inventory = (inventory_t *)jsUnwrapPointer(args_p[0]);
|
||||
itemid_t item = (itemid_t)jerry_value_as_number(args_p[1]);
|
||||
|
||||
assertNotNull(inventory, "Inventory pointer cannot be NULL.");
|
||||
|
||||
bool_t isFull = inventoryItemFull(inventory, item);
|
||||
return jerry_boolean(isFull);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleInventorySort) {
|
||||
if(!jerry_value_is_object(args_p[0])) {
|
||||
return JS_THROW("inventorySort: Expected inventory pointer as first argument");
|
||||
}
|
||||
|
||||
if(!jerry_value_is_number(args_p[1])) {
|
||||
return JS_THROW("inventorySort: Expected sort type as second argument");
|
||||
}
|
||||
|
||||
bool_t reverse = false;
|
||||
if(args_count >= 3) {
|
||||
if(!jerry_value_is_boolean(args_p[2])) {
|
||||
return JS_THROW("inventorySort: Expected reverse flag as third argument");
|
||||
}
|
||||
reverse = (bool_t)jerry_value_is_true(args_p[2]);
|
||||
}
|
||||
|
||||
inventory_t *inventory = (inventory_t *)jsUnwrapPointer(args_p[0]);
|
||||
inventorysort_t sortBy = (inventorysort_t)jerry_value_as_number(args_p[1]);
|
||||
|
||||
assertNotNull(inventory, "Inventory pointer cannot be NULL.");
|
||||
inventorySort(inventory, sortBy, reverse);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
static void moduleItem(void) {
|
||||
moduleBaseEval(ITEM_SCRIPT);
|
||||
|
||||
jerry_value_t backpack = jsWrapPointer(&BACKPACK);
|
||||
jsSetValue("BACKPACK", backpack);
|
||||
jerry_value_free(backpack);
|
||||
|
||||
jsRegister("inventoryItemExists", moduleInventoryItemExists);
|
||||
jsRegister("inventoryAdd", moduleInventoryAdd);
|
||||
jsRegister("inventorySet", moduleInventorySet);
|
||||
jsRegister("inventoryRemove", moduleInventoryRemove);
|
||||
jsRegister("inventoryGetCount", moduleInventoryGetCount);
|
||||
jsRegister("inventoryIsFull", moduleInventoryIsFull);
|
||||
jsRegister("inventoryItemFull", moduleInventoryItemFull);
|
||||
jsRegister("inventorySort", moduleInventorySort);
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "script/module/modulebase.h"
|
||||
#include "assert/assert.h"
|
||||
#include "story/storyflag.h"
|
||||
|
||||
JS_FUNC(moduleStoryFlagGet) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
JS_REQUIRE_NUMBER(0);
|
||||
storyflag_t flag = (storyflag_t)jerry_value_as_number(args_p[0]);
|
||||
if(flag <= STORY_FLAG_NULL || flag >= STORY_FLAG_COUNT) {
|
||||
return JS_THROW("storyFlagGet: invalid flag ID");
|
||||
}
|
||||
return jerry_number((double)storyFlagGet(flag));
|
||||
}
|
||||
|
||||
JS_FUNC(moduleStoryFlagSet) {
|
||||
JS_REQUIRE_ARGS(2);
|
||||
JS_REQUIRE_NUMBER(0);
|
||||
JS_REQUIRE_NUMBER(1);
|
||||
storyflag_t flag = (storyflag_t)jerry_value_as_number(args_p[0]);
|
||||
if(flag <= STORY_FLAG_NULL || flag >= STORY_FLAG_COUNT) {
|
||||
return JS_THROW("storyFlagSet: invalid flag ID");
|
||||
}
|
||||
storyflagvalue_t value = (storyflagvalue_t)jerry_value_as_number(args_p[1]);
|
||||
storyFlagSet(flag, value);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleStoryFlagIncrement) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
JS_REQUIRE_NUMBER(0);
|
||||
storyflag_t flag = (storyflag_t)jerry_value_as_number(args_p[0]);
|
||||
if(flag <= STORY_FLAG_NULL || flag >= STORY_FLAG_COUNT) {
|
||||
return JS_THROW("storyFlagIncrement: invalid flag ID");
|
||||
}
|
||||
storyFlagSet(flag, storyFlagGet(flag) + 1);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleStoryFlagDecrement) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
JS_REQUIRE_NUMBER(0);
|
||||
storyflag_t flag = (storyflag_t)jerry_value_as_number(args_p[0]);
|
||||
if(flag <= STORY_FLAG_NULL || flag >= STORY_FLAG_COUNT) {
|
||||
return JS_THROW("storyFlagDecrement: invalid flag ID");
|
||||
}
|
||||
storyFlagSet(flag, storyFlagGet(flag) - 1);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
static void moduleStoryFlag(void) {
|
||||
jsRegister("storyFlagGet", moduleStoryFlagGet);
|
||||
jsRegister("storyFlagSet", moduleStoryFlagSet);
|
||||
jsRegister("storyFlagIncrement", moduleStoryFlagIncrement);
|
||||
jsRegister("storyFlagDecrement", moduleStoryFlagDecrement);
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "script/module/item/moduleitem.h"
|
||||
#include "script/module/story/modulestoryflag.h"
|
||||
|
||||
#define SCRIPT_GAME_INIT(L) \
|
||||
moduleItem(L); \
|
||||
moduleStoryFlag(L);
|
||||
@@ -23,9 +23,10 @@ errorret_t displaySDL2Init(void) {
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
|
||||
#ifdef DUSK_OPENGL_LEGACY
|
||||
// SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
|
||||
#else
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
SDL_GL_SetAttribute(
|
||||
SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE
|
||||
);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||
#endif
|
||||
|
||||
@@ -91,10 +91,10 @@
|
||||
<section class="panel-section" id="info-section" hidden>
|
||||
<div class="section-label">Info</div>
|
||||
<table class="info-table">
|
||||
<tr><td>File</td><td id="info-filename">—</td></tr>
|
||||
<tr><td>Input</td><td id="info-input-size">—</td></tr>
|
||||
<tr><td>Output</td><td id="info-output-size">—</td></tr>
|
||||
<tr><td>DTF</td><td id="info-dtf-size">—</td></tr>
|
||||
<tr><td>File</td><td id="info-filename">N/A</td></tr>
|
||||
<tr><td>Input</td><td id="info-input-size">N/A</td></tr>
|
||||
<tr><td>Output</td><td id="info-output-size">N/A</td></tr>
|
||||
<tr><td>DTF</td><td id="info-dtf-size">N/A</td></tr>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -85,10 +85,10 @@
|
||||
<section class="panel-section" id="info-section" hidden>
|
||||
<div class="section-label">Info</div>
|
||||
<table class="info-table">
|
||||
<tr><td>File</td><td id="info-filename">—</td></tr>
|
||||
<tr><td>Size</td><td id="info-size">—</td></tr>
|
||||
<tr><td>Format</td><td id="info-format">—</td></tr>
|
||||
<tr><td>DTF</td><td id="info-dtf-size">—</td></tr>
|
||||
<tr><td>File</td><td id="info-filename">N/A</td></tr>
|
||||
<tr><td>Size</td><td id="info-size">N/A</td></tr>
|
||||
<tr><td>Format</td><td id="info-format">N/A</td></tr>
|
||||
<tr><td>DTF</td><td id="info-dtf-size">N/A</td></tr>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user