diff --git a/Airport.vcxproj b/Airport.vcxproj index 75be58d..0977a38 100644 --- a/Airport.vcxproj +++ b/Airport.vcxproj @@ -23,6 +23,7 @@ + diff --git a/Toy b/Toy index 9b673f2..e243ad9 160000 --- a/Toy +++ b/Toy @@ -1 +1 @@ -Subproject commit 9b673f23ad2e4a7a4c27db79a4bb49b2faf249f6 +Subproject commit e243ad949a822044a6d5710b7390e1a48b784dff diff --git a/assets/scripts/frames.toy b/assets/scripts/frames.toy new file mode 100644 index 0000000..e54519b --- /dev/null +++ b/assets/scripts/frames.toy @@ -0,0 +1,22 @@ +import node; + +fn onInit(node: opaque) { + node.loadTexture("sprites:/frametest.png"); + + //mapped to the given image + node.setNodeRect(0, 0, 32, 32); + node.setNodeFrames(3); +} + +var counter = 0; +fn onStep(node: opaque) { + counter++; + if (counter >= 60) { + counter = 0; + node.incrementCurrentNodeFrame(); + } +} + +fn onDraw(node: opaque) { + node.drawNode(0, 0); +} \ No newline at end of file diff --git a/assets/scripts/init.toy b/assets/scripts/init.toy index eddaf2c..73c724c 100644 --- a/assets/scripts/init.toy +++ b/assets/scripts/init.toy @@ -28,4 +28,4 @@ mapInputEventToKeyUp("character_right", "right"); //event, keysym initWindow("Airport Game", 1080, 720, false); //kick off the logic of the scene graph -loadRootNode("scripts:/scene.toy"); +loadRootNode("scripts:/frames.toy"); diff --git a/assets/scripts/tilemap/layer-background.toy b/assets/scripts/tilemap/layer-background.toy index 16c0d6e..9e8c904 100644 --- a/assets/scripts/tilemap/layer-background.toy +++ b/assets/scripts/tilemap/layer-background.toy @@ -60,7 +60,7 @@ fn drawLayer(node: opaque, camX, camY, camW, camH, depth) { //render each tile for (var j = lowerY; j <= upperY; j++) { for (var i = lowerX; i <= upperX; i++) { - node.getNodeChild(0).drawNode(round(camX_mod + i * tileWidth_mod), round(camY_mod + j * tileHeight_mod), tileWidth_mod, tileHeight_mod); + node.getChildNode(0).drawNode(round(camX_mod + i * tileWidth_mod), round(camY_mod + j * tileHeight_mod), tileWidth_mod, tileHeight_mod); } } } diff --git a/assets/scripts/tilemap/layer-walls.toy b/assets/scripts/tilemap/layer-walls.toy index 9262ac1..afef670 100644 --- a/assets/scripts/tilemap/layer-walls.toy +++ b/assets/scripts/tilemap/layer-walls.toy @@ -64,7 +64,7 @@ fn drawLayer(node: opaque, camX, camY, camW, camH, depth) { continue; } - node.getNodeChild(0).drawNode(round(camX_mod + i * tileWidth_mod), round(camY_mod + j * tileHeight_mod), tileWidth_mod, tileHeight_mod); + node.getChildNode(0).drawNode(round(camX_mod + i * tileWidth_mod), round(camY_mod + j * tileHeight_mod), tileWidth_mod, tileHeight_mod); } } } diff --git a/assets/scripts/tilemap/tilemap.toy b/assets/scripts/tilemap/tilemap.toy index 0c7876f..092ed67 100644 --- a/assets/scripts/tilemap/tilemap.toy +++ b/assets/scripts/tilemap/tilemap.toy @@ -2,6 +2,7 @@ import standard; import node; +//TODO: get child count var childCounter: int = 0; var levelXCount: int const = 4; @@ -49,7 +50,7 @@ fn onDraw(node: opaque) { //iterate over each layer, passing in the screen dimensions for (var c = 0; c < childCounter; c++) { - node.getNodeChild(c).callNodeFn("drawLayer", camX, camY, screenWidth, screenHeight, c * 2); + node.getChildNode(c).callNodeFn("drawLayer", camX, camY, screenWidth, screenHeight, c * 2); } } diff --git a/assets/sprites/frametest.png b/assets/sprites/frametest.png new file mode 100644 index 0000000..844f1c7 Binary files /dev/null and b/assets/sprites/frametest.png differ diff --git a/box/box_engine_node.c b/box/box_engine_node.c index e341aca..5a05f1b 100644 --- a/box/box_engine_node.c +++ b/box/box_engine_node.c @@ -13,6 +13,8 @@ void Box_initEngineNode(Box_EngineNode* node, Toy_Interpreter* interpreter, cons node->capacity = 0; node->count = 0; node->texture = NULL; + node->rect = ((SDL_Rect) { 0, 0, 0, 0 }); + node->frames = 0; Toy_initLiteralDictionary(node->functions); @@ -205,6 +207,7 @@ int Box_loadTextureEngineNode(Box_EngineNode* node, const char* fname) { SDL_QueryTexture(node->texture, NULL, NULL, &w, &h); SDL_Rect r = { 0, 0, w, h }; Box_setRectEngineNode(node, r); + Box_setFramesEngineNode(node, 1); //default return 0; } @@ -220,6 +223,36 @@ void Box_setRectEngineNode(Box_EngineNode* node, SDL_Rect rect) { node->rect = rect; } -void Box_drawEngineNode(Box_EngineNode* node, SDL_Rect dest) { - SDL_RenderCopy(engine.renderer, node->texture, &node->rect, &dest); +BOX_API SDL_Rect Box_getRectEngineNode(Box_EngineNode* node) { + return node->rect; +} + +BOX_API void Box_setFramesEngineNode(Box_EngineNode* node, int frames) { + node->frames = frames; + node->currentFrame = 0; //just in case +} + +BOX_API int Box_getFramesEngineNode(Box_EngineNode* node) { + return node->frames; +} + +BOX_API void Box_setCurrentFrameEngineNode(Box_EngineNode* node, int currentFrame) { + node->currentFrame = currentFrame; +} + +BOX_API int Box_getCurrentFrameEngineNode(Box_EngineNode* node) { + return node->currentFrame; +} + +BOX_API void Box_incrementCurrentFrame(Box_EngineNode* node) { + node->currentFrame++; + if (node->currentFrame >= node->frames) { + node->currentFrame = 0; + } +} + +void Box_drawEngineNode(Box_EngineNode* node, SDL_Rect dest) { + SDL_Rect src = node->rect; + src.x += src.w * node->currentFrame; //TODO: improve this + SDL_RenderCopy(engine.renderer, node->texture, &src, &dest); } diff --git a/box/box_engine_node.h b/box/box_engine_node.h index dabb6a9..b17f7a1 100644 --- a/box/box_engine_node.h +++ b/box/box_engine_node.h @@ -24,7 +24,6 @@ typedef struct Box_private_engineNode { //my opaque type tag int tag; - // int _unused0; //use Toy's memory model Box_EngineNode** children; @@ -34,16 +33,18 @@ typedef struct Box_private_engineNode { //rendering-specific features SDL_Texture* texture; SDL_Rect rect; - //TODO: depth -} Box_EngineNode; + int frames; + int currentFrame; +} Box_EngineNode; //TODO: rename this? BOX_API void Box_initEngineNode(Box_EngineNode* node, Toy_Interpreter* interpreter, const unsigned char* tb, size_t size); //run bytecode, then grab all top-level function literals BOX_API void Box_pushEngineNode(Box_EngineNode* node, Box_EngineNode* child); //push to the array (prune tombstones when expanding/copying) -BOX_API void Box_freeEngineNode(Box_EngineNode* node); //free and tombstone this node +BOX_API void Box_freeEngineNode(Box_EngineNode* node); //free this node and all children BOX_API Toy_Literal Box_callEngineNodeLiteral(Box_EngineNode* node, Toy_Interpreter* interpreter, Toy_Literal key, Toy_LiteralArray* args); BOX_API Toy_Literal Box_callEngineNode(Box_EngineNode* node, Toy_Interpreter* interpreter, const char* fnName, Toy_LiteralArray* args); //call "fnName" on this node, and only this node, if it exists +//for calling various lifecycle functions BOX_API void Box_callRecursiveEngineNodeLiteral(Box_EngineNode* node, Toy_Interpreter* interpreter, Toy_Literal key, Toy_LiteralArray* args); BOX_API void Box_callRecursiveEngineNode(Box_EngineNode* node, Toy_Interpreter* interpreter, const char* fnName, Toy_LiteralArray* args); //call "fnName" on this node, and all children, if it exists @@ -51,5 +52,12 @@ BOX_API int Box_loadTextureEngineNode(Box_EngineNode* node, const char* fname); BOX_API void Box_freeTextureEngineNode(Box_EngineNode* node); BOX_API void Box_setRectEngineNode(Box_EngineNode* node, SDL_Rect rect); -//TODO: getRect +BOX_API SDL_Rect Box_getRectEngineNode(Box_EngineNode* node); + +BOX_API void Box_setFramesEngineNode(Box_EngineNode* node, int frames); +BOX_API int Box_getFramesEngineNode(Box_EngineNode* node); +BOX_API void Box_setCurrentFrameEngineNode(Box_EngineNode* node, int currentFrame); +BOX_API int Box_getCurrentFrameEngineNode(Box_EngineNode* node); +BOX_API void Box_incrementCurrentFrame(Box_EngineNode* node); + BOX_API void Box_drawEngineNode(Box_EngineNode* node, SDL_Rect dest); diff --git a/box/lib_node.c b/box/lib_node.c index 1cb26f8..cf8eb12 100644 --- a/box/lib_node.c +++ b/box/lib_node.c @@ -113,6 +113,97 @@ static int nativeInitNode(Toy_Interpreter* interpreter, Toy_LiteralArray* argume return 0; } +static int nativePushNode(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { + //checks + if (arguments->count != 2) { + interpreter->errorOutput("Incorrect number of arguments passed to pushNode\n"); + return -1; + } + + Toy_Literal child = Toy_popLiteralArray(arguments); + Toy_Literal parent = Toy_popLiteralArray(arguments); + + Toy_Literal parentIdn = parent; + if (TOY_IS_IDENTIFIER(parent) && Toy_parseIdentifierToValue(interpreter, &parent)) { + Toy_freeLiteral(parentIdn); + } + + Toy_Literal childIdn = child; + if (TOY_IS_IDENTIFIER(child) && Toy_parseIdentifierToValue(interpreter, &child)) { + Toy_freeLiteral(childIdn); + } + + if (!TOY_IS_OPAQUE(parent) || !TOY_IS_OPAQUE(child)) { + interpreter->errorOutput("Incorrect argument type passed to pushNode\n"); + Toy_freeLiteral(parent); + Toy_freeLiteral(child); + return -1; + } + + //push the node + Box_EngineNode* parentNode = TOY_AS_OPAQUE(parent); + Box_EngineNode* childNode = TOY_AS_OPAQUE(child); + + Box_pushEngineNode(parentNode, childNode); + + //no return value + Toy_freeLiteral(parent); + Toy_freeLiteral(child); + + return 0; +} + +static int nativeGetChildNode(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { + //checks + if (arguments->count != 2) { + interpreter->errorOutput("Incorrect number of arguments passed to getChildNode\n"); + return -1; + } + + Toy_Literal index = Toy_popLiteralArray(arguments); + Toy_Literal parent = Toy_popLiteralArray(arguments); + + Toy_Literal parentIdn = parent; + if (TOY_IS_IDENTIFIER(parent) && Toy_parseIdentifierToValue(interpreter, &parent)) { + Toy_freeLiteral(parentIdn); + } + + Toy_Literal indexIdn = index; + if (TOY_IS_IDENTIFIER(index) && Toy_parseIdentifierToValue(interpreter, &index)) { + Toy_freeLiteral(indexIdn); + } + + if (!TOY_IS_OPAQUE(parent) || !TOY_IS_INTEGER(index)) { + interpreter->errorOutput("Incorrect argument type passed to getChildNode\n"); + Toy_freeLiteral(parent); + Toy_freeLiteral(index); + return -1; + } + + //push the node + Box_EngineNode* parentNode = TOY_AS_OPAQUE(parent); + int intIndex = TOY_AS_INTEGER(index); + + if (intIndex < 0 || intIndex >= parentNode->count) { + interpreter->errorOutput("index out of bounds in getChildNode\n"); + Toy_freeLiteral(parent); + Toy_freeLiteral(index); + return -1; + } + + Box_EngineNode* childNode = parentNode->children[intIndex]; + Toy_Literal child = TOY_TO_OPAQUE_LITERAL(childNode, childNode->tag); + + Toy_pushLiteralArray(&interpreter->stack, child); + + //no return value + Toy_freeLiteral(parent); + Toy_freeLiteral(child); + Toy_freeLiteral(index); + + return 1; +} + static int nativeFreeChildNode(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { if (arguments->count != 2) { interpreter->errorOutput("Incorrect number of arguments passed to freeChildNode\n"); @@ -162,101 +253,10 @@ static int nativeFreeChildNode(Toy_Interpreter* interpreter, Toy_LiteralArray* a return 0; } -static int nativePushNode(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { - //checks - if (arguments->count != 2) { - interpreter->errorOutput("Incorrect number of arguments passed to pushNode\n"); - return -1; - } - - Toy_Literal child = Toy_popLiteralArray(arguments); - Toy_Literal parent = Toy_popLiteralArray(arguments); - - Toy_Literal parentIdn = parent; - if (TOY_IS_IDENTIFIER(parent) && Toy_parseIdentifierToValue(interpreter, &parent)) { - Toy_freeLiteral(parentIdn); - } - - Toy_Literal childIdn = child; - if (TOY_IS_IDENTIFIER(child) && Toy_parseIdentifierToValue(interpreter, &child)) { - Toy_freeLiteral(childIdn); - } - - if (!TOY_IS_OPAQUE(parent) || !TOY_IS_OPAQUE(child)) { - interpreter->errorOutput("Incorrect argument type passed to pushNode\n"); - Toy_freeLiteral(parent); - Toy_freeLiteral(child); - return -1; - } - - //push the node - Box_EngineNode* parentNode = TOY_AS_OPAQUE(parent); - Box_EngineNode* childNode = TOY_AS_OPAQUE(child); - - Box_pushEngineNode(parentNode, childNode); - - //no return value - Toy_freeLiteral(parent); - Toy_freeLiteral(child); - - return 0; -} - -static int nativeGetNodeChild(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { - //checks - if (arguments->count != 2) { - interpreter->errorOutput("Incorrect number of arguments passed to getNodeChild\n"); - return -1; - } - - Toy_Literal index = Toy_popLiteralArray(arguments); - Toy_Literal parent = Toy_popLiteralArray(arguments); - - Toy_Literal parentIdn = parent; - if (TOY_IS_IDENTIFIER(parent) && Toy_parseIdentifierToValue(interpreter, &parent)) { - Toy_freeLiteral(parentIdn); - } - - Toy_Literal indexIdn = index; - if (TOY_IS_IDENTIFIER(index) && Toy_parseIdentifierToValue(interpreter, &index)) { - Toy_freeLiteral(indexIdn); - } - - if (!TOY_IS_OPAQUE(parent) || !TOY_IS_INTEGER(index)) { - interpreter->errorOutput("Incorrect argument type passed to getNodeChild\n"); - Toy_freeLiteral(parent); - Toy_freeLiteral(index); - return -1; - } - - //push the node - Box_EngineNode* parentNode = TOY_AS_OPAQUE(parent); - int intIndex = TOY_AS_INTEGER(index); - - if (intIndex < 0 || intIndex >= parentNode->count) { - interpreter->errorOutput("index out of bounds in getNodeChild\n"); - Toy_freeLiteral(parent); - Toy_freeLiteral(index); - return -1; - } - - Box_EngineNode* childNode = parentNode->children[intIndex]; - Toy_Literal child = TOY_TO_OPAQUE_LITERAL(childNode, childNode->tag); - - Toy_pushLiteralArray(&interpreter->stack, child); - - //no return value - Toy_freeLiteral(parent); - Toy_freeLiteral(child); - Toy_freeLiteral(index); - - return 1; -} - -static int nativeGetNodeParent(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { +static int nativeGetParentNode(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { //checks if (arguments->count != 1) { - interpreter->errorOutput("Incorrect number of arguments passed to getNodeParent\n"); + interpreter->errorOutput("Incorrect number of arguments passed to getParentNode\n"); return -1; } @@ -268,7 +268,7 @@ static int nativeGetNodeParent(Toy_Interpreter* interpreter, Toy_LiteralArray* a } if (!TOY_IS_OPAQUE(nodeLiteral)) { - interpreter->errorOutput("Incorrect argument type passed to getNodeParent\n"); + interpreter->errorOutput("Incorrect argument type passed to getParentNode\n"); Toy_freeLiteral(nodeLiteral); return -1; } @@ -384,9 +384,9 @@ static int nativeFreeTexture(Toy_Interpreter* interpreter, Toy_LiteralArray* arg return 0; } -static int nativeSetRect(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { +static int nativeSetNodeRect(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { if (arguments->count != 5) { - interpreter->errorOutput("Incorrect number of arguments passed to setRect\n"); + interpreter->errorOutput("Incorrect number of arguments passed to setNodeRect\n"); return -1; } @@ -424,7 +424,7 @@ static int nativeSetRect(Toy_Interpreter* interpreter, Toy_LiteralArray* argumen //check argument types if (!TOY_IS_OPAQUE(nodeLiteral) || !TOY_IS_INTEGER(x) || !TOY_IS_INTEGER(y) || !TOY_IS_INTEGER(w) || !TOY_IS_INTEGER(h)) { - interpreter->errorOutput("Incorrect argument type passed to setRect\n"); + interpreter->errorOutput("Incorrect argument type passed to setNodeRect\n"); Toy_freeLiteral(nodeLiteral); Toy_freeLiteral(x); Toy_freeLiteral(y); @@ -449,7 +449,187 @@ static int nativeSetRect(Toy_Interpreter* interpreter, Toy_LiteralArray* argumen return 0; } -//TODO: get x, y, w, h +static int nativeSetNodeFrames(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { + if (arguments->count != 2) { + interpreter->errorOutput("Incorrect number of arguments passed to setNodeFrames\n"); + return -1; + } + + //extract the arguments + Toy_Literal framesLiteral = Toy_popLiteralArray(arguments); + Toy_Literal nodeLiteral = Toy_popLiteralArray(arguments); + + Toy_Literal nodeIdn = nodeLiteral; + if (TOY_IS_IDENTIFIER(nodeLiteral) && Toy_parseIdentifierToValue(interpreter, &nodeLiteral)) { + Toy_freeLiteral(nodeIdn); + } + + Toy_Literal frameLiteralIdn = framesLiteral; + if (TOY_IS_IDENTIFIER(framesLiteral) && Toy_parseIdentifierToValue(interpreter, &framesLiteral)) { + Toy_freeLiteral(frameLiteralIdn); + } + + //check argument types + if (!TOY_IS_OPAQUE(nodeLiteral) || !TOY_IS_INTEGER(framesLiteral)) { + interpreter->errorOutput("Incorrect argument type passed to setNodeFrames\n"); + Toy_freeLiteral(nodeLiteral); + Toy_freeLiteral(framesLiteral); + return -1; + } + + //actually set + Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral); + + Box_setFramesEngineNode(node, TOY_AS_INTEGER(framesLiteral)); + + //cleanup + Toy_freeLiteral(nodeLiteral); + Toy_freeLiteral(framesLiteral); + + return 0; +} + +static int nativeGetNodeFrames(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { + if (arguments->count != 1) { + interpreter->errorOutput("Incorrect number of arguments passed to getNodeFrames\n"); + return -1; + } + + //extract the arguments + Toy_Literal nodeLiteral = Toy_popLiteralArray(arguments); + + Toy_Literal nodeIdn = nodeLiteral; + if (TOY_IS_IDENTIFIER(nodeLiteral) && Toy_parseIdentifierToValue(interpreter, &nodeLiteral)) { + Toy_freeLiteral(nodeIdn); + } + + //check argument types + if (!TOY_IS_OPAQUE(nodeLiteral)) { + interpreter->errorOutput("Incorrect argument type passed to getNodeFrames\n"); + Toy_freeLiteral(nodeLiteral); + return -1; + } + + //actually get + Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral); + Toy_Literal framesLiteral = TOY_TO_INTEGER_LITERAL(node->frames); + + Toy_pushLiteralArray(interpreter, framesLiteral); + + + //cleanup + Toy_freeLiteral(nodeLiteral); + Toy_freeLiteral(framesLiteral); + + return 1; +} + +static int nativeSetCurrentNodeFrame(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { + if (arguments->count != 2) { + interpreter->errorOutput("Incorrect number of arguments passed to setCurrentNodeFrame\n"); + return -1; + } + + //extract the arguments + Toy_Literal currentFrameLiteral = Toy_popLiteralArray(arguments); + Toy_Literal nodeLiteral = Toy_popLiteralArray(arguments); + + Toy_Literal nodeIdn = nodeLiteral; + if (TOY_IS_IDENTIFIER(nodeLiteral) && Toy_parseIdentifierToValue(interpreter, &nodeLiteral)) { + Toy_freeLiteral(nodeIdn); + } + + Toy_Literal currentFrameLiteralIdn = currentFrameLiteral; + if (TOY_IS_IDENTIFIER(currentFrameLiteral) && Toy_parseIdentifierToValue(interpreter, ¤tFrameLiteral)) { + Toy_freeLiteral(currentFrameLiteralIdn); + } + + //check argument types + if (!TOY_IS_OPAQUE(nodeLiteral) || !TOY_IS_INTEGER(currentFrameLiteral)) { + interpreter->errorOutput("Incorrect argument type passed to setCurrentNodeFrame\n"); + Toy_freeLiteral(nodeLiteral); + Toy_freeLiteral(currentFrameLiteral); + return -1; + } + + //actually set + Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral); + + Box_setFramesEngineNode(node, TOY_AS_INTEGER(currentFrameLiteral)); + + //cleanup + Toy_freeLiteral(nodeLiteral); + Toy_freeLiteral(currentFrameLiteral); + + return 0; +} + +static int nativeGetCurrentNodeFrame(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { + if (arguments->count != 1) { + interpreter->errorOutput("Incorrect number of arguments passed to getCurrentNodeFrame\n"); + return -1; + } + + //extract the arguments + Toy_Literal nodeLiteral = Toy_popLiteralArray(arguments); + + Toy_Literal nodeIdn = nodeLiteral; + if (TOY_IS_IDENTIFIER(nodeLiteral) && Toy_parseIdentifierToValue(interpreter, &nodeLiteral)) { + Toy_freeLiteral(nodeIdn); + } + + //check argument types + if (!TOY_IS_OPAQUE(nodeLiteral)) { + interpreter->errorOutput("Incorrect argument type passed to getCurrentNodeFrame\n"); + Toy_freeLiteral(nodeLiteral); + return -1; + } + + //actually get + Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral); + Toy_Literal currentFrameLiteral = TOY_TO_INTEGER_LITERAL(node->currentFrame); + + Toy_pushLiteralArray(interpreter, currentFrameLiteral); + + + //cleanup + Toy_freeLiteral(nodeLiteral); + Toy_freeLiteral(currentFrameLiteral); + + return 1; +} + +static int nativeIncrementCurrentNodeFrame(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { + if (arguments->count != 1) { + interpreter->errorOutput("Incorrect number of arguments passed to incrementCurrentNodeFrame\n"); + return -1; + } + + //extract the arguments + Toy_Literal nodeLiteral = Toy_popLiteralArray(arguments); + + Toy_Literal nodeIdn = nodeLiteral; + if (TOY_IS_IDENTIFIER(nodeLiteral) && Toy_parseIdentifierToValue(interpreter, &nodeLiteral)) { + Toy_freeLiteral(nodeIdn); + } + + //check argument types + if (!TOY_IS_OPAQUE(nodeLiteral)) { + interpreter->errorOutput("Incorrect argument type passed to incrementCurrentNodeFrame\n"); + Toy_freeLiteral(nodeLiteral); + return -1; + } + + //actually get + Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral); + + Box_incrementCurrentFrame(node); + + //cleanup + Toy_freeLiteral(nodeLiteral); + + return 0; +} static int nativeDrawNode(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) { if (arguments->count != 3 && arguments->count != 5) { @@ -614,17 +794,23 @@ int Box_hookNode(Toy_Interpreter* interpreter, Toy_Literal identifier, Toy_Liter Natives natives[] = { {"loadNode", nativeLoadNode}, {"initNode", nativeInitNode}, - {"freeChildNode", nativeFreeChildNode}, {"pushNode", nativePushNode}, - {"getNodeChild", nativeGetNodeChild}, - {"getNodeParent", nativeGetNodeParent}, + {"getChildNode", nativeGetChildNode}, + {"freeChildNode", nativeFreeChildNode}, + {"getParentNode", nativeGetParentNode}, {"loadTexture", nativeLoadTexture}, {"freeTexture", nativeFreeTexture}, - {"setRect", nativeSetRect}, + {"setNodeRect", nativeSetNodeRect}, + //get rect + {"setNodeFrames", nativeSetNodeFrames}, + {"getNodeFrames", nativeGetNodeFrames}, + {"setCurrentNodeFrame", nativeSetCurrentNodeFrame}, + {"getCurrentNodeFrame", nativeGetCurrentNodeFrame}, + {"incrementCurrentNodeFrame", nativeIncrementCurrentNodeFrame}, {"drawNode", nativeDrawNode}, {"callNodeFn", nativeCallNodeFn}, - //get rect, get node var, create empty node, get child count, get root node + //TODO: get rect, get node var, create empty node, get child count, get root node {NULL, NULL}, };