smartcmd-MinecraftConsoles/Minecraft.Client/Common/GameRules/LevelRuleset.cpp

72 lines
1.3 KiB
C++
Raw Normal View History

2026-03-01 12:16:08 +08:00
#include "stdafx.h"
#include "../../../Minecraft.World/StringHelpers.h"
#include "../../StringTable.h"
2026-03-01 12:16:08 +08:00
#include "ConsoleGameRules.h"
#include "LevelRuleset.h"
LevelRuleset::LevelRuleset()
{
m_stringTable = nullptr;
2026-03-01 12:16:08 +08:00
}
LevelRuleset::~LevelRuleset()
{
for (auto it = m_areas.begin(); it != m_areas.end(); ++it)
2026-03-01 12:16:08 +08:00
{
delete *it;
}
}
void LevelRuleset::getChildren(vector<GameRuleDefinition *> *children)
{
CompoundGameRuleDefinition::getChildren(children);
for (const auto& area : m_areas)
children->push_back(area);
2026-03-01 12:16:08 +08:00
}
GameRuleDefinition *LevelRuleset::addChild(ConsoleGameRules::EGameRuleType ruleType)
{
GameRuleDefinition *rule = nullptr;
2026-03-01 12:16:08 +08:00
if(ruleType == ConsoleGameRules::eGameRuleType_NamedArea)
{
rule = new NamedAreaRuleDefinition();
m_areas.push_back(static_cast<NamedAreaRuleDefinition *>(rule));
2026-03-01 12:16:08 +08:00
}
else
{
rule = CompoundGameRuleDefinition::addChild(ruleType);
}
return rule;
}
void LevelRuleset::loadStringTable(StringTable *table)
{
m_stringTable = table;
}
LPCWSTR LevelRuleset::getString(const wstring &key)
{
if(m_stringTable == nullptr)
2026-03-01 12:16:08 +08:00
{
return L"";
}
else
{
return m_stringTable->getString(key);
}
}
AABB *LevelRuleset::getNamedArea(const wstring &areaName)
{
AABB *area = nullptr;
for(auto& it : m_areas)
2026-03-01 12:16:08 +08:00
{
if( it->getName().compare(areaName) == 0 )
2026-03-01 12:16:08 +08:00
{
area = it->getArea();
2026-03-01 12:16:08 +08:00
break;
}
}
return area;
}