Changed how the TryParse function works (and also did some general cleanup along the way)

This commit is contained in:
jadebenn
2024-02-02 17:50:30 -06:00
parent d78b50874c
commit 4f75479a4c
34 changed files with 506 additions and 535 deletions

View File

@@ -33,14 +33,12 @@ void AmDropshipComputer::OnUse(Entity* self, Entity* user) {
void AmDropshipComputer::OnDie(Entity* self, Entity* killer) {
const auto myGroup = GeneralUtils::UTF16ToWTF8(self->GetVar<std::u16string>(u"spawner_name"));
int32_t pipeNum = 0;
if (!GeneralUtils::TryParse<int32_t>(myGroup.substr(10, 1), pipeNum)) {
return;
}
const auto pipeNum = GeneralUtils::TryParse<int32_t>(myGroup.substr(10, 1));
if (!pipeNum) return;
const auto pipeGroup = myGroup.substr(0, 10);
const auto nextPipeNum = pipeNum + 1;
const auto nextPipeNum = pipeNum.value() + 1;
const auto samePipeSpawners = Game::zoneManager->GetSpawnersByName(myGroup);
@@ -70,11 +68,9 @@ void AmDropshipComputer::OnDie(Entity* self, Entity* killer) {
}
void AmDropshipComputer::OnTimerDone(Entity* self, std::string timerName) {
auto* quickBuildComponent = self->GetComponent<QuickBuildComponent>();
const auto* const quickBuildComponent = self->GetComponent<QuickBuildComponent>();
if (quickBuildComponent == nullptr) {
return;
}
if (!quickBuildComponent) return;
if (timerName == "reset" && quickBuildComponent->GetState() == eQuickBuildState::OPEN) {
self->Smash(self->GetObjectID(), eKillType::SILENT);

View File

@@ -144,13 +144,10 @@ void AmSkullkinTower::OnChildRemoved(Entity* self, Entity* child) {
);
for (const auto& mission : missions) {
int32_t missionID = 0;
const auto missionID = GeneralUtils::TryParse<LOT>(mission);
if (!missionID) continue;
if (!GeneralUtils::TryParse(mission, missionID)) {
continue;
}
missionIDs.push_back(missionID);
missionIDs.push_back(missionID.value());
}
}

View File

@@ -12,12 +12,9 @@ void AmTemplateSkillVolume::OnSkillEventFired(Entity* self, Entity* caster, cons
const auto missionIDs = GeneralUtils::SplitString(missionIDsVariable, '_');
for (const auto& missionIDStr : missionIDs) {
int32_t missionID = 0;
const auto missionID = GeneralUtils::TryParse<uint32_t>(missionIDStr);
if (!missionID) continue;
if (!GeneralUtils::TryParse(missionIDStr, missionID)) {
continue;
}
missionComponent->ForceProgressTaskType(missionID, 1, 1, false);
missionComponent->ForceProgressTaskType(missionID.value(), 1, 1, false);
}
}

View File

@@ -41,11 +41,9 @@ void ChooseYourDestinationNsToNt::SetDestination(Entity* self, Entity* player) {
void ChooseYourDestinationNsToNt::BaseChoiceBoxRespond(Entity* self, Entity* sender, int32_t button, const std::u16string& buttonIdentifier, const std::u16string& identifier) {
if (button != -1) {
const auto newMapStr = GeneralUtils::UTF16ToWTF8(buttonIdentifier).substr(7, -1);
int32_t newMap = 0;
if (!GeneralUtils::TryParse(newMapStr, newMap)) {
return;
}
const auto newMap = GeneralUtils::TryParse<int32_t>(newMapStr);
if (!newMap) return;
std::u16string strText = u"";
@@ -56,7 +54,7 @@ void ChooseYourDestinationNsToNt::BaseChoiceBoxRespond(Entity* self, Entity* sen
}
self->SetVar(u"teleportString", strText);
self->SetVar(u"transferZoneID", GeneralUtils::to_u16string(newMap));
self->SetVar(u"transferZoneID", GeneralUtils::to_u16string(newMap.value()));
GameMessages::SendDisplayMessageBox(sender->GetObjectID(), true, self->GetObjectID(), u"TransferBox", 0, strText, u"", sender->GetSystemAddress());
} else {

View File

@@ -7,10 +7,8 @@
void FvBrickPuzzleServer::OnStartup(Entity* self) {
const auto myGroup = GeneralUtils::UTF16ToWTF8(self->GetVar<std::u16string>(u"spawner_name"));
int32_t pipeNum = 0;
if (!GeneralUtils::TryParse<int32_t>(myGroup.substr(10, 1), pipeNum)) {
return;
}
const auto pipeNum = GeneralUtils::TryParse<int32_t>(myGroup.substr(10, 1));
if (!pipeNum) return;
if (pipeNum != 1) {
self->AddTimer("reset", 30);
@@ -20,14 +18,12 @@ void FvBrickPuzzleServer::OnStartup(Entity* self) {
void FvBrickPuzzleServer::OnDie(Entity* self, Entity* killer) {
const auto myGroup = GeneralUtils::UTF16ToWTF8(self->GetVar<std::u16string>(u"spawner_name"));
int32_t pipeNum = 0;
if (!GeneralUtils::TryParse<int32_t>(myGroup.substr(10, 1), pipeNum)) {
return;
}
const auto pipeNum = GeneralUtils::TryParse<int32_t>(myGroup.substr(10, 1));
if (!pipeNum) return;
const auto pipeGroup = myGroup.substr(0, 10);
const auto nextPipeNum = pipeNum + 1;
const auto nextPipeNum = pipeNum.value() + 1;
const auto samePipeSpawners = Game::zoneManager->GetSpawnersByName(myGroup);
@@ -37,7 +33,7 @@ void FvBrickPuzzleServer::OnDie(Entity* self, Entity* killer) {
samePipeSpawners[0]->Deactivate();
}
if (killer != nullptr && killer->IsPlayer()) {
if (killer && killer->IsPlayer()) {
const auto nextPipe = pipeGroup + std::to_string(nextPipeNum);
const auto nextPipeSpawners = Game::zoneManager->GetSpawnersByName(nextPipe);