Compare commits

...

1 Commits

Author SHA1 Message Date
Pascal Abresch 93f1555e2f Remove Craftmethods enum 2021-09-03 16:00:37 +02:00
4 changed files with 15 additions and 43 deletions

View File

@ -299,7 +299,7 @@ bool CraftInput::empty() const
std::string CraftInput::dump() const
{
std::ostringstream os(std::ios::binary);
os << "(method=" << ((int)method) << ", items="
os << "(method=" << (method) << ", items="
<< craftDumpMatrix(items, width) << ")";
return os.str();
}

View File

@ -32,15 +32,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
The crafting method depends on the inventory list
that the crafting input comes from.
*/
enum CraftMethod
{
// Crafting grid
CRAFT_METHOD_NORMAL,
// Cooking something in a furnace
CRAFT_METHOD_COOKING,
// Using something as fuel for a furnace
CRAFT_METHOD_FUEL,
};
// Crafting grid
static std::string CRAFT_METHOD_NORMAL = "normal";
// Cooking something in a furnace
static std::string CRAFT_METHOD_COOKING = "cooking";
// Using something as fuel for a furnace
static std::string CRAFT_METHOD_FUEL = "fuel";
/*
The type a hash can be. The earlier a type is mentioned in this enum,
@ -69,13 +67,13 @@ const int craft_hash_type_max = (int) CRAFT_HASH_TYPE_UNHASHED;
*/
struct CraftInput
{
CraftMethod method = CRAFT_METHOD_NORMAL;
std::string method = CRAFT_METHOD_NORMAL;
unsigned int width = 0;
std::vector<ItemStack> items;
CraftInput() = default;
CraftInput(CraftMethod method_, unsigned int width_,
CraftInput(std::string method_, unsigned int width_,
const std::vector<ItemStack> &items_):
method(method_), width(width_), items(items_)
{}

View File

@ -26,14 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "server.h"
#include "craftdef.h"
struct EnumString ModApiCraft::es_CraftMethod[] =
{
{CRAFT_METHOD_NORMAL, "normal"},
{CRAFT_METHOD_COOKING, "cooking"},
{CRAFT_METHOD_FUEL, "fuel"},
{0, NULL},
};
// helper for register_craft
bool ModApiCraft::readCraftRecipeShaped(lua_State *L, int index,
int &width, std::vector<std::string> &recipe)
@ -305,7 +297,7 @@ int ModApiCraft::l_clear_craft(lua_State *L)
}
std::vector<std::string> recipe;
int width = 0;
CraftMethod method = CRAFT_METHOD_NORMAL;
std::string method = CRAFT_METHOD_NORMAL;
/*
CraftDefinitionShaped
*/
@ -373,9 +365,7 @@ int ModApiCraft::l_get_craft_result(lua_State *L)
NO_MAP_LOCK_REQUIRED;
int input_i = 1;
std::string method_s = getstringfield_default(L, input_i, "method", "normal");
enum CraftMethod method = (CraftMethod)getenumfield(L, input_i, "method",
es_CraftMethod, CRAFT_METHOD_NORMAL);
std::string method = getstringfield_default(L, input_i, "method", "normal");
int width = 1;
lua_getfield(L, input_i, "width");
if(lua_isnumber(L, -1))
@ -408,7 +398,7 @@ int ModApiCraft::l_get_craft_result(lua_State *L)
lua_setfield(L, -2, "replacements");
}
lua_newtable(L); // decremented input table
lua_pushstring(L, method_s.c_str());
lua_pushstring(L, method.c_str());
lua_setfield(L, -2, "method");
lua_pushinteger(L, width);
lua_setfield(L, -2, "width");
@ -436,25 +426,11 @@ static void push_craft_recipe(lua_State *L, IGameDef *gdef,
lua_setfield(L, -2, "items");
setintfield(L, -1, "width", input.width);
std::string method_s;
switch (input.method) {
case CRAFT_METHOD_NORMAL:
method_s = "normal";
break;
case CRAFT_METHOD_COOKING:
method_s = "cooking";
break;
case CRAFT_METHOD_FUEL:
method_s = "fuel";
break;
default:
method_s = "unknown";
}
lua_pushstring(L, method_s.c_str());
lua_pushstring(L, input.method.c_str());
lua_setfield(L, -2, "method");
// Deprecated, only for compatibility's sake
lua_pushstring(L, method_s.c_str());
lua_pushstring(L, input.method.c_str());
lua_setfield(L, -2, "type");
lua_pushstring(L, output.item.c_str());

View File

@ -41,8 +41,6 @@ private:
static bool readCraftRecipeShaped(lua_State *L, int index,
int &width, std::vector<std::string> &recipe);
static struct EnumString es_CraftMethod[];
public:
static void Initialize(lua_State *L, int top);
};