From 7f66a924156e6baa9110e2e023e3a24c31ce95d3 Mon Sep 17 00:00:00 2001 From: Andy Belle-Isle Date: Mon, 2 Sep 2019 00:08:38 -0400 Subject: Added LIGHTING --- src/components/Light.hpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++ src/components/Render.hpp | 6 ++++++ 2 files changed, 60 insertions(+) create mode 100644 src/components/Light.hpp (limited to 'src/components') diff --git a/src/components/Light.hpp b/src/components/Light.hpp new file mode 100644 index 0000000..ee215a6 --- /dev/null +++ b/src/components/Light.hpp @@ -0,0 +1,54 @@ +/** + * @file Light.hpp + * + * Copyright (C) 2019 Belle-Isle, Andrew + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +#ifndef COMPONENT_LIGHT_HPP_ +#define COMPONENT_LIGHT_HPP_ + +#include "Component.hpp" + +struct Light : Component, entityx::Component +{ +public: + float r, g, b; + float strength; + + Light() {} + Light(float _r, float _g, float _z, float _s) : + r(_r), g(_g), b(_z), strength(_s) {} + + Light FromLua(sol::object ref) + { + if (ref.get_type() == sol::type::table) { + sol::table tab = ref; + if (tab["r"] == sol::type::number) + this->r = tab["r"]; + if (tab["g"] == sol::type::number) + this->g = tab["g"]; + if (tab["b"] == sol::type::number) + this->b = tab["b"]; + if (tab["strength"] == sol::type::number) + this->strength = tab["strength"]; + } else { + throw std::string("Light component must be a table"); + } + return *this; + } +}; + +#endif//COMPONENT_LIGHT_HPP_ diff --git a/src/components/Render.hpp b/src/components/Render.hpp index 6cc26db..f5936ea 100644 --- a/src/components/Render.hpp +++ b/src/components/Render.hpp @@ -25,7 +25,9 @@ struct Render : Component, entityx::Component { public: Texture texture; + Texture normal; bool visible; + bool hasNormal = false; Render(std::string _file) : texture(_file), visible(true) {} @@ -40,6 +42,10 @@ public: this->visible = tab["visible"]; if (tab["texture"].get_type() == sol::type::string) this->texture = Texture(static_cast(tab["texture"])); + if (tab["normal"].get_type() == sol::type::string) { + this->normal = Texture(static_cast(tab["normal"])); + hasNormal = true; + } } else { throw std::string( "Render component table formatted incorrectly" -- cgit v1.2.3