mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-06-16 12:11:56 +00:00
format .Client/Common/GameRules
This commit is contained in:
@@ -3,149 +3,149 @@
|
||||
#include "../../Minecraft.World/Util/StringHelpers.h"
|
||||
#include "ConsoleGameRules.h"
|
||||
|
||||
GameRuleDefinition::GameRuleDefinition()
|
||||
{
|
||||
m_descriptionId = L"";
|
||||
m_promptId = L"";
|
||||
m_4JDataValue = 0;
|
||||
GameRuleDefinition::GameRuleDefinition() {
|
||||
m_descriptionId = L"";
|
||||
m_promptId = L"";
|
||||
m_4JDataValue = 0;
|
||||
}
|
||||
|
||||
void GameRuleDefinition::write(DataOutputStream *dos)
|
||||
{
|
||||
// Write EGameRuleType.
|
||||
ConsoleGameRules::EGameRuleType eType = getActionType();
|
||||
assert( eType != ConsoleGameRules::eGameRuleType_Invalid );
|
||||
ConsoleGameRules::write(dos, eType); // stringID
|
||||
void GameRuleDefinition::write(DataOutputStream* dos) {
|
||||
// Write EGameRuleType.
|
||||
ConsoleGameRules::EGameRuleType eType = getActionType();
|
||||
assert(eType != ConsoleGameRules::eGameRuleType_Invalid);
|
||||
ConsoleGameRules::write(dos, eType); // stringID
|
||||
|
||||
writeAttributes(dos, 0);
|
||||
|
||||
// 4J-JEV: Get children.
|
||||
std::vector<GameRuleDefinition *> *children = new std::vector<GameRuleDefinition *>();
|
||||
getChildren( children );
|
||||
writeAttributes(dos, 0);
|
||||
|
||||
// Write children.
|
||||
dos->writeInt( children->size() );
|
||||
for (AUTO_VAR(it, children->begin()); it != children->end(); it++)
|
||||
(*it)->write(dos);
|
||||
// 4J-JEV: Get children.
|
||||
std::vector<GameRuleDefinition*>* children =
|
||||
new std::vector<GameRuleDefinition*>();
|
||||
getChildren(children);
|
||||
|
||||
// Write children.
|
||||
dos->writeInt(children->size());
|
||||
for (AUTO_VAR(it, children->begin()); it != children->end(); it++)
|
||||
(*it)->write(dos);
|
||||
}
|
||||
|
||||
void GameRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttributes)
|
||||
{
|
||||
dos->writeInt(numAttributes + 3);
|
||||
void GameRuleDefinition::writeAttributes(DataOutputStream* dos,
|
||||
unsigned int numAttributes) {
|
||||
dos->writeInt(numAttributes + 3);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_descriptionName);
|
||||
dos->writeUTF(m_descriptionId);
|
||||
ConsoleGameRules::write(dos,
|
||||
ConsoleGameRules::eGameRuleAttr_descriptionName);
|
||||
dos->writeUTF(m_descriptionId);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_promptName);
|
||||
dos->writeUTF(m_promptId);
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_promptName);
|
||||
dos->writeUTF(m_promptId);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_dataTag);
|
||||
dos->writeUTF(_toString(m_4JDataValue));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_dataTag);
|
||||
dos->writeUTF(_toString(m_4JDataValue));
|
||||
}
|
||||
|
||||
void GameRuleDefinition::getChildren(std::vector<GameRuleDefinition *> *children) {}
|
||||
void GameRuleDefinition::getChildren(
|
||||
std::vector<GameRuleDefinition*>* children) {}
|
||||
|
||||
GameRuleDefinition *GameRuleDefinition::addChild(ConsoleGameRules::EGameRuleType ruleType)
|
||||
{
|
||||
GameRuleDefinition* GameRuleDefinition::addChild(
|
||||
ConsoleGameRules::EGameRuleType ruleType) {
|
||||
#ifndef _CONTENT_PACKAGE
|
||||
wprintf(L"GameRuleDefinition: Attempted to add invalid child rule - %d\n", ruleType );
|
||||
wprintf(L"GameRuleDefinition: Attempted to add invalid child rule - %d\n",
|
||||
ruleType);
|
||||
#endif
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void GameRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue)
|
||||
{
|
||||
if(attributeName.compare(L"descriptionName") == 0)
|
||||
{
|
||||
m_descriptionId = attributeValue;
|
||||
void GameRuleDefinition::addAttribute(const std::wstring& attributeName,
|
||||
const std::wstring& attributeValue) {
|
||||
if (attributeName.compare(L"descriptionName") == 0) {
|
||||
m_descriptionId = attributeValue;
|
||||
#ifndef _CONTENT_PACKAGE
|
||||
wprintf(L"GameRuleDefinition: Adding parameter descriptionId=%ls\n",m_descriptionId.c_str());
|
||||
wprintf(L"GameRuleDefinition: Adding parameter descriptionId=%ls\n",
|
||||
m_descriptionId.c_str());
|
||||
#endif
|
||||
}
|
||||
else if(attributeName.compare(L"promptName") == 0)
|
||||
{
|
||||
m_promptId = attributeValue;
|
||||
} else if (attributeName.compare(L"promptName") == 0) {
|
||||
m_promptId = attributeValue;
|
||||
#ifndef _CONTENT_PACKAGE
|
||||
wprintf(L"GameRuleDefinition: Adding parameter m_promptId=%ls\n",m_promptId.c_str());
|
||||
wprintf(L"GameRuleDefinition: Adding parameter m_promptId=%ls\n",
|
||||
m_promptId.c_str());
|
||||
#endif
|
||||
}
|
||||
else if(attributeName.compare(L"dataTag") == 0)
|
||||
{
|
||||
m_4JDataValue = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("GameRuleDefinition: Adding parameter m_4JDataValue=%d\n",m_4JDataValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else if (attributeName.compare(L"dataTag") == 0) {
|
||||
m_4JDataValue = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf(
|
||||
"GameRuleDefinition: Adding parameter m_4JDataValue=%d\n",
|
||||
m_4JDataValue);
|
||||
} else {
|
||||
#ifndef _CONTENT_PACKAGE
|
||||
wprintf(L"GameRuleDefinition: Attempted to add invalid attribute: %ls\n", attributeName.c_str());
|
||||
wprintf(
|
||||
L"GameRuleDefinition: Attempted to add invalid attribute: %ls\n",
|
||||
attributeName.c_str());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GameRuleDefinition::populateGameRule(GameRulesInstance::EGameRulesInstanceType type, GameRule *rule)
|
||||
{
|
||||
GameRule::ValueType value;
|
||||
value.b = false;
|
||||
rule->setParameter(L"bComplete",value);
|
||||
void GameRuleDefinition::populateGameRule(
|
||||
GameRulesInstance::EGameRulesInstanceType type, GameRule* rule) {
|
||||
GameRule::ValueType value;
|
||||
value.b = false;
|
||||
rule->setParameter(L"bComplete", value);
|
||||
}
|
||||
|
||||
bool GameRuleDefinition::getComplete(GameRule *rule)
|
||||
{
|
||||
GameRule::ValueType value;
|
||||
value = rule->getParameter(L"bComplete");
|
||||
return value.b;
|
||||
bool GameRuleDefinition::getComplete(GameRule* rule) {
|
||||
GameRule::ValueType value;
|
||||
value = rule->getParameter(L"bComplete");
|
||||
return value.b;
|
||||
}
|
||||
|
||||
void GameRuleDefinition::setComplete(GameRule *rule, bool val)
|
||||
{
|
||||
GameRule::ValueType value;
|
||||
value = rule->getParameter(L"bComplete");
|
||||
value.b = val;
|
||||
rule->setParameter(L"bComplete",value);
|
||||
void GameRuleDefinition::setComplete(GameRule* rule, bool val) {
|
||||
GameRule::ValueType value;
|
||||
value = rule->getParameter(L"bComplete");
|
||||
value.b = val;
|
||||
rule->setParameter(L"bComplete", value);
|
||||
}
|
||||
|
||||
std::vector<GameRuleDefinition *> *GameRuleDefinition::enumerate()
|
||||
{
|
||||
// Get Vector.
|
||||
std::vector<GameRuleDefinition *> *gRules;
|
||||
gRules = new std::vector<GameRuleDefinition *>();
|
||||
gRules->push_back(this);
|
||||
getChildren(gRules);
|
||||
return gRules;
|
||||
std::vector<GameRuleDefinition*>* GameRuleDefinition::enumerate() {
|
||||
// Get Vector.
|
||||
std::vector<GameRuleDefinition*>* gRules;
|
||||
gRules = new std::vector<GameRuleDefinition*>();
|
||||
gRules->push_back(this);
|
||||
getChildren(gRules);
|
||||
return gRules;
|
||||
}
|
||||
|
||||
std::unordered_map<GameRuleDefinition *, int> *GameRuleDefinition::enumerateMap()
|
||||
{
|
||||
std::unordered_map<GameRuleDefinition *, int> *out
|
||||
= new std::unordered_map<GameRuleDefinition *, int>();
|
||||
std::unordered_map<GameRuleDefinition*, int>*
|
||||
GameRuleDefinition::enumerateMap() {
|
||||
std::unordered_map<GameRuleDefinition*, int>* out =
|
||||
new std::unordered_map<GameRuleDefinition*, int>();
|
||||
|
||||
int i = 0;
|
||||
std::vector<GameRuleDefinition *> *gRules = enumerate();
|
||||
for (AUTO_VAR(it, gRules->begin()); it != gRules->end(); it++)
|
||||
out->insert( std::pair<GameRuleDefinition *, int>( *it, i++ ) );
|
||||
int i = 0;
|
||||
std::vector<GameRuleDefinition*>* gRules = enumerate();
|
||||
for (AUTO_VAR(it, gRules->begin()); it != gRules->end(); it++)
|
||||
out->insert(std::pair<GameRuleDefinition*, int>(*it, i++));
|
||||
|
||||
return out;
|
||||
return out;
|
||||
}
|
||||
|
||||
GameRulesInstance *GameRuleDefinition::generateNewGameRulesInstance(GameRulesInstance::EGameRulesInstanceType type, LevelRuleset *rules, Connection *connection)
|
||||
{
|
||||
GameRulesInstance *manager = new GameRulesInstance(rules, connection);
|
||||
GameRulesInstance* GameRuleDefinition::generateNewGameRulesInstance(
|
||||
GameRulesInstance::EGameRulesInstanceType type, LevelRuleset* rules,
|
||||
Connection* connection) {
|
||||
GameRulesInstance* manager = new GameRulesInstance(rules, connection);
|
||||
|
||||
rules->populateGameRule(type, manager);
|
||||
rules->populateGameRule(type, manager);
|
||||
|
||||
return manager;
|
||||
return manager;
|
||||
}
|
||||
|
||||
std::wstring GameRuleDefinition::generateDescriptionString(ConsoleGameRules::EGameRuleType defType, const std::wstring &description, void *data, int dataLength)
|
||||
{
|
||||
std::wstring formatted = description;
|
||||
switch(defType)
|
||||
{
|
||||
case ConsoleGameRules::eGameRuleType_CompleteAllRule:
|
||||
formatted = CompleteAllRuleDefinition::generateDescriptionString(description,data,dataLength);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
return formatted;
|
||||
std::wstring GameRuleDefinition::generateDescriptionString(
|
||||
ConsoleGameRules::EGameRuleType defType, const std::wstring& description,
|
||||
void* data, int dataLength) {
|
||||
std::wstring formatted = description;
|
||||
switch (defType) {
|
||||
case ConsoleGameRules::eGameRuleType_CompleteAllRule:
|
||||
formatted = CompleteAllRuleDefinition::generateDescriptionString(
|
||||
description, data, dataLength);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
return formatted;
|
||||
}
|
||||
Reference in New Issue
Block a user