1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-04-01 05:06:41 +00:00

Move control switch reading/writing to relevant class

This commit is contained in:
Andrei Kortunov 2020-04-24 12:43:17 +04:00
parent b4e52a6bc8
commit 73552f1d3c
3 changed files with 61 additions and 24 deletions

View file

@ -1,5 +1,11 @@
#include "controlswitch.hpp"
#include <components/esm/esmwriter.hpp>
#include <components/esm/esmreader.hpp>
#include <components/esm/controlsstate.hpp>
#include <components/loadinglistener/loadinglistener.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
@ -55,4 +61,39 @@ namespace MWInput
}
mSwitches[key] = value;
}
void ControlSwitch::write(ESM::ESMWriter& writer, Loading::Listener& /*progress*/)
{
ESM::ControlsState controls;
controls.mViewSwitchDisabled = !mSwitches["playerviewswitch"];
controls.mControlsDisabled = !mSwitches["playercontrols"];
controls.mJumpingDisabled = !mSwitches["playerjumping"];
controls.mLookingDisabled = !mSwitches["playerlooking"];
controls.mVanityModeDisabled = !mSwitches["vanitymode"];
controls.mWeaponDrawingDisabled = !mSwitches["playerfighting"];
controls.mSpellDrawingDisabled = !mSwitches["playermagic"];
writer.startRecord (ESM::REC_INPU);
controls.save(writer);
writer.endRecord (ESM::REC_INPU);
}
void ControlSwitch::readRecord(ESM::ESMReader& reader, uint32_t type)
{
ESM::ControlsState controls;
controls.load(reader);
set("playerviewswitch", !controls.mViewSwitchDisabled);
set("playercontrols", !controls.mControlsDisabled);
set("playerjumping", !controls.mJumpingDisabled);
set("playerlooking", !controls.mLookingDisabled);
set("vanitymode", !controls.mVanityModeDisabled);
set("playerfighting", !controls.mWeaponDrawingDisabled);
set("playermagic", !controls.mSpellDrawingDisabled);
}
int ControlSwitch::countSavedGameRecords() const
{
return 1;
}
}

View file

@ -3,6 +3,18 @@
#include <map>
namespace ESM
{
struct ControlsState;
class ESMReader;
class ESMWriter;
}
namespace Loading
{
class Listener;
}
namespace MWInput
{
class ControlSwitch
@ -14,6 +26,10 @@ namespace MWInput
void set(const std::string& key, bool value);
void clear();
void write(ESM::ESMWriter& writer, Loading::Listener& progress);
void readRecord(ESM::ESMReader& reader, uint32_t type);
int countSavedGameRecords() const;
private:
std::map<std::string, bool> mSwitches;
};

View file

@ -208,39 +208,19 @@ namespace MWInput
int InputManager::countSavedGameRecords() const
{
return 1;
return mControlSwitch->countSavedGameRecords();
}
void InputManager::write(ESM::ESMWriter& writer, Loading::Listener& /*progress*/)
void InputManager::write(ESM::ESMWriter& writer, Loading::Listener& progress)
{
ESM::ControlsState controls;
controls.mViewSwitchDisabled = !getControlSwitch("playerviewswitch");
controls.mControlsDisabled = !getControlSwitch("playercontrols");
controls.mJumpingDisabled = !getControlSwitch("playerjumping");
controls.mLookingDisabled = !getControlSwitch("playerlooking");
controls.mVanityModeDisabled = !getControlSwitch("vanitymode");
controls.mWeaponDrawingDisabled = !getControlSwitch("playerfighting");
controls.mSpellDrawingDisabled = !getControlSwitch("playermagic");
writer.startRecord (ESM::REC_INPU);
controls.save(writer);
writer.endRecord (ESM::REC_INPU);
mControlSwitch->write(writer, progress);
}
void InputManager::readRecord(ESM::ESMReader& reader, uint32_t type)
{
if (type == ESM::REC_INPU)
{
ESM::ControlsState controls;
controls.load(reader);
toggleControlSwitch("playerviewswitch", !controls.mViewSwitchDisabled);
toggleControlSwitch("playercontrols", !controls.mControlsDisabled);
toggleControlSwitch("playerjumping", !controls.mJumpingDisabled);
toggleControlSwitch("playerlooking", !controls.mLookingDisabled);
toggleControlSwitch("vanitymode", !controls.mVanityModeDisabled);
toggleControlSwitch("playerfighting", !controls.mWeaponDrawingDisabled);
toggleControlSwitch("playermagic", !controls.mSpellDrawingDisabled);
mControlSwitch->readRecord(reader, type);
}
}