1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-30 09:15:38 +00:00

changed a few hardcoded refIds used in mutliple places to be defined only once in a variable

This commit is contained in:
fteppe 2022-10-12 19:45:23 +02:00 committed by florent.teppe
parent 20da0892ef
commit 62d8fe3fc2
20 changed files with 86 additions and 41 deletions

View file

@ -7,6 +7,7 @@
#include <osg/ImageUtils>
#include <osgDB/ReadFile>
#include <components/esm/refidhardcoded.hpp>
#include <components/esm/defs.hpp>
#include <components/esm3/esmreader.hpp>
#include <components/esm3/esmwriter.hpp>
@ -397,7 +398,7 @@ namespace ESSImport
}
writer.startRecord(ESM::REC_NPC_);
context.mPlayerBase.mId = ESM::RefId::stringRefId("player");
context.mPlayerBase.mId = ESM::sPlayerId;
context.mPlayerBase.save(writer);
writer.endRecord(ESM::REC_NPC_);

View file

@ -32,6 +32,7 @@
#include <components/esm3/loadweap.hpp>
#include <components/misc/resourcehelpers.hpp>
#include <components/misc/strings/algorithm.hpp>
#include <components/esm/refidhardcoded.hpp>
#include "../prefs/state.hpp"
@ -681,7 +682,7 @@ void CSMTools::ReferenceableCheckStage::npcCheck(
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Npc, npc.mId);
// Detect if player is present
if (npc.mId == ESM::RefId::stringRefId("player")) // Happy now, scrawl?
if (npc.mId == ESM::sPlayerId) // Happy now, scrawl?
mPlayerPresent = true;
// Skip "Base" records (setting!)

View file

@ -5,6 +5,7 @@
#include <components/esm3/loadcrea.hpp>
#include <components/esm3/loadmisc.hpp>
#include <components/esm3/loadnpc.hpp>
#include <components/esm/refidhardcoded.hpp>
#include <components/settings/settings.hpp>
@ -35,11 +36,11 @@ namespace MWClass
bool Miscellaneous::isGold(const MWWorld::ConstPtr& ptr) const
{
return ptr.getCellRef().getRefId() == ESM::RefId::stringRefId("gold_001")
|| ptr.getCellRef().getRefId() == ESM::RefId::stringRefId("gold_005")
|| ptr.getCellRef().getRefId() == ESM::RefId::stringRefId("gold_010")
|| ptr.getCellRef().getRefId() == ESM::RefId::stringRefId("gold_025")
|| ptr.getCellRef().getRefId() == ESM::RefId::stringRefId("gold_100");
return ptr.getCellRef().getRefId() == ESM::sGoldId001
|| ptr.getCellRef().getRefId() == ESM::sGoldId005
|| ptr.getCellRef().getRefId() == ESM::sGoldId010
|| ptr.getCellRef().getRefId() == ESM::sGoldId025
|| ptr.getCellRef().getRefId() == ESM::sGoldId100;
}
void Miscellaneous::insertObjectRendering(

View file

@ -4,6 +4,7 @@
#include <MyGUI_TextBox.h>
#include <components/esm3/loadbook.hpp>
#include <components/esm/refidhardcoded.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
@ -202,7 +203,7 @@ namespace MWGui
{
if (mCurrentPage > 0)
{
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page"));
MWBase::Environment::get().getWindowManager()->playSound(ESM::sBookPageSoundId);
--mCurrentPage;

View file

@ -8,6 +8,7 @@
#include <components/debug/debuglog.hpp>
#include <components/esm3/loadcrea.hpp>
#include <components/esm/refidhardcoded.hpp>
#include <components/translation/translation.hpp>
#include <components/widgets/box.hpp>
#include <components/widgets/list.hpp>
@ -278,19 +279,19 @@ namespace MWGui
void Choice::activated()
{
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
MWBase::Environment::get().getWindowManager()->playSound(ESM::sMenuClickSoundId);
eventChoiceActivated(mChoiceId);
}
void Topic::activated()
{
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
MWBase::Environment::get().getWindowManager()->playSound(ESM::sMenuClickSoundId);
eventTopicActivated(mTopicId);
}
void Goodbye::activated()
{
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
MWBase::Environment::get().getWindowManager()->playSound(ESM::sMenuClickSoundId);
eventActivated();
}

View file

@ -10,6 +10,7 @@
#include <MyGUI_TextBox.h>
#include <components/misc/strings/algorithm.hpp>
#include <components/esm/refidhardcoded.hpp>
#include <components/widgets/imagebutton.hpp>
#include <components/widgets/list.hpp>
@ -413,7 +414,7 @@ namespace
mOptionsMode = false;
mTopicsMode = false;
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page"));
MWBase::Environment::get().getWindowManager()->playSound(ESM::sBookPageSoundId);
}
void notifyTopicSelected(const ESM::RefId& topic, int id)
@ -444,7 +445,7 @@ namespace
mOptionsMode = false;
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page"));
MWBase::Environment::get().getWindowManager()->playSound(ESM::sBookPageSoundId);
}
void notifyOptions(MyGUI::Widget* _sender)
@ -472,7 +473,7 @@ namespace
assert(mStates.size() > 1);
popBook();
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page"));
MWBase::Environment::get().getWindowManager()->playSound(ESM::sBookPageSoundId);
}
void notifyIndexLinkClicked(MWGui::TypesetBook::InteractiveId index)
@ -493,7 +494,7 @@ namespace
list->adjustSize();
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page"));
MWBase::Environment::get().getWindowManager()->playSound(ESM::sBookPageSoundId);
}
void notifyTopics(MyGUI::Widget* _sender)
@ -508,7 +509,7 @@ namespace
setVisible(ShowAllBTN, false);
setVisible(ShowActiveBTN, false);
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page"));
MWBase::Environment::get().getWindowManager()->playSound(ESM::sBookPageSoundId);
}
struct AddNamesToList
@ -565,7 +566,7 @@ namespace
mModel->visitQuestNames(false, setInactive);
}
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page"));
MWBase::Environment::get().getWindowManager()->playSound(ESM::sBookPageSoundId);
}
void notifyShowAll(MyGUI::Widget* _sender)
@ -589,7 +590,7 @@ namespace
else
{
setBookMode();
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page"));
MWBase::Environment::get().getWindowManager()->playSound(ESM::sBookPageSoundId);
}
}
@ -619,7 +620,7 @@ namespace
if (page + 2 < book->pageCount())
{
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page"));
MWBase::Environment::get().getWindowManager()->playSound(ESM::sBookPageSoundId);
page += 2;
updateShowingPages();
@ -637,7 +638,7 @@ namespace
if (page >= 2)
{
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page"));
MWBase::Environment::get().getWindowManager()->playSound(ESM::sBookPageSoundId);
page -= 2;
updateShowingPages();

View file

@ -7,6 +7,7 @@
#include <components/settings/settings.hpp>
#include <components/vfs/manager.hpp>
#include <components/widgets/imagebutton.hpp>
#include <components/esm/refidhardcoded.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/statemanager.hpp"
@ -89,7 +90,7 @@ namespace MWGui
MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
const std::string& name = *sender->getUserData<std::string>();
winMgr->playSound(ESM::RefId::stringRefId("Menu Click"));
winMgr->playSound(ESM::sMenuClickSoundId);
if (name == "return")
{
winMgr->removeGuiMode(GM_MainMenu);

View file

@ -8,6 +8,7 @@
#include <components/debug/debuglog.hpp>
#include <components/files/conversion.hpp>
#include <components/sdlutil/sdlmappings.hpp>
#include <components/esm/refidhardcoded.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/inputmanager.hpp"
@ -206,7 +207,7 @@ namespace MWInput
MyGUI::Button* b
= MyGUI::InputManager::getInstance().getMouseFocusWidget()->castType<MyGUI::Button>(false);
if (b && b->getEnabled())
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
MWBase::Environment::get().getWindowManager()->playSound(ESM::sMenuClickSoundId);
}
mBindingsManager->setPlayerControlsEnabled(!mousePressSuccess);

View file

@ -6,6 +6,7 @@
#include <components/sdlutil/sdlinputwrapper.hpp>
#include <components/sdlutil/sdlmappings.hpp>
#include <components/esm/refidhardcoded.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/inputmanager.hpp"
@ -166,7 +167,7 @@ namespace MWInput
= MyGUI::InputManager::getInstance().getMouseFocusWidget()->castType<MyGUI::Button>(false);
if (b && b->getEnabled() && id == SDL_BUTTON_LEFT)
{
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
MWBase::Environment::get().getWindowManager()->playSound(ESM::sMenuClickSoundId);
}
}
MWBase::Environment::get().getWindowManager()->setCursorActive(true);

View file

@ -2,6 +2,7 @@
#include <components/lua/luastate.hpp>
#include <components/misc/resourcehelpers.hpp>
#include <components/esm/refidhardcoded.hpp>
namespace MWLua
{
@ -66,7 +67,7 @@ namespace MWLua
if (ref == nullptr)
throw std::runtime_error("Can't get type name from an empty object.");
const ESM::RefId& id = ref->mRef.getRefId();
if (id == ESM::RefId::stringRefId("player"))
if (id == ESM::sPlayerId)
return ESM::REC_INTERNAL_PLAYER;
if (Misc::ResourceHelpers::isHiddenMarker(id))
return ESM::REC_INTERNAL_MARKER;

View file

@ -6,6 +6,7 @@
#include <components/esm/records.hpp>
#include <components/esm/refid.hpp>
#include <components/esm/refidhardcoded.hpp>
#include <components/esm3/esmwriter.hpp>
#include <components/esm3/loadgmst.hpp>
#include <components/esm3/loadmgef.hpp>
@ -84,7 +85,7 @@ namespace
const MWWorld::CellRef& cellref = target.getCellRef();
const ESM::RefId& owner = cellref.getOwner();
bool isOwned = !owner.empty() && owner != ESM::RefId::stringRefId("player");
bool isOwned = !owner.empty() && owner != ESM::sPlayerId;
const ESM::RefId& faction = cellref.getFaction();
bool isFactionOwned = false;

View file

@ -26,6 +26,7 @@
#include <components/sceneutil/shadow.hpp>
#include <components/settings/settings.hpp>
#include <components/stereo/multiview.hpp>
#include <components/esm/refidhardcoded.hpp>
#include "../mwworld/class.hpp"
#include "../mwworld/inventorystore.hpp"
@ -543,7 +544,7 @@ namespace MWRender
void RaceSelectionPreview::setPrototype(const ESM::NPC& proto)
{
mBase = proto;
mBase.mId = ESM::RefId::stringRefId("player");
mBase.mId = ESM::sPlayerId;
rebuild();
}

View file

@ -10,6 +10,7 @@
#include <components/interpreter/interpreter.hpp>
#include <components/interpreter/opcodes.hpp>
#include <components/interpreter/runtime.hpp>
#include <components/esm/refidhardcoded.hpp>
#include "../mwworld/class.hpp"
#include "../mwworld/esmstore.hpp"
@ -484,7 +485,7 @@ namespace MWScript
if (!targetPtr.isEmpty() && targetPtr.getCellRef().getRefId() == testedTargetId)
targetsAreEqual = true;
}
else if (testedTargetId == ESM::RefId::stringRefId("player")) // Currently the player ID is hardcoded
else if (testedTargetId == ESM::sPlayerId) // Currently the player ID is hardcoded
{
MWBase::MechanicsManager* mechMgr = MWBase::Environment::get().getMechanicsManager();
bool greeting = mechMgr->getGreetingState(actor) == MWMechanics::Greet_InProgress;

View file

@ -15,7 +15,7 @@
#include <components/esm3/loadlevlist.hpp>
#include <components/esm3/loadskil.hpp>
#include <components/esm/refidhardcoded.hpp>
#include <components/esm3/loadcrea.hpp>
#include "../mwbase/environment.hpp"
@ -104,9 +104,9 @@ namespace MWScript
if (count == 0)
return;
if (item == ESM::RefId::stringRefId("gold_005") ||item == ESM::RefId::stringRefId("gold_010")
|| item == ESM::RefId::stringRefId("gold_025") ||item == ESM::RefId::stringRefId("gold_100"))
item = ESM::RefId::stringRefId("gold_001");
if (item == ESM::sGoldId005 ||item == ESM::sGoldId010
|| item == ESM::sGoldId025||item == ESM::sGoldId100)
item = ESM::sGoldId001;
// Check if "item" can be placed in a container
MWWorld::ManualRef manualRef(MWBase::Environment::get().getWorld()->getStore(), item, 1);

View file

@ -6,6 +6,7 @@
#include <components/debug/debuglog.hpp>
#include <components/esm/records.hpp>
#include <components/esm/refidhardcoded.hpp>
#include <components/esm3/esmreader.hpp>
#include <components/esm3/esmwriter.hpp>
#include <components/esm3/readerscache.hpp>
@ -534,7 +535,7 @@ namespace MWWorld
void ESMStore::movePlayerRecord()
{
auto& npcs = getWritable<ESM::NPC>();
auto player = npcs.find(ESM::RefId::stringRefId("player"));
auto player = npcs.find(ESM::sPlayerId);
npcs.insert(*player);
}
@ -651,7 +652,7 @@ namespace MWWorld
{
setUp();
const ESM::NPC* player = get<ESM::NPC>().find(ESM::RefId::stringRefId("player"));
const ESM::NPC* player = get<ESM::NPC>().find(ESM::sPlayerId);
if (!get<ESM::Race>().find(player->mRace) || !get<ESM::Class>().find(player->mClass))
throw std::runtime_error("Invalid player record (race or class unavailable");
@ -687,7 +688,7 @@ namespace MWWorld
{
auto& npcs = getWritable<ESM::NPC>();
if (npc.mId == ESM::RefId::stringRefId("player"))
if (npc.mId == ESM::sPlayerId)
{
return npcs.insert(npc);
}

View file

@ -5,6 +5,7 @@
#include <components/debug/debuglog.hpp>
#include <components/esm/defs.hpp>
#include <components/esm/refidhardcoded.hpp>
#include <components/esm3/esmreader.hpp>
#include <components/esm3/esmwriter.hpp>
#include <components/esm3/loadbsgn.hpp>
@ -49,7 +50,7 @@ namespace MWWorld
{
ESM::CellRef cellRef;
cellRef.blank();
cellRef.mRefID = ESM::RefId::stringRefId("player");
cellRef.mRefID = ESM::sPlayerId;
mPlayer = LiveCellRef<ESM::NPC>(cellRef, player);
ESM::Position playerPos = mPlayer.mData.getPosition();

View file

@ -12,6 +12,7 @@
#include <components/debug/debuglog.hpp>
#include <components/esm/refidhardcoded.hpp>
#include <components/esm3/cellid.hpp>
#include <components/esm3/cellref.hpp>
#include <components/esm3/esmreader.hpp>
@ -325,7 +326,7 @@ namespace MWWorld
mPlayer->clear();
mPlayer->setCell(nullptr);
mPlayer->getPlayer().getRefData() = RefData();
mPlayer->set(mStore.get<ESM::NPC>().find(ESM::RefId::stringRefId("player")));
mPlayer->set(mStore.get<ESM::NPC>().find(ESM::sPlayerId));
}
mWorldModel.clear();
@ -576,7 +577,7 @@ namespace MWWorld
= mStore.get<ESM::GameSetting>().find("sDefaultCellname")->mValue.getString();
if (Misc::StringUtils::ciEqual(cellName, defaultName))
{
cell = mStore.get<ESM::Cell>().searchExtByName(ESM::RefId::stringRefId(""));
cell = mStore.get<ESM::Cell>().searchExtByName(ESM::RefId::sEmpty);
if (cell)
return cell;
}
@ -685,7 +686,7 @@ namespace MWWorld
{
Ptr ret;
// the player is always in an active cell.
if (name == ESM::RefId::stringRefId("player"))
if (name == ESM::sPlayerId)
{
return mPlayer->getPlayer();
}
@ -1759,7 +1760,7 @@ namespace MWWorld
{
bool update = false;
if (record.mId == ESM::RefId::stringRefId("player"))
if (record.mId == ESM::sPlayerId)
{
const ESM::NPC* player = mPlayer->getPlayer().get<ESM::NPC>()->mBase;
@ -2436,7 +2437,7 @@ namespace MWWorld
void World::setupPlayer()
{
const ESM::NPC* player = mStore.get<ESM::NPC>().find(ESM::RefId::stringRefId("player"));
const ESM::NPC* player = mStore.get<ESM::NPC>().find(ESM::sPlayerId);
if (!mPlayer)
mPlayer = std::make_unique<MWWorld::Player>(player);
else

View file

@ -80,7 +80,7 @@ add_component_dir (to_utf8
to_utf8
)
add_component_dir(esm attr common defs esmcommon records util luascripts format refid)
add_component_dir(esm attr common defs esmcommon records util luascripts format refid refidhardcoded)
add_component_dir(fx pass technique lexer widgets stateupdater)

View file

@ -0,0 +1,17 @@
#include "refidhardcoded.hpp"
namespace ESM
{//A few hardcoded ids that are used multiple times accross the codebase
const RefId sPlayerId = ESM::RefId::stringRefId("Player");
const RefId sMenuClickSoundId = ESM::RefId::stringRefId("Menu Click");
const RefId sBookPageSoundId = ESM::RefId::stringRefId("book page");
const RefId sGoldId001 = ESM::RefId::stringRefId("gold_001");
const RefId sGoldId005 = ESM::RefId::stringRefId("gold_005");
const RefId sGoldId010 = ESM::RefId::stringRefId("gold_010");
const RefId sGoldId025 = ESM::RefId::stringRefId("gold_025");
const RefId sGoldId100 = ESM::RefId::stringRefId("gold_100");
}

View file

@ -0,0 +1,12 @@
#ifndef OPENMW_COMPONENTS_ESM_REFIDHARDCODED_HPP
#define OPENMW_COMPONENTS_ESM_REFIDHARDCODED_HPP
#include "refid.hpp"
namespace ESM
{
extern const RefId sPlayerId, sMenuClickSoundId, sBookPageSoundId;
extern const RefId sGoldId001, sGoldId005, sGoldId010, sGoldId025, sGoldId100;
}
#endif