一份游戏状态(开关/变量/独立变量)。 更多...
#include <GameState.h>
Public 成员函数 | |
| GameState ()=default | |
| Game state. | |
| void | setSwitch (const std::string &name, bool on) |
| 设置开关。 | |
| void | switchOn (const std::string &name) |
| Switch on. | |
| void | switchOff (const std::string &name) |
| Switch off. | |
| bool | isSwitchOn (const std::string &name) const |
| 开关是否打开。 | |
| void | setVariable (const std::string &name, double value) |
| 设置/读取/增减变量。 | |
| double | getVariable (const std::string &name) const |
| Returns the variable. | |
| void | addVariable (const std::string &name, double delta) |
| Adds variable. | |
| void | setSelfVariable (const std::string &scope, const std::string &name, double value) |
| 独立变量:scope(如 "map:1:event:3")下按名字存数字。 | |
| double | getSelfVariable (const std::string &scope, const std::string &name) const |
| Returns the self variable. | |
| bool | hasSelfVariable (const std::string &scope, const std::string &name) const |
| True when self variable. | |
| void | setSelfString (const std::string &scope, const std::string &name, std::string value) |
Scoped string facts (for example a .dnut story cursor JSON blob). | |
| std::string | getSelfString (const std::string &scope, const std::string &name) const |
| Return a scoped string fact, or an empty string when absent. | |
| bool | hasSelfString (const std::string &scope, const std::string &name) const |
| Whether a scoped string fact is present. | |
| void | clearSelfString (const std::string &scope, const std::string &name) |
| Remove one scoped string fact; no-op when absent. | |
| void | clear () |
| 清空全部状态。 | |
| eve::Result< std::string > | snapshotJson () const |
| Serialize this state as the canonical versioned RPG game-state JSON document. | |
| eve::Result< void > | restoreSnapshotJson (std::string_view json) |
| Validate and atomically restore a canonical RPG game-state JSON document. | |
静态 Public 成员函数 | |
| static GameState & | global () |
| 进程级全局单例(脚本便利入口)。 | |
友元 | |
| class | RPGSaveSession |
详细描述
一份游戏状态(开关/变量/独立变量)。
在文件 GameState.h 第 25 行定义.
构造及析构函数说明
◆ GameState()
|
default |
Game state.
成员函数说明
◆ addVariable()
| void eve::rpg::GameState::addVariable | ( | const std::string & | name, |
| double | delta | ||
| ) |
Adds variable.
在文件 GameState.cpp 第 67 行定义.
引用了 getVariable() , 以及 name.
被这些函数引用 eve::rpg::ShopTransaction::buy(), eve::rpg::QuestReward::claim(), eve::rpg::WorldInteraction::collectLoot(), eve::rpg::ShopTransaction::sell() , 以及 eve::rpg::BattleVictory::settle().
◆ clear()
| void eve::rpg::GameState::clear | ( | ) |
清空全部状态。
在文件 GameState.cpp 第 112 行定义.
◆ clearSelfString()
| void eve::rpg::GameState::clearSelfString | ( | const std::string & | scope, |
| const std::string & | name | ||
| ) |
Remove one scoped string fact; no-op when absent.
在文件 GameState.cpp 第 105 行定义.
◆ getSelfString()
| std::string eve::rpg::GameState::getSelfString | ( | const std::string & | scope, |
| const std::string & | name | ||
| ) | const |
Return a scoped string fact, or an empty string when absent.
- 备注
- Absence and an explicitly stored empty string both return
""; callhasSelfStringwhen the distinction matters.
在文件 GameState.cpp 第 92 行定义.
◆ getSelfVariable()
| double eve::rpg::GameState::getSelfVariable | ( | const std::string & | scope, |
| const std::string & | name | ||
| ) | const |
Returns the self variable.
在文件 GameState.cpp 第 75 行定义.
被这些函数引用 eve::rpg::StoryEventSession::advance(), eve::rpg::StoryEventSession::begin() , 以及 eve::rpg::WorldState::isObjectConsumed().
◆ getVariable()
| double eve::rpg::GameState::getVariable | ( | const std::string & | name | ) | const |
Returns the variable.
在文件 GameState.cpp 第 62 行定义.
引用了 name.
被这些函数引用 addVariable(), eve::rpg::QuestReward::claim() , 以及 eve::rpg::WorldInteraction::collectLoot().
◆ global()
|
static |
◆ hasSelfString()
| bool eve::rpg::GameState::hasSelfString | ( | const std::string & | scope, |
| const std::string & | name | ||
| ) | const |
◆ hasSelfVariable()
| bool eve::rpg::GameState::hasSelfVariable | ( | const std::string & | scope, |
| const std::string & | name | ||
| ) | const |
True when self variable.
在文件 GameState.cpp 第 82 行定义.
被这些函数引用 eve::rpg::StoryEventSession::advance(), eve::rpg::StoryEventSession::begin(), eve::rpg::WorldState::isObjectConsumed() , 以及 eve::rpg::RpgStorySession::Impl::persistProgress().
◆ isSwitchOn()
| bool eve::rpg::GameState::isSwitchOn | ( | const std::string & | name | ) | const |
◆ restoreSnapshotJson()
| eve::Result< void > eve::rpg::GameState::restoreSnapshotJson | ( | std::string_view | json | ) |
Validate and atomically restore a canonical RPG game-state JSON document.
- 参数
-
json UTF-8 JSON produced by snapshotJson().
- 返回
- Success after one commit, or a structured parse/schema/version failure.
- 备注
- A failed restore leaves every current value unchanged. Version 1 accepts unknown fields and treats a missing
selfStringsobject as empty, but rejects unknown schema ids and versions. @thread Call on the owning simulation thread. @reentrancy No callbacks are invoked.
在文件 GameState.cpp 第 146 行定义.
引用了 eve::Value::asBool(), eve::Value::asInt(), eve::Value::asString(), eve::Diagnostic::error(), eve::Result< T >::failure(), eve::Value::find(), eve::Value::fromJson(), eve::InvalidArgument, eve::Value::isBool(), eve::Value::isInt64(), eve::Value::isObject(), eve::Value::isString(), key, eve::Value::keys(), eve::ParseError, root, scope, eve::Result< T >::success(), eve::UnknownVersion , 以及 values.
被这些函数引用 eve::rpg::QuestReward::claim(), eve::rpg::WorldInteraction::collectLoot() , 以及 eve::rpg::BattleVictory::settle().
◆ setSelfString()
| void eve::rpg::GameState::setSelfString | ( | const std::string & | scope, |
| const std::string & | name, | ||
| std::string | value | ||
| ) |
Scoped string facts (for example a .dnut story cursor JSON blob).
- 参数
-
scope Owner scope such as story.<id>.name Fact name within the scope. value Owning UTF-8 text; empty is allowed and distinguishable from absence.
- 备注
- Numeric self-variables remain the default for switches/counters. Use strings only when the fact cannot be a finite number (opaque cursor payloads, localization keys stored as facts, etc.). @thread Owning simulation thread only.
在文件 GameState.cpp 第 88 行定义.
◆ setSelfVariable()
| void eve::rpg::GameState::setSelfVariable | ( | const std::string & | scope, |
| const std::string & | name, | ||
| double | value | ||
| ) |
独立变量:scope(如 "map:1:event:3")下按名字存数字。
在文件 GameState.cpp 第 71 行定义.
被这些函数引用 eve::rpg::StoryEventSession::advance(), eve::rpg::StoryEventSession::begin(), eve::rpg::WorldState::consumeObject(), eve::rpg::RpgStorySession::Impl::persistProgress() , 以及 eve::rpg::WorldState::resetObject().
◆ setSwitch()
| void eve::rpg::GameState::setSwitch | ( | const std::string & | name, |
| bool | on | ||
| ) |
◆ setVariable()
| void eve::rpg::GameState::setVariable | ( | const std::string & | name, |
| double | value | ||
| ) |
◆ snapshotJson()
| eve::Result< std::string > eve::rpg::GameState::snapshotJson | ( | ) | const |
Serialize this state as the canonical versioned RPG game-state JSON document.
- 返回
- Owning deterministic JSON, or a structured serialization failure.
- 备注
- Schema
eve.rpg.game-stateversion 1 preserves switches, numeric variables, scoped numeric variables and optional scoped string facts (selfStrings). Unknown fields are reserved and ignored when restoring the same version. @thread Call on the owning simulation thread; no internal synchronization is performed. @reentrancy No callbacks are invoked.
在文件 GameState.cpp 第 119 行定义.
引用了 name, root, scope, eve::Value::toJson(), value , 以及 values.
被这些函数引用 eve::rpg::ShopTransaction::buy(), eve::rpg::QuestReward::claim(), eve::rpg::WorldInteraction::collectLoot(), eve::rpg::ShopTransaction::sell(), eve::rpg::BattleVictory::settle() , 以及 eve::rpg::RPGSaveSession::snapshotJson().
◆ switchOff()
| void eve::rpg::GameState::switchOff | ( | const std::string & | name | ) |
◆ switchOn()
| void eve::rpg::GameState::switchOn | ( | const std::string & | name | ) |
友元及相关函数文档
◆ RPGSaveSession
|
friend |
在文件 GameState.h 第 106 行定义.
该类的文档由以下文件生成:
- src/modules/rpg/GameState.h
- src/modules/rpg/GameState.cpp