Editor: slightly less hardcoded teleport map
Some checks reported errors
continuous-integration/drone/push Build encountered an error

This commit is contained in:
zv0n 2022-11-13 20:56:20 +01:00
parent c5283000c7
commit 6ac2726a94
5 changed files with 52 additions and 10 deletions

View File

@ -468,5 +468,5 @@ MushroomModifierBlock::MushroomModifierBlock(
TeleportModifierBlock::TeleportModifierBlock( TeleportModifierBlock::TeleportModifierBlock(
int x, int y, std::shared_ptr<SDLPP::Renderer> &renderer) int x, int y, std::shared_ptr<SDLPP::Renderer> &renderer)
: MarioBlock(x, y, renderer, g_mod_texture, MOD_TELEPORT_SRC, false) { : MarioBlock(x, y, renderer, g_mod_texture, MOD_TELEPORT_SRC, false) {
setId(MUSHROOM_MODIFIER_ID); setId(TELEPORT_MODIFIER_ID);
} }

View File

@ -33,9 +33,22 @@ uint8_t read8Bits(std::ifstream &file) {
file.read((char *)&data, sizeof(uint8_t) / sizeof(char)); file.read((char *)&data, sizeof(uint8_t) / sizeof(char));
return data; return data;
} }
std::string readString(std::ifstream &file) {
std::string res = "";
char tmp{};
file.read(&tmp, 1);
while (tmp != '\0') {
res += tmp;
file.read(&tmp, 1);
}
return res;
}
void write8Bits(std::ofstream &file, uint8_t data) { void write8Bits(std::ofstream &file, uint8_t data) {
file.write((char *)&data, sizeof(uint8_t) / sizeof(char)); file.write((char *)&data, sizeof(uint8_t) / sizeof(char));
} }
void writeString(std::ofstream &file, const std::string &text) {
file.write(text.c_str(), text.size() + 1);
}
uint16_t read16Bits(std::ifstream &file) { uint16_t read16Bits(std::ifstream &file) {
uint16_t data; uint16_t data;
@ -74,6 +87,7 @@ MapObject parseBlock(std::ifstream &map_file) {
uint8_t character_id = 0; uint8_t character_id = 0;
uint32_t modifier_id = 0; uint32_t modifier_id = 0;
uint8_t modifier_data = 0; uint8_t modifier_data = 0;
std::string modifier_text = "";
uint16_t wide_terrain = read16Bits(map_file); uint16_t wide_terrain = read16Bits(map_file);
auto terrain = separateWideTerrain(wide_terrain); auto terrain = separateWideTerrain(wide_terrain);
uint16_t terrain_id = terrain.first; uint16_t terrain_id = terrain.first;
@ -86,6 +100,9 @@ MapObject parseBlock(std::ifstream &map_file) {
auto modifier = separateAdditionalData(additional_data); auto modifier = separateAdditionalData(additional_data);
modifier_id = modifier.first | 0x6000; modifier_id = modifier.first | 0x6000;
modifier_data = modifier.second; modifier_data = modifier.second;
if(modifier_id == TELEPORT_MODIFIER_ID) {
modifier_text = readString(map_file);
}
} else { } else {
// character // character
auto character = separateAdditionalData(additional_data); auto character = separateAdditionalData(additional_data);
@ -94,7 +111,7 @@ MapObject parseBlock(std::ifstream &map_file) {
} }
} }
return MapObject(terrain_id, terrain_type, character_id, character_type, return MapObject(terrain_id, terrain_type, character_id, character_type,
modifier_id, modifier_data); modifier_id, modifier_data, modifier_text);
} }
void loadEmptyMap(std::vector<mapColumnType> &objects, size_t editor_width) { void loadEmptyMap(std::vector<mapColumnType> &objects, size_t editor_width) {
@ -167,7 +184,7 @@ void loadMapV01(std::shared_ptr<SDLPP::Scene> &scene,
mushroom = true; mushroom = true;
} }
if (!editor && block.getModifierId() == TELEPORT_MODIFIER_ID) { if (!editor && block.getModifierId() == TELEPORT_MODIFIER_ID) {
teleport_level = "test.marmap"; teleport_level = block.getModifierText();
} }
// TODO add modifiers to createTerrainBlock // TODO add modifiers to createTerrainBlock
if (block.getTerrainId() != 0) { if (block.getTerrainId() != 0) {
@ -270,6 +287,9 @@ void saveMap(const std::string &file, std::vector<mapColumnType> &objects) {
} }
if (additional_data) { if (additional_data) {
write8Bits(output_file, additional_data); write8Bits(output_file, additional_data);
if(additional_data & ADDITIONAL_IS_MOD && additional_data & !block.getModifierText().empty()) {
writeString(output_file, block.getModifierText());
}
} }
} }
} }

View File

@ -2,20 +2,25 @@
MapObject::MapObject(uint16_t terrain_id, LandType::Value terrain_type, MapObject::MapObject(uint16_t terrain_id, LandType::Value terrain_type,
uint8_t character_id, LandType::Value character_type, uint8_t character_id, LandType::Value character_type,
uint32_t modifier_id, uint8_t modifier_data) { uint32_t modifier_id, uint8_t modifier_data, const std::string &modifier_text) {
setTerrain(terrain_id, terrain_type); setTerrain(terrain_id, terrain_type);
if (character_id != 0) if (character_id != 0)
setCharacter(character_id, character_type); setCharacter(character_id, character_type);
if (modifier_id != 0) if (modifier_id != 0) {
setModifier(modifier_id, modifier_data); if(!modifier_text.empty()) {
setModifier(modifier_id, modifier_text);
} else {
setModifier(modifier_id, modifier_data);
}
}
} }
MapObject::MapObject(uint16_t terrain_id, uint8_t terrain_type, MapObject::MapObject(uint16_t terrain_id, uint8_t terrain_type,
uint8_t character_id, uint8_t character_type, uint8_t character_id, uint8_t character_type,
uint32_t modifier_id, uint8_t modifier_data) uint32_t modifier_id, uint8_t modifier_data, const std::string &modifier_text)
: MapObject(terrain_id, static_cast<LandType::Value>(terrain_type), : MapObject(terrain_id, static_cast<LandType::Value>(terrain_type),
character_id, static_cast<LandType::Value>(character_type), character_id, static_cast<LandType::Value>(character_type),
modifier_id, modifier_data) {} modifier_id, modifier_data, modifier_text) {}
void MapObject::setTerrain(uint16_t id, LandType::Value land_type) { void MapObject::setTerrain(uint16_t id, LandType::Value land_type) {
terrain_id = id; terrain_id = id;
@ -48,6 +53,15 @@ void MapObject::setModifier(uint32_t id, uint8_t data) {
} }
} }
void MapObject::setModifier(uint32_t id, const std::string &text) {
setModifier(id, 0);
modifier_text = text;
}
const std::string &MapObject::getModifierText() {
return modifier_text;
}
void MapObject::unsetTerrain() { void MapObject::unsetTerrain() {
setTerrain(0, 0); setTerrain(0, 0);
} }

View File

@ -8,15 +8,16 @@ public:
MapObject() = default; MapObject() = default;
MapObject(uint16_t terrain_id, uint8_t terrain_type, uint8_t character_id, MapObject(uint16_t terrain_id, uint8_t terrain_type, uint8_t character_id,
uint8_t character_type, uint32_t modifier_id, uint8_t character_type, uint32_t modifier_id,
uint8_t modifier_data); uint8_t modifier_data, const std::string &modifier_text);
MapObject(uint16_t terrain_id, LandType::Value terrain_type, MapObject(uint16_t terrain_id, LandType::Value terrain_type,
uint8_t character_id, LandType::Value character_type, uint8_t character_id, LandType::Value character_type,
uint32_t modifier_id, uint8_t modifier_data); uint32_t modifier_id, uint8_t modifier_data, const std::string &modifier_text);
void setTerrain(uint16_t id, LandType::Value land_type); void setTerrain(uint16_t id, LandType::Value land_type);
void setTerrain(uint16_t id, uint8_t land_type); void setTerrain(uint16_t id, uint8_t land_type);
void setCharacter(uint8_t id, LandType::Value land_type); void setCharacter(uint8_t id, LandType::Value land_type);
void setCharacter(uint8_t id, uint8_t land_type); void setCharacter(uint8_t id, uint8_t land_type);
void setModifier(uint32_t id, uint8_t data); void setModifier(uint32_t id, uint8_t data);
void setModifier(uint32_t id, const std::string &text);
void unsetTerrain(); void unsetTerrain();
void unsetModifier(); void unsetModifier();
void unsetCharacter(); void unsetCharacter();
@ -29,6 +30,7 @@ public:
LandType::Value getTerrainType(); LandType::Value getTerrainType();
LandType::Value getCharacterType(); LandType::Value getCharacterType();
uint8_t getModifierData(); uint8_t getModifierData();
const std::string &getModifierText();
private: private:
LandType::Value terrain_type = LandType::OVERWORLD; LandType::Value terrain_type = LandType::OVERWORLD;
@ -37,6 +39,7 @@ private:
uint8_t character_id = 0; uint8_t character_id = 0;
uint32_t modifier_id = 0; uint32_t modifier_id = 0;
uint8_t modifier_data = 0; uint8_t modifier_data = 0;
std::string modifier_text = "";
}; };
#endif #endif

View File

@ -765,6 +765,11 @@ void placeTool(SDLPP::Scene &scene) {
global_vars.mouse.edit_box.getY(), false, true); global_vars.mouse.edit_box.getY(), false, true);
new_obj->setTextureKeepSRC(global_vars.translucent_mod_texture); new_obj->setTextureKeepSRC(global_vars.translucent_mod_texture);
new_obj->setData(global_vars.current_tool->getData()); new_obj->setData(global_vars.current_tool->getData());
if(new_obj->getId() == TELEPORT_MODIFIER_ID) {
// TODO input
new_obj->setTeleportLevel("test2.marmap");
obj.setModifier(global_vars.current_tool->getId(), "test2.marmap");
}
new_obj->getCollisions()[0]->setId(EDITOR_TERRAIN_ID); new_obj->getCollisions()[0]->setId(EDITOR_TERRAIN_ID);
// TODO createModifierBlock // TODO createModifierBlock
dynamic_cast<MarioBlock *>(new_obj.get())->setTerrain(false); dynamic_cast<MarioBlock *>(new_obj.get())->setTerrain(false);