diff --git a/config.lua b/config.lua index a158699..98e1b2d 100644 --- a/config.lua +++ b/config.lua @@ -19,15 +19,7 @@ -- -local MOUSE_BUTTON_LEFT = 0 -local KEY_SPACE = 32 -local KEY_A = 65 -local KEY_D = 68 -local KEY_E = 69 -local KEY_Q = 81 -local KEY_R = 82 -local KEY_S = 83 -local KEY_W = 87 +require("include/raylib") Crosshair = { radius = 2.5 diff --git a/include/raylib.lua b/include/raylib.lua new file mode 100644 index 0000000..6f51228 --- /dev/null +++ b/include/raylib.lua @@ -0,0 +1,30 @@ +-- +-- GNU Sparky --- A 5v5 character-based libre tactical shooter +-- Copyright (C) 2024 Wasym A. Alonso +-- +-- This file is part of Sparky. +-- +-- Sparky is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- Sparky is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Sparky. If not, see . +-- + + +MOUSE_BUTTON_LEFT = 0 +KEY_SPACE = 32 +KEY_A = 65 +KEY_D = 68 +KEY_E = 69 +KEY_Q = 81 +KEY_R = 82 +KEY_S = 83 +KEY_W = 87 diff --git a/src/sk_config.c b/src/sk_config.c index 5c45eca..2fb0b08 100644 --- a/src/sk_config.c +++ b/src/sk_config.c @@ -69,55 +69,70 @@ void sk_config_load(const char *filepath, sk_config *c) { } lua_getglobal(L, "Crosshair"); lua_getfield(L, -1, "radius"); - c->crosshair.radius = (f32) lua_tonumber(L, -1); + if ((f32) lua_tonumber(L, -1) > 0) c->crosshair.radius = (f32) lua_tonumber(L, -1); + else SK_LOG_WARN("sk_config_load :: `Crosshair.radius` needs to be > 0. Using default instead"); lua_pop(L, 1); lua_pop(L, 1); lua_getglobal(L, "Video"); lua_getfield(L, -1, "win_width"); - c->video.win_width = (u16) lua_tonumber(L, -1); + if ((i16) lua_tonumber(L, -1) > 0) c->video.win_width = (u16) lua_tonumber(L, -1); + else SK_LOG_WARN("sk_config_load :: `Video.win_width` needs to be > 0. Using default instead"); lua_pop(L, 1); lua_getfield(L, -1, "win_height"); - c->video.win_height = (u16) lua_tonumber(L, -1); + if ((i16) lua_tonumber(L, -1) > 0) c->video.win_height = (u16) lua_tonumber(L, -1); + else SK_LOG_WARN("sk_config_load :: `Video.win_height` needs to be > 0. Using default instead"); lua_pop(L, 1); lua_getfield(L, -1, "fps_limit"); - c->video.fps_limit = (u16) lua_tonumber(L, -1); + if ((i16) lua_tonumber(L, -1) > 0) c->video.fps_limit = (u16) lua_tonumber(L, -1); + else SK_LOG_WARN("sk_config_load :: `Video.fps_limit` needs to be > 0. Using default instead"); lua_pop(L, 1); lua_pop(L, 1); lua_getglobal(L, "General"); lua_getfield(L, -1, "fov"); - c->general.fov = (u8) lua_tonumber(L, -1); + if ((i8) lua_tonumber(L, -1) > 0) c->general.fov = (u8) lua_tonumber(L, -1); + else SK_LOG_WARN("sk_config_load :: `General.fov` needs to be > 0. Using default instead"); lua_pop(L, 1); lua_getfield(L, -1, "mouse_sensitivity"); - c->general.mouse_sensitivity = (f32) lua_tonumber(L, -1); + if ((f32) lua_tonumber(L, -1) > 0) c->general.mouse_sensitivity = (f32) lua_tonumber(L, -1); + else SK_LOG_WARN("sk_config_load :: `General.mouse_sensitivity` needs to be > 0. Using default instead"); lua_pop(L, 1); lua_pop(L, 1); lua_getglobal(L, "Controls"); lua_getfield(L, -1, "move_forward"); - c->controls.move_forward = (u16) lua_tonumber(L, -1); + if ((i16) lua_tonumber(L, -1) > 0) c->controls.move_forward = (u16) lua_tonumber(L, -1); + else SK_LOG_WARN("sk_config_load :: `Controls.move_forward` needs to be > 0. Using default instead"); lua_pop(L, 1); lua_getfield(L, -1, "move_backwards"); - c->controls.move_backwards = (u16) lua_tonumber(L, -1); + if ((i16) lua_tonumber(L, -1) > 0) c->controls.move_backwards = (u16) lua_tonumber(L, -1); + else SK_LOG_WARN("sk_config_load :: `Controls.move_backwards` needs to be > 0. Using default instead"); lua_pop(L, 1); lua_getfield(L, -1, "move_left"); - c->controls.move_left = (u16) lua_tonumber(L, -1); + if ((i16) lua_tonumber(L, -1) > 0) c->controls.move_left = (u16) lua_tonumber(L, -1); + else SK_LOG_WARN("sk_config_load :: `Controls.move_left` needs to be > 0. Using default instead"); lua_pop(L, 1); lua_getfield(L, -1, "move_right"); - c->controls.move_right = (u16) lua_tonumber(L, -1); + if ((i16) lua_tonumber(L, -1) > 0) c->controls.move_right = (u16) lua_tonumber(L, -1); + else SK_LOG_WARN("sk_config_load :: `Controls.move_right` needs to be > 0. Using default instead"); lua_pop(L, 1); lua_getfield(L, -1, "peek_left"); - c->controls.peek_left = (u16) lua_tonumber(L, -1); + if ((i16) lua_tonumber(L, -1) > 0) c->controls.peek_left = (u16) lua_tonumber(L, -1); + else SK_LOG_WARN("sk_config_load :: `Controls.peek_left` needs to be > 0. Using default instead"); lua_pop(L, 1); lua_getfield(L, -1, "peek_right"); - c->controls.peek_right = (u16) lua_tonumber(L, -1); + if ((i16) lua_tonumber(L, -1) > 0) c->controls.peek_right = (u16) lua_tonumber(L, -1); + else SK_LOG_WARN("sk_config_load :: `Controls.peek_right` needs to be > 0. Using default instead"); lua_pop(L, 1); lua_getfield(L, -1, "jump"); - c->controls.jump = (u16) lua_tonumber(L, -1); + if ((i16) lua_tonumber(L, -1) > 0) c->controls.jump = (u16) lua_tonumber(L, -1); + else SK_LOG_WARN("sk_config_load :: `Controls.jump` needs to be > 0. Using default instead"); lua_pop(L, 1); lua_getfield(L, -1, "shoot"); - c->controls.shoot = (u16) lua_tonumber(L, -1); + if ((i16) lua_tonumber(L, -1) >= 0) c->controls.shoot = (u16) lua_tonumber(L, -1); + else SK_LOG_WARN("sk_config_load :: `Controls.jump` needs to be >= 0. Using default instead"); lua_pop(L, 1); lua_getfield(L, -1, "reload"); - c->controls.reload = (u16) lua_tonumber(L, -1); + if ((i16) lua_tonumber(L, -1) > 0) c->controls.reload = (u16) lua_tonumber(L, -1); + else SK_LOG_WARN("sk_config_load :: `Controls.reload` needs to be > 0. Using default instead"); lua_pop(L, 1); lua_pop(L, 1); lua_close(L);