Skip to content

Commit

Permalink
fix: version modifications and removed client versions selector
Browse files Browse the repository at this point in the history
  • Loading branch information
phacUFPE committed Jul 28, 2024
1 parent dafc9b3 commit 054f22a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 33 deletions.
3 changes: 3 additions & 0 deletions source/client_assets.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ enum MapVersionID {
MAP_OTBM_3 = 2,
MAP_OTBM_4 = 3,
MAP_OTBM_5 = 4,
MAP_OTBM_6 = 5,

MAP_OTBM_LAST_VERSION = MAP_OTBM_6
};

// The composed version of a otbm file (otbm version)
Expand Down
42 changes: 17 additions & 25 deletions source/common_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ MapPropertiesWindow::MapPropertiesWindow(wxWindow* parent, MapTab* view, Editor
// Map version
grid_sizer->Add(newd wxStaticText(this, wxID_ANY, "Map Version"));
version_choice = newd wxChoice(this, MAP_PROPERTIES_VERSION);
version_choice->Append("OTServ 0.5.0");
version_choice->Append("OTServ 0.6.0");
version_choice->Append("OTServ 0.6.1");
version_choice->Append("OTServ 0.7.0 (revscriptsys)");
version_choice->Append("0.5.0");
version_choice->Append("0.6.0");
version_choice->Append("0.6.1");
version_choice->Append("0.7.0 (revscriptsys)");
version_choice->Append("1.0.0");
version_choice->Append("1.1.0 (revscriptsys)");

switch (map.getVersion().otbm) {
case MAP_OTBM_1:
Expand All @@ -87,20 +89,18 @@ MapPropertiesWindow::MapPropertiesWindow(wxWindow* parent, MapTab* view, Editor
case MAP_OTBM_4:
version_choice->SetSelection(3);
break;
case MAP_OTBM_5:
version_choice->SetSelection(4);
break;
case MAP_OTBM_6:
version_choice->SetSelection(5);
break;
default:
version_choice->SetSelection(0);
}

grid_sizer->Add(version_choice, wxSizerFlags(1).Expand());

// Client directory
grid_sizer->Add(newd wxStaticText(this, wxID_ANY, "Client Folder"));
protocol_choice = newd wxChoice(this, wxID_ANY);

protocol_choice->SetStringSelection(wxstr(ClientAssets::getVersionName()));

grid_sizer->Add(protocol_choice, wxSizerFlags(1).Expand());

// Dimensions
grid_sizer->Add(newd wxStaticText(this, wxID_ANY, "Map Dimensions"));
{
Expand Down Expand Up @@ -156,22 +156,10 @@ MapPropertiesWindow::MapPropertiesWindow(wxWindow* parent, MapTab* view, Editor

SetSizerAndFit(topsizer);
Centre(wxBOTH);
UpdateProtocolList();

protocol_choice->SetStringSelection(wxstr(ClientAssets::getVersionName()));
}

void MapPropertiesWindow::UpdateProtocolList() {
wxString ver = version_choice->GetStringSelection();
wxString client = protocol_choice->GetStringSelection();

protocol_choice->Clear();
protocol_choice->SetSelection(0);
protocol_choice->SetStringSelection(client);
}

void MapPropertiesWindow::OnChangeVersion(wxCommandEvent &) {
UpdateProtocolList();
//
}

struct MapConversionContext {
Expand Down Expand Up @@ -228,6 +216,10 @@ void MapPropertiesWindow::OnClickOK(wxCommandEvent &WXUNUSED(event)) {
new_ver.otbm = MAP_OTBM_3;
} else if (ver.Contains("0.7.0")) {
new_ver.otbm = MAP_OTBM_4;
} else if (ver.Contains("1.0.0")) {
new_ver.otbm = MAP_OTBM_5;
} else if (ver.Contains("1.1.0")) {
new_ver.otbm = MAP_OTBM_6;
}

if (new_ver.otbm != old_ver.otbm) {
Expand Down
3 changes: 0 additions & 3 deletions source/common_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,11 @@ class MapPropertiesWindow : public wxDialog {
void OnClickCancel(wxCommandEvent &);

protected:
void UpdateProtocolList();

MapTab* view;
Editor &editor;
wxSpinCtrl* height_spin;
wxSpinCtrl* width_spin;
wxChoice* version_choice;
wxChoice* protocol_choice;
wxTextCtrl* description_ctrl;
wxTextCtrl* house_filename_ctrl;
wxTextCtrl* spawn_filename_ctrl;
Expand Down
11 changes: 6 additions & 5 deletions source/iomap_otbm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void Item::serializeItemAttributes_OTBM(const IOMap &maphandle, NodeFileWriteHan
}
}

if (maphandle.version.otbm >= MAP_OTBM_4) {
if (maphandle.version.otbm == MAP_OTBM_4 || maphandle.version.otbm > MAP_OTBM_5) {
if (attributes && !attributes->empty()) {
stream.addU8(OTBM_ATTR_ATTRIBUTE_MAP);
serializeAttributeMap(maphandle, stream);
Expand All @@ -186,13 +186,13 @@ void Item::serializeItemAttributes_OTBM(const IOMap &maphandle, NodeFileWriteHan
stream.addU16(getSubtype());
}

uint16_t actionId = getActionID();
const auto actionId = getActionID();
if (actionId > 0) {
stream.addU8(OTBM_ATTR_ACTION_ID);
stream.addU16(actionId);
}

uint16_t uniqueId = getUniqueID();
const auto uniqueId = getUniqueID();
if (uniqueId > 0) {
stream.addU8(OTBM_ATTR_UNIQUE_ID);
stream.addU16(uniqueId);
Expand Down Expand Up @@ -664,7 +664,7 @@ bool IOMapOTBM::loadMap(Map &map, NodeFileReadHandle &f) {

version.otbm = (MapVersionID)u32;

if (version.otbm > MAP_OTBM_5) {
if (version.otbm > MAP_OTBM_LAST_VERSION) {
// Failed to read version
if (g_gui.PopupDialog("Map error", "The loaded map appears to be a OTBM format that is not supported by the editor."
"Do you still want to attempt to load the map?",
Expand Down Expand Up @@ -1536,7 +1536,8 @@ bool IOMapOTBM::saveMap(Map &map, NodeFileWriteHandle &f) {
FileName tmpName;
f.addNode(0);
{
f.addU32(MapVersionID::MAP_OTBM_5); // Map version
const auto mapVersion = map.mapVersion.otbm < MapVersionID::MAP_OTBM_5 ? MapVersionID::MAP_OTBM_5 : map.mapVersion.otbm;
f.addU32(mapVersion); // Map version

f.addU16(map.width);
f.addU16(map.height);
Expand Down

0 comments on commit 054f22a

Please sign in to comment.