From b61898c30c1e1049e8767ca98fd38e7010a32e45 Mon Sep 17 00:00:00 2001 From: Lane Kolbly Date: Wed, 12 Jul 2017 05:30:43 -0500 Subject: Lua plugin cColor (#3833) --- Server/Plugins/APIDump/APIDesc.lua | 172 +++++++++++++++++++++++++++++++++++++ src/Bindings/AllToLua.pkg | 1 + src/Bindings/CMakeLists.txt | 1 + src/Bindings/ManualBindings.cpp | 22 +++++ src/Color.h | 12 +-- 5 files changed, 202 insertions(+), 6 deletions(-) diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua index 65ae69144..29545a692 100644 --- a/Server/Plugins/APIDump/APIDesc.lua +++ b/Server/Plugins/APIDump/APIDesc.lua @@ -1730,6 +1730,178 @@ end }, }, }, + cColor = + { + Desc = [[ + Encapsulates a RGB color, e.g. for armor. + ]], + Functions = + { + Clear = + { + Notes = "Resets the color to uninitialized." + }, + constructor = + { + { + Returns = { {Type="cColor"} }, + Notes = "Creates an uninitialized cColor. Each component must be between 0 and 255, inclusive.", + }, + { + Params = + { + { + Name = "Red", + Type = "number", + }, + { + Name = "Green", + Type = "number", + }, + { + Name = "Blue", + Type = "number", + }, + }, + Returns = { {Type="cColor"} }, + Notes = "Creates the specified cColor. All components must be between 0 and 255, inclusive.", + }, + }, + GetColor = + { + Returns = + { + { + Name = "Red", + Type = "number", + }, + { + Name = "Green", + Type = "number", + }, + { + Name = "Blue", + Type = "number", + }, + }, + Notes = "Returns the color's red, green, and blue components, respectively." + }, + GetRed = + { + Returns = + { + { + Name = "Red", + Type = "number", + }, + }, + Notes = "Returns the color's red component." + }, + GetGreen = + { + Returns = + { + { + Name = "Green", + Type = "number", + }, + }, + Notes = "Returns the color's green component." + }, + GetBlue = + { + Returns = + { + { + Name = "Blue", + Type = "number", + }, + }, + Notes = "Returns the color's blue component." + }, + IsValid = + { + Returns = + { + { + Type = "boolean" + }, + }, + Notes = "True if the color is valid, false if the color has not been set yet." + }, + SetColor = + { + Params = + { + { + Name = "Red", + Type = "number" + }, + { + Name = "Green", + Type = "number" + }, + { + Name = "Blue", + Type = "number" + }, + }, + Notes = "Sets the color's red, green, and blue components. Values range from 0 to 255." + }, + SetRed = + { + Params = + { + { + Name = "Red", + Type = "number", + }, + }, + Notes = "Sets the color's red component. Must be between 0 and 255, inclusive." + }, + SetGreen = + { + Params = + { + { + Name = "Green", + Type = "number", + }, + }, + Notes = "Sets the color's green component. Must be between 0 and 255, inclusive." + }, + SetBlue = + { + Params = + { + { + Name = "Blue", + Type = "number", + }, + }, + Notes = "Sets the color's blue component. Must be between 0 and 255, inclusive." + }, + }, + Constants = + { + COLOR_LIMIT = + { + Notes = "The upper bound (exclusive) for a color component", + }, + COLOR_MAX = + { + Notes = "The maximum value for a color component", + }, + COLOR_MIN = + { + Notes = "The minimum value for a color component", + }, + COLOR_NONE = + { + Notes = "A constant denoting the color is invalid (note: use IsValid)", + }, + }, + }, cCompositeChat = { Desc = [[ diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 31c914bcd..a109913e2 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -46,6 +46,7 @@ $cfile "../StringUtils.h" $cfile "../Defines.h" $cfile "../ChatColor.h" $cfile "../ClientHandle.h" +$cfile "../Color.h" $cfile "../EffectID.h" $cfile "../Server.h" $cfile "../World.h" diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt index e50db12c3..da7c8bbe8 100644 --- a/src/Bindings/CMakeLists.txt +++ b/src/Bindings/CMakeLists.txt @@ -89,6 +89,7 @@ set(BINDING_DEPENDENCIES ../ChatColor.h ../ChunkDef.h ../ClientHandle.h + ../Color.h ../CompositeChat.h ../CraftingRecipes.h ../Cuboid.h diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 565c636e3..e81a8ef05 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -3297,6 +3297,24 @@ static int tolua_cChunkDesc_GetBlockTypeMeta(lua_State * a_LuaState) +static int tolua_cColor_GetColor(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + + cColor * self; + if (!L.CheckParamSelf("cColor") || !L.GetStackValue(1, self)) + { + return 0; + } + + L.Push(self->GetRed(), self->GetGreen(), self->GetBlue()); + return 3; +} + + + + + static int tolua_cCompositeChat_new(lua_State * a_LuaState) { /* Function signatures: @@ -3727,6 +3745,10 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "SendPluginMessage", tolua_cClientHandle_SendPluginMessage); tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cColor"); + tolua_function(tolua_S, "GetColor", tolua_cColor_GetColor); + tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cCompositeChat"); tolua_function(tolua_S, "new", tolua_cCompositeChat_new); tolua_function(tolua_S, "new_local", tolua_cCompositeChat_new_local); diff --git a/src/Color.h b/src/Color.h index 3680193ab..059729bcf 100644 --- a/src/Color.h +++ b/src/Color.h @@ -9,13 +9,12 @@ #pragma once - // tolua_begin - +// tolua_begin class cColor { public: - enum : unsigned int + enum eColorLimits : unsigned int { COLOR_MIN = 0, COLOR_MAX = 255, @@ -28,6 +27,7 @@ public: /** Returns whether the color is a valid color */ bool IsValid() const { return m_Color != COLOR_NONE; } + /** Changes the color */ void SetColor(unsigned char a_Red, unsigned char a_Green, unsigned char a_Blue); @@ -35,10 +35,10 @@ public: void SetRed(unsigned char a_Red); /** Alters the green value of the color */ - void SetGreen(unsigned char a_Red); + void SetGreen(unsigned char a_Green); /** Alters the blue value of the color */ - void SetBlue(unsigned char a_Red); + void SetBlue(unsigned char a_Blue); /** Returns the red value of the color */ unsigned char GetRed() const; @@ -55,4 +55,4 @@ public: unsigned int m_Color; -}; +}; // tolua_export -- cgit v1.2.3