mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-04 19:19:40 +00:00
[Client] Allow ClientScriptGlobal to create new global variables
This commit is contained in:
parent
0eb01591e8
commit
eefa94db12
6 changed files with 123 additions and 2 deletions
|
@ -10,6 +10,16 @@
|
||||||
|
|
||||||
#include <components/esm/cellid.hpp>
|
#include <components/esm/cellid.hpp>
|
||||||
|
|
||||||
|
/*
|
||||||
|
Start of tes3mp addition
|
||||||
|
|
||||||
|
Include additional headers for multiplayer purposes
|
||||||
|
*/
|
||||||
|
#include <components/esm/variant.hpp>
|
||||||
|
/*
|
||||||
|
End of tes3mp addition
|
||||||
|
*/
|
||||||
|
|
||||||
#include <osg/Timer>
|
#include <osg/Timer>
|
||||||
|
|
||||||
#include "../mwworld/ptr.hpp"
|
#include "../mwworld/ptr.hpp"
|
||||||
|
@ -175,6 +185,19 @@ namespace MWBase
|
||||||
virtual void getDoorMarkers (MWWorld::CellStore* cell, std::vector<DoorMarker>& out) = 0;
|
virtual void getDoorMarkers (MWWorld::CellStore* cell, std::vector<DoorMarker>& out) = 0;
|
||||||
///< get a list of teleport door markers for a given cell, to be displayed on the local map
|
///< get a list of teleport door markers for a given cell, to be displayed on the local map
|
||||||
|
|
||||||
|
/*
|
||||||
|
Start of tes3mp addition
|
||||||
|
|
||||||
|
Make it possible to check whether global variables exist and to create
|
||||||
|
new ones
|
||||||
|
*/
|
||||||
|
virtual bool hasGlobal(const std::string& name) = 0;
|
||||||
|
|
||||||
|
virtual void createGlobal(const std::string& name, ESM::VarType varType) = 0;
|
||||||
|
/*
|
||||||
|
End of tes3mp addition
|
||||||
|
*/
|
||||||
|
|
||||||
virtual void setGlobalInt (const std::string& name, int value) = 0;
|
virtual void setGlobalInt (const std::string& name, int value) = 0;
|
||||||
///< Set value independently from real type.
|
///< Set value independently from real type.
|
||||||
|
|
||||||
|
|
|
@ -381,10 +381,27 @@ void Worldstate::setClientGlobals()
|
||||||
debugMessage += clientGlobal.id + ": " + variableTypeAsString + " " + valueAsString;
|
debugMessage += clientGlobal.id + ": " + variableTypeAsString + " " + valueAsString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MWBase::World* world = MWBase::Environment::get().getWorld();
|
||||||
|
|
||||||
|
// If this global doesn't exist, create it
|
||||||
|
if (!world->hasGlobal(clientGlobal.id))
|
||||||
|
{
|
||||||
|
ESM::VarType varType;
|
||||||
|
|
||||||
|
if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::SHORT)
|
||||||
|
varType = ESM::VarType::VT_Short;
|
||||||
|
else if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::LONG)
|
||||||
|
varType = ESM::VarType::VT_Long;
|
||||||
|
if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::FLOAT)
|
||||||
|
varType = ESM::VarType::VT_Float;
|
||||||
|
|
||||||
|
world->createGlobal(clientGlobal.id, varType);
|
||||||
|
}
|
||||||
|
|
||||||
if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::SHORT || clientGlobal.variableType == mwmp::VARIABLE_TYPE::LONG)
|
if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::SHORT || clientGlobal.variableType == mwmp::VARIABLE_TYPE::LONG)
|
||||||
MWBase::Environment::get().getWorld()->setGlobalInt(clientGlobal.id, clientGlobal.intValue);
|
world->setGlobalInt(clientGlobal.id, clientGlobal.intValue);
|
||||||
else if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::FLOAT)
|
else if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::FLOAT)
|
||||||
MWBase::Environment::get().getWorld()->setGlobalFloat(clientGlobal.id, clientGlobal.floatValue);
|
world->setGlobalFloat(clientGlobal.id, clientGlobal.floatValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_APPEND(TimedLog::LOG_INFO, "- %s", debugMessage.c_str());
|
LOG_APPEND(TimedLog::LOG_INFO, "- %s", debugMessage.c_str());
|
||||||
|
|
|
@ -105,4 +105,30 @@ namespace MWWorld
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Start of tes3mp addition
|
||||||
|
|
||||||
|
Make it possible to add a global record from elsewhere
|
||||||
|
*/
|
||||||
|
void Globals::addRecord(const ESM::Global global)
|
||||||
|
{
|
||||||
|
mVariables.insert(std::make_pair(Misc::StringUtils::lowerCase(global.mId), global));
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
End of tes3mp addition
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Start of tes3mp addition
|
||||||
|
|
||||||
|
Make it possible to check whether a global exists
|
||||||
|
*/
|
||||||
|
bool Globals::hasRecord(const std::string& name)
|
||||||
|
{
|
||||||
|
return (mVariables.find(name) != mVariables.end());
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
End of tes3mp addition
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,26 @@ namespace MWWorld
|
||||||
///
|
///
|
||||||
/// \return Known type?
|
/// \return Known type?
|
||||||
|
|
||||||
|
/*
|
||||||
|
Start of tes3mp addition
|
||||||
|
|
||||||
|
Make it possible to add a global record from elsewhere
|
||||||
|
*/
|
||||||
|
void addRecord(const ESM::Global global);
|
||||||
|
/*
|
||||||
|
End of tes3mp addition
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Start of tes3mp addition
|
||||||
|
|
||||||
|
Make it possible to check whether a global exists
|
||||||
|
*/
|
||||||
|
bool hasRecord(const std::string& name);
|
||||||
|
/*
|
||||||
|
End of tes3mp addition
|
||||||
|
*/
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -658,6 +658,28 @@ namespace MWWorld
|
||||||
return mWorldScene->hasCellChanged();
|
return mWorldScene->hasCellChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Start of tes3mp addition
|
||||||
|
|
||||||
|
Make it possible to check whether global variables exist and to create
|
||||||
|
new ones
|
||||||
|
*/
|
||||||
|
bool World::hasGlobal(const std::string& name)
|
||||||
|
{
|
||||||
|
return mGlobalVariables.hasRecord(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void World::createGlobal(const std::string& name, ESM::VarType varType)
|
||||||
|
{
|
||||||
|
ESM::Global global;
|
||||||
|
global.mId = name;
|
||||||
|
global.mValue.setType(varType);
|
||||||
|
mGlobalVariables.addRecord(global);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
End of tes3mp addition
|
||||||
|
*/
|
||||||
|
|
||||||
void World::setGlobalInt (const std::string& name, int value)
|
void World::setGlobalInt (const std::string& name, int value)
|
||||||
{
|
{
|
||||||
bool dateUpdated = mCurrentDate->updateGlobalInt(name, value);
|
bool dateUpdated = mCurrentDate->updateGlobalInt(name, value);
|
||||||
|
|
|
@ -281,6 +281,19 @@ namespace MWWorld
|
||||||
void getDoorMarkers (MWWorld::CellStore* cell, std::vector<DoorMarker>& out) override;
|
void getDoorMarkers (MWWorld::CellStore* cell, std::vector<DoorMarker>& out) override;
|
||||||
///< get a list of teleport door markers for a given cell, to be displayed on the local map
|
///< get a list of teleport door markers for a given cell, to be displayed on the local map
|
||||||
|
|
||||||
|
/*
|
||||||
|
Start of tes3mp addition
|
||||||
|
|
||||||
|
Make it possible to check whether global variables exist and to create
|
||||||
|
new ones
|
||||||
|
*/
|
||||||
|
bool hasGlobal(const std::string& name);
|
||||||
|
|
||||||
|
void createGlobal(const std::string& name, ESM::VarType varType);
|
||||||
|
/*
|
||||||
|
End of tes3mp addition
|
||||||
|
*/
|
||||||
|
|
||||||
void setGlobalInt (const std::string& name, int value) override;
|
void setGlobalInt (const std::string& name, int value) override;
|
||||||
///< Set value independently from real type.
|
///< Set value independently from real type.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue