Skip to content

Commit

Permalink
treewide: Change formatting rules
Browse files Browse the repository at this point in the history
Allow & enforce braceless if, for and while statements
  • Loading branch information
pongo1231 committed Jan 15, 2025
1 parent c7661a4 commit 9cdae15
Show file tree
Hide file tree
Showing 252 changed files with 24 additions and 2,114 deletions.
4 changes: 3 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,6 @@ csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_inlined_variable_declaration = true:none
csharp_style_throw_expression = true:none
csharp_style_conditional_delegate_call = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion

csharp_prefer_braces = false
1 change: 1 addition & 0 deletions ChaosMod/.clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ PenaltyReturnTypeOnItsOwnLine: 60
PenaltyIndentedWhitespace: 0
PointerAlignment: Right
ReflowComments: true
RemoveBracesLLVM: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
Expand Down
30 changes: 0 additions & 30 deletions ChaosMod/Components/DebugMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ DebugMenu::DebugMenu() : Component()
{
m_IsEnabled = g_OptionsManager.GetConfigValue({ "EnableDebugMenu" }, OPTION_DEFAULT_DEBUG_MENU);
if (!m_IsEnabled)
{
return;
}

for (const auto &pair : g_EnabledEffects)
{
Expand All @@ -38,27 +36,19 @@ DebugMenu::DebugMenu() : Component()
[](const DebugEffect &a, const DebugEffect &b)
{
for (int idx = 0;; idx++)
{
if (idx >= a.EffectName.size()
|| std::toupper(a.EffectName[idx]) < std::toupper(b.EffectName[idx]))
{
return true;
}
else if (idx >= b.EffectName.size()
|| std::toupper(b.EffectName[idx]) < std::toupper(a.EffectName[idx]))
{
return false;
}
}
});
}

void DebugMenu::OnRun()
{
if (!m_IsEnabled || !m_Visible)
{
return;
}

// Arrow Up
DISABLE_CONTROL_ACTION(1, 27, true);
Expand Down Expand Up @@ -88,9 +78,7 @@ void DebugMenu::OnRun()
m_DispatchEffect = false;

if (ComponentExists<EffectDispatcher>())
{
GetComponent<EffectDispatcher>()->DispatchEffect(m_Effects[m_SelectedIdx].Identifier);
}
}

float y = .1f;
Expand All @@ -101,13 +89,9 @@ void DebugMenu::OnRun()
short overflow = MAX_VIS_ITEMS / 2 - (m_Effects.size() - 1 - m_SelectedIdx);

if (i < 0 || i < m_SelectedIdx - remainingDrawItems / 2 - (overflow > 0 ? overflow : 0))
{
continue;
}
else if (i >= m_Effects.size())
{
break;
}

BEGIN_TEXT_COMMAND_DISPLAY_TEXT("STRING");
ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME(m_Effects[i].EffectName.c_str());
Expand Down Expand Up @@ -145,18 +129,14 @@ void DebugMenu::OnKeyInput(DWORD key, bool repeated, bool isUpNow, bool isCtrlPr
bool isAltPressed)
{
if (!m_IsEnabled || !m_Visible)
{
return;
}

if (repeated)
{
auto curTime = GetTickCount64();

if (key == VK_RETURN || m_RepeatTime > curTime - 250)
{
return;
}
}
else
{
Expand All @@ -167,16 +147,12 @@ void DebugMenu::OnKeyInput(DWORD key, bool repeated, bool isUpNow, bool isCtrlPr
{
case VK_UP:
if (--m_SelectedIdx < 0)
{
m_SelectedIdx = m_Effects.size() - 1;
}

break;
case VK_DOWN:
if (++m_SelectedIdx >= m_Effects.size())
{
m_SelectedIdx = 0;
}

break;
case VK_RIGHT:
Expand All @@ -187,9 +163,7 @@ void DebugMenu::OnKeyInput(DWORD key, bool repeated, bool isUpNow, bool isCtrlPr
while (!found)
{
if (searchChar++ == SCHAR_MAX)
{
searchChar = SCHAR_MIN;
}

for (int idx = 0; idx < m_Effects.size(); idx++)
{
Expand All @@ -214,9 +188,7 @@ void DebugMenu::OnKeyInput(DWORD key, bool repeated, bool isUpNow, bool isCtrlPr
while (!found)
{
if (searchChar-- == SCHAR_MIN)
{
searchChar = SCHAR_MAX;
}

for (int idx = 0; idx < m_Effects.size(); idx++)
{
Expand All @@ -235,9 +207,7 @@ void DebugMenu::OnKeyInput(DWORD key, bool repeated, bool isUpNow, bool isCtrlPr
}
case VK_RETURN:
if (!m_Effects[m_SelectedIdx].Identifier.GetEffectId().empty())
{
m_DispatchEffect = true;
}

break;
case VK_BACK:
Expand Down
40 changes: 0 additions & 40 deletions ChaosMod/Components/DebugSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ static void OnFetchEffects(DebugSocket *debugSocket, std::shared_ptr<ix::Connect
for (const auto &[effectId, effectData] : g_EnabledEffects)
{
if (effectData.TimedType == EffectTimedType::Permanent || effectData.IsHidden())
{
continue;
}

json effectInfoJson;
effectInfoJson["id"] = effectId.GetEffectId();
Expand All @@ -50,58 +48,42 @@ static void OnTriggerEffect(DebugSocket *debugSocket, std::shared_ptr<ix::Connec
ix::WebSocket &webSocket, const json &payloadJson)
{
if (!ComponentExists<EffectDispatcher>())
{
return;
}

if (!payloadJson.contains("effect_id") || !payloadJson["effect_id"].is_string())
{
return;
}

auto targetEffectId = payloadJson["effect_id"].get<std::string>();
if (targetEffectId.empty())
{
return;
}

QueueDelegate(debugSocket,
[targetEffectId]()
{
auto result = g_EnabledEffects.find(targetEffectId);
if (result != g_EnabledEffects.end())
{
GetComponent<EffectDispatcher>()->DispatchEffect(result->first);
}
});
}

static void OnExecScript(DebugSocket *debugSocket, std::shared_ptr<ix::ConnectionState> connectionState,
ix::WebSocket &webSocket, const json &payloadJson)
{
if (!ComponentExists<EffectDispatcher>())
{
return;
}

if (!payloadJson.contains("script_raw") || !payloadJson["script_raw"].is_string())
{
return;
}

auto script = payloadJson["script_raw"].get<std::string>();
if (script.empty())
{
return;
}

// Generate random hex value for script name
std::string scriptName;
scriptName.resize(8);
for (int i = 0; i < 8; i++)
{
sprintf(scriptName.data() + i, "%x", g_RandomNoDeterm.GetRandomInt(0, 16));
}

json json;
json["command"] = "result_exec_script";
Expand All @@ -112,19 +94,15 @@ static void OnExecScript(DebugSocket *debugSocket, std::shared_ptr<ix::Connectio
[payloadJson, scriptName]()
{
if (ComponentExists<LuaScripts>())
{
GetComponent<LuaScripts>()->RegisterScriptRawTemporary(scriptName, payloadJson["script_raw"]);
}
});
}

static void OnSetProfileState(DebugSocket *debugSocket, std::shared_ptr<ix::ConnectionState> connectionState,
ix::WebSocket &webSocket, const json &payloadJson)
{
if (!payloadJson.contains("state") || !payloadJson["state"].is_string())
{
return;
}

const auto &state = payloadJson["state"];
if (state == "start")
Expand Down Expand Up @@ -161,18 +139,14 @@ static void OnSetProfileState(DebugSocket *debugSocket, std::shared_ptr<ix::Conn
for (const auto &[effectId, traceStats] : debugSocket->m_EffectTraceStats)
{
if (traceStats.TotalExecTime == 0)
{
continue;
}

json profileJson;
profileJson["total_exec_time"] = traceStats.TotalExecTime;
profileJson["max_exec_time"] = traceStats.MaxExecTime;

for (const auto &execTrace : traceStats.ExecTraces)
{
profileJson["exec_times"].push_back(execTrace.ExecTime);
}

resultJson["profiles"][effectId] = profileJson;
}
Expand All @@ -187,9 +161,7 @@ static void OnMessage(DebugSocket *debugSocket, std::shared_ptr<ix::ConnectionSt
ix::WebSocket &webSocket, const ix::WebSocketMessagePtr &msg)
{
if (msg->type != ix::WebSocketMessageType::Message)
{
return;
}

auto payload = msg->str;

Expand All @@ -205,9 +177,7 @@ static void OnMessage(DebugSocket *debugSocket, std::shared_ptr<ix::ConnectionSt
}

if (!payloadJson.contains("command"))
{
return;
}

auto command = payloadJson["command"].get<std::string>();
#define SET_HANDLER(cmd, handler) \
Expand Down Expand Up @@ -242,15 +212,11 @@ static void EventOnPreRunEffect(DebugSocket *debugSocket, const EffectIdentifier
static void EventOnPostRunEffect(DebugSocket *debugSocket, const EffectIdentifier &identifier)
{
if (!debugSocket->m_IsProfiling)
{
return;
}

const auto &effectId = identifier.GetEffectId();
if (!debugSocket->m_EffectTraceStats.contains(effectId))
{
return;
}

auto &traceStats = debugSocket->m_EffectTraceStats.at(effectId);

Expand All @@ -272,9 +238,7 @@ static void EventOnPostRunEffect(DebugSocket *debugSocket, const EffectIdentifie
}

if (execTime > traceStats.MaxExecTime)
{
traceStats.MaxExecTime = execTime;
}
}

DebugSocket::DebugSocket()
Expand Down Expand Up @@ -316,19 +280,15 @@ void DebugSocket::Close()
void DebugSocket::ScriptLog(std::string_view scriptName, std::string_view text)
{
if (!m_Server)
{
return;
}

json json;
json["command"] = "script_log";
json["script_name"] = scriptName;
json["text"] = text;

for (auto client : m_Server->getClients())
{
client->send(json.dump());
}
}

void DebugSocket::OnModPauseCleanup()
Expand Down
20 changes: 0 additions & 20 deletions ChaosMod/Components/EffectDispatchTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ EffectDispatchTimer::EffectDispatchTimer(const std::array<BYTE, 3> &timerColor)
void EffectDispatchTimer::UpdateTimer(int deltaTime)
{
if (!m_EnableTimer || (ComponentExists<MetaModifiers>() && GetComponent<MetaModifiers>()->DisableChaos))
{
return;
}

m_TimerPercentage += deltaTime
* (ComponentExists<MetaModifiers>() ? GetComponent<MetaModifiers>()->TimerSpeedModifier : 1.f)
Expand All @@ -37,12 +35,8 @@ void EffectDispatchTimer::UpdateTimer(int deltaTime)
GetComponent<EffectDispatcher>()->DispatchRandomEffect();

if (ComponentExists<MetaModifiers>())
{
for (std::uint8_t i = 0; i < GetComponent<MetaModifiers>()->AdditionalEffectsToDispatch; i++)
{
GetComponent<EffectDispatcher>()->DispatchRandomEffect();
}
}

m_TimerPercentage = 0.f;
}
Expand Down Expand Up @@ -86,12 +80,8 @@ void EffectDispatchTimer::UpdateTravelledDistance()
GetComponent<EffectDispatcher>()->DispatchRandomEffect();

if (ComponentExists<MetaModifiers>())
{
for (std::uint8_t i = 0; i < GetComponent<MetaModifiers>()->AdditionalEffectsToDispatch; i++)
{
GetComponent<EffectDispatcher>()->DispatchRandomEffect();
}
}
}

m_DistanceChaosState.SavedPosition = position;
Expand All @@ -113,12 +103,8 @@ void EffectDispatchTimer::UpdateTravelledDistance()
GetComponent<EffectDispatcher>()->DispatchRandomEffect();

if (ComponentExists<MetaModifiers>())
{
for (std::uint8_t i = 0; i < GetComponent<MetaModifiers>()->AdditionalEffectsToDispatch; i++)
{
GetComponent<EffectDispatcher>()->DispatchRandomEffect();
}
}

m_TimerPercentage = 0;
}
Expand Down Expand Up @@ -204,20 +190,14 @@ void EffectDispatchTimer::OnRun()

// the game was paused
if (deltaTime > 1000)
{
deltaTime = 0;
}

if (!m_PauseTimer)
{
if (m_DistanceChaosState.EnableDistanceBasedEffectDispatch)
{
UpdateTravelledDistance();
}
else
{
UpdateTimer(deltaTime);
}
}

m_Timer = currentUpdateTime;
Expand Down
Loading

0 comments on commit 9cdae15

Please sign in to comment.