Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: difference of splash type on rme and server #104

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 45 additions & 17 deletions source/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,44 @@ void Item::animate() {
// ============================================================================
// Static conversions

std::string Item::LiquidID2Name(uint16_t id) {
uint8_t Item::liquidSubTypeToSpriteSubType(uint8_t id) {
switch (id) {
case LIQUID_WATER:
return 1;
case LIQUID_BLOOD:
case LIQUID_LIFEFLUID:
return 2;
case LIQUID_BEER:
case LIQUID_MUD:
case LIQUID_OIL:
case LIQUID_RUM:
case LIQUID_MEAD:
case LIQUID_TEA:
return 3;
case LIQUID_SLIME:
return 4;
case LIQUID_URINE:
case LIQUID_LEMONADE:
case LIQUID_FRUIT_JUICE:
return 5;
case LIQUID_MILK:
case LIQUID_COCONUT_MILK:
return 6;
case LIQUID_MANAFLUID:
case LIQUID_WINE:
return 7;
case LIQUID_INK:
return 8;
case LIQUID_CHOCOLATE:
return 9;
case LIQUID_UNKNOWN:
return 10;
default:
return 0;
}
}

std::string Item::LiquidID2Name(uint8_t id) {
switch (id) {
case LIQUID_NONE:
return "None";
Expand All @@ -418,14 +455,10 @@ std::string Item::LiquidID2Name(uint16_t id) {
return "Milk";
case LIQUID_MANAFLUID:
return "Manafluid";
case LIQUID_WATER2:
return "Water";
case LIQUID_LIFEFLUID:
return "Lifefluid";
case LIQUID_OIL:
return "Oil";
case LIQUID_SLIME2:
return "Slime";
case LIQUID_URINE:
return "Urine";
case LIQUID_COCONUT_MILK:
Expand All @@ -436,24 +469,22 @@ std::string Item::LiquidID2Name(uint16_t id) {
return "Mud";
case LIQUID_FRUIT_JUICE:
return "Fruit Juice";
case LIQUID_LAVA:
return "Lava";
case LIQUID_RUM:
return "Rum";
case LIQUID_SWAMP:
return "Swamp";
case LIQUID_INK:
return "Ink";
case LIQUID_TEA:
return "Tea";
case LIQUID_MEAD:
return "Mead";
case LIQUID_CHOCOLATE:
return "Chocolate";
default:
return "Unknown";
}
}

uint16_t Item::LiquidName2ID(std::string liquid) {
uint8_t Item::LiquidName2ID(std::string liquid) {
to_lower_str(liquid);
if (liquid == "none") {
return LIQUID_NONE;
Expand Down Expand Up @@ -500,15 +531,9 @@ uint16_t Item::LiquidName2ID(std::string liquid) {
if (liquid == "fruit juice") {
return LIQUID_FRUIT_JUICE;
}
if (liquid == "lava") {
return LIQUID_LAVA;
}
if (liquid == "rum") {
return LIQUID_RUM;
}
if (liquid == "swamp") {
return LIQUID_SWAMP;
}
if (liquid == "ink") {
return LIQUID_INK;
}
Expand All @@ -518,7 +543,10 @@ uint16_t Item::LiquidName2ID(std::string liquid) {
if (liquid == "mead") {
return LIQUID_MEAD;
}
return LIQUID_NONE;
if (liquid == "chocolate") {
return LIQUID_CHOCOLATE;
}
return LIQUID_UNKNOWN;
}

// ============================================================================
Expand Down
47 changes: 23 additions & 24 deletions source/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,31 @@ enum ITEMPROPERTY {
BLOCKINGANDNOTMOVEABLE
};

enum SplashType {
enum SplashType : uint8_t {
LIQUID_NONE = 0,
LIQUID_WATER = 1,
LIQUID_BLOOD = 2,
LIQUID_WINE = 2,
LIQUID_BEER = 3,
LIQUID_SLIME = 4,
LIQUID_LEMONADE = 5,
LIQUID_MILK = 6,
LIQUID_MANAFLUID = 7,
LIQUID_INK = 8,
LIQUID_WATER2 = 9,
LIQUID_LIFEFLUID = 10,
LIQUID_OIL = 11,
LIQUID_SLIME2 = 12,
LIQUID_URINE = 13,
LIQUID_COCONUT_MILK = 14,
LIQUID_WINE = 15,
LIQUID_MUD = 19,
LIQUID_FRUIT_JUICE = 21,
LIQUID_LAVA = 26,
LIQUID_RUM = 27,
LIQUID_SWAMP = 28,
LIQUID_TEA = 35,
LIQUID_MEAD = 43,
LIQUID_MUD = 4,
LIQUID_BLOOD = 5,
LIQUID_SLIME = 6,
LIQUID_OIL = 7,
LIQUID_URINE = 8,
LIQUID_MILK = 9,
LIQUID_MANAFLUID = 10,
LIQUID_LIFEFLUID = 11,
LIQUID_LEMONADE = 12,
LIQUID_RUM = 13,
LIQUID_FRUIT_JUICE = 14,
LIQUID_COCONUT_MILK = 15,
LIQUID_MEAD = 16,
LIQUID_TEA = 17,
LIQUID_INK = 18,
LIQUID_UNKNOWN = 19,
LIQUID_CHOCOLATE = 20,

LIQUID_FIRST = LIQUID_WATER,
LIQUID_LAST = LIQUID_MEAD
LIQUID_LAST = LIQUID_CHOCOLATE
};

IMPLEMENT_INCREMENT_OP(SplashType)
Expand Down Expand Up @@ -140,8 +138,9 @@ class Item : public ItemAttributes {
*/

// Static conversions
static std::string LiquidID2Name(uint16_t id);
static uint16_t LiquidName2ID(std::string id);
static uint8_t liquidSubTypeToSpriteSubType(uint8_t id);
static std::string LiquidID2Name(uint8_t id);
static uint8_t LiquidName2ID(std::string id);

const ItemType &getItemType() const noexcept {
return g_items.getItemType(id);
Expand Down
2 changes: 1 addition & 1 deletion source/map_drawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ void MapDrawer::BlitItem(int &draw_x, int &draw_y, const Tile* tile, const Item*
int pattern_z = pos.z % sprite->pattern_z;

if (type.isSplash() || type.isFluidContainer()) {
subtype = item->getSubtype();
subtype = Item::liquidSubTypeToSpriteSubType(item->getSubtype());
} else if (type.isHangable) {
if (tile->hasProperty(HOOK_SOUTH)) {
pattern_x = 1;
Expand Down
18 changes: 12 additions & 6 deletions source/old_properties_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,11 @@ OldPropertiesWindow::OldPropertiesWindow(wxWindow* win_parent, const Map* map, c

// SetSize(220, 310);
} else if (edit_item->isSplash() || edit_item->isFluidContainer()) {

const auto subTypeName = edit_item->isSplash() ? "Splash" : "Fluid Container";

// Splash
wxSizer* boxsizer = newd wxStaticBoxSizer(wxVERTICAL, this, "Splash Properties");
wxSizer* boxsizer = newd wxStaticBoxSizer(wxVERTICAL, this, wxString::Format("%s Properties", subTypeName));

wxFlexGridSizer* subsizer = newd wxFlexGridSizer(2, 10, 10);
subsizer->AddGrowableCol(1);
Expand All @@ -165,17 +168,20 @@ OldPropertiesWindow::OldPropertiesWindow(wxWindow* win_parent, const Map* map, c
// Splash types
splash_type_field = newd wxChoice(this, wxID_ANY);
if (edit_item->isFluidContainer()) {
splash_type_field->Append(wxstr(Item::LiquidID2Name(LIQUID_NONE)), newd int32_t(LIQUID_NONE));
splash_type_field->Append(wxstr(Item::LiquidID2Name(LIQUID_NONE)), newd uint8_t(LIQUID_NONE));
}

for (SplashType splashType = LIQUID_FIRST; splashType != LIQUID_LAST; ++splashType) {
splash_type_field->Append(wxstr(Item::LiquidID2Name(splashType)), newd int32_t(splashType));
for (SplashType splashType = LIQUID_FIRST; splashType <= LIQUID_LAST; ++splashType) {
const auto splashTypeName = wxstr(Item::LiquidID2Name(splashType));
if (splashTypeName != "Unknown") {
splash_type_field->Append(splashTypeName, newd uint8_t(splashType));
}
}

if (item->getSubtype()) {
const std::string &what = Item::LiquidID2Name(item->getSubtype());
if (what == "Unknown") {
splash_type_field->Append(wxstr(Item::LiquidID2Name(LIQUID_NONE)), newd int32_t(LIQUID_NONE));
splash_type_field->Append(wxstr(Item::LiquidID2Name(LIQUID_UNKNOWN)), newd uint8_t(LIQUID_UNKNOWN));
}
splash_type_field->SetStringSelection(wxstr(what));
} else {
Expand Down Expand Up @@ -538,7 +544,7 @@ OldPropertiesWindow::OldPropertiesWindow(wxWindow* win_parent, const Map* map, c
OldPropertiesWindow::~OldPropertiesWindow() {
// Warning: edit_item may no longer be valid, DONT USE IT!
if (splash_type_field) {
for (uint32_t i = 0; i < splash_type_field->GetCount(); ++i) {
for (uint8_t i = 0; i < splash_type_field->GetCount(); ++i) {
delete reinterpret_cast<int*>(splash_type_field->GetClientData(i));
}
}
Expand Down
Loading