| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- module scripts.lua.textures;
- import bindbc.lua;
- import raylib;
- import variables;
- import graphics.effects;
- import std.conv;
- import system.debugwriteln;
- import system.config;
- import std.string;
- import std.algorithm;
- import system.init;
- import graphics.playback;
- import std.file;
- import graphics.collision;
- import audio.sfx;
- import system.hpf;
- extern (C) nothrow int luaL_loadTexture(lua_State *L) {
- int textureIndex = cast(int)luaL_checkinteger(L, 1);
- char* textureFilename = cast(char*)luaL_checkstring(L, 2);
- if (textureIndex >= textures.length) {
- textures.length = textureIndex + 1;
- }
- if (textures.length < textures.length) {
- textures.length = textures.length;
- }
- if (textureIndex < textures.length && textures[textureIndex].id != 0) {
- UnloadTexture(textures[textureIndex]);
- }
- textures[textureIndex] = LoadTexture(textureFilename);
- return 0;
- }
- extern (C) nothrow int luaL_loadTextureFromHPF(lua_State *L) {
- try {
- int indexOfArchive = cast(int)luaL_checkinteger(L, 1);
- int textureIndexInArchive = cast(int)luaL_checkinteger(L, 2);
- int textureIndex = cast(int)luaL_checkinteger(L, 3);
- ubyte[] textureFile = loadFileFromHPF(archivesNames[indexOfArchive], parsedChunks[indexOfArchive], textureIndexInArchive);
- if (textureIndex >= textures.length) {
- textures.length = textureIndex + 1;
- }
- if (textures.length < textures.length) {
- textures.length = textures.length;
- }
- if (textureIndex < textures.length && textures[textureIndex].id != 0) {
- UnloadTexture(textures[textureIndex]);
- }
- Image textureImage = LoadImageFromMemory(
- ".png", cast(const(ubyte)*)textureFile, cast(int)textureFile.length
- );
- textures[textureIndex] = LoadTextureFromImage(textureImage);
- UnloadImage(textureImage);
- } catch (Exception e) {
- debugWriteln("exception in luaL_loadTextureFromHPF");
- }
- return 0;
- }
- extern (C) nothrow int luaL_unloadTexture(lua_State *L) {
- int textureIndex = cast(int)luaL_checkinteger(L, 1);
- UnloadTexture(textures[textureIndex]);
- return 0;
- }
- extern (C) nothrow int luaL_drawTexture(lua_State *L) {
- int textureIndex = cast(int)luaL_checkinteger(L, 1);
- int x = cast(int)luaL_checkinteger(L, 2);
- int y = cast(int)luaL_checkinteger(L, 3);
- float scale = luaL_checknumber(L, 4)*variables.scale;
- Color color = Colors.WHITE;
-
- if (lua_gettop(L) >= 5 && lua_istable(L, 5)) {
- lua_getfield(L, 5, "r");
- color.r = cast(ubyte)lua_tointeger(L, -1);
- lua_pop(L, 1);
-
- lua_getfield(L, 5, "g");
- color.g = cast(ubyte)lua_tointeger(L, -1);
- lua_pop(L, 1);
-
- lua_getfield(L, 5, "b");
- color.b = cast(ubyte)lua_tointeger(L, -1);
- lua_pop(L, 1);
-
- lua_getfield(L, 5, "a");
- color.a = cast(ubyte)lua_tointeger(L, -1);
- lua_pop(L, 1);
- }
-
- DrawTextureEx(textures[textureIndex], Vector2(x, y), 0.0f, scale, color);
- return 0;
- }
- extern (C) nothrow int luaL_getTextureWidth(lua_State *L) {
- int textureIndex = cast(int)luaL_checkinteger(L, 1);
- float scalel = textures[textureIndex].width*variables.scale;
- //debugWriteln(scalel);
- lua_pushnumber(L, scalel);
- return 1;
- }
- extern (C) nothrow int luaL_getTextureHeight(lua_State *L) {
- int textureIndex = cast(int)luaL_checkinteger(L, 1);
- float scalel = textures[textureIndex].height*variables.scale;
- //debugWriteln(scalel);
- lua_pushnumber(L, scalel);
- return 1;
- }
- extern (C) nothrow int luaL_drawTextureEx(lua_State *L) {
- int textureIndex = cast(int)luaL_checkinteger(L, 1);
- float x = luaL_checknumber(L, 2);
- float y = luaL_checknumber(L, 3);
- float rotation = luaL_optnumber(L, 4, 0);
- float scale = luaL_optnumber(L, 5, 1);
- Color color = Colors.WHITE;
- if (lua_istable(L, 6)) {
- lua_getfield(L, 6, "r");
- color.r = cast(ubyte)lua_tointeger(L, -1);
- lua_pop(L, 1);
-
- lua_getfield(L, 6, "g");
- color.g = cast(ubyte)lua_tointeger(L, -1);
- lua_pop(L, 1);
-
- lua_getfield(L, 6, "b");
- color.b = cast(ubyte)lua_tointeger(L, -1);
- lua_pop(L, 1);
-
- lua_getfield(L, 6, "a");
- color.a = cast(ubyte)lua_tointeger(L, -1);
- lua_pop(L, 1);
- }
- DrawTextureEx(textures[textureIndex], Vector2(x, y), rotation, scale*variables.scale, color);
-
- return 0;
- }
|