From a3b1ac162f2f574322219e8aad5e823e3e29abf8 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Wed, 25 Sep 2024 22:50:45 -0600 Subject: [PATCH] Restore tools/metaforce_renames.py --- tools/metaforce_renames.py | 87 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 tools/metaforce_renames.py diff --git a/tools/metaforce_renames.py b/tools/metaforce_renames.py new file mode 100644 index 00000000..01cc8aab --- /dev/null +++ b/tools/metaforce_renames.py @@ -0,0 +1,87 @@ +import re +import argparse +from pathlib import Path + +_LITERAL_REPLACEMENTS = [ + ("std::string_view", "const rstl::string&"), + ("std::vector", "rstl::vector"), + ("std::list", "rstl::list"), + ("std::pair", "rstl::pair"), + ("std::optional", "rstl::optional_object"), + ("std::nullopt", "rstl::optional_object_null()"), + + ("zeus::CTransform", "CTransform4f"), + ("zeus::skZero2f", "CVector2f(0.f, 0.f)"), + ("zeus::skZero3f", "CVector3f::Zero()"), + ("zeus::skPurple", "CColor::Purple()"), + ("zeus::skWhite", "CColor::White()"), + ("zeus::CFrustum", "CFrustumPlanes"), + ("zeus::lookAt", "CTransform4f::LookAt"), + ("zeus::radToDeg", "CMath::Rad2Deg"), + ("zeus::degToRad", "CMath::Deg2Rad"), + ("zeus::", ""), + ("u32 ", "uint "), + ("s32 ", "int "), + ("std::min(", "rstl::min_val("), + ("std::max(", "rstl::max_val("), + + ("DEFINE_ENTITY", ""), + ("visitor.Visit(this)", "visitor.Visit(*this)"), + + ("g_SimplePool", "gpSimplePool"), + ("g_Renderer", "gpRender"), + ("g_ResFactory", "gpResourceFactory"), + + # Vector + (".magnitude()", ".Magnitude()"), + (".normalized()", ".AsNormalized()"), + # Transform + (".frontVector()", ".GetForward()"), + + # CStateManager + (".GetActiveRandom()", ".Random()"), + + # Enums + ("EMaterialTypes::", "kMT_"), + ("EScriptObjectState::", "kSS_"), + ("EScriptObjectMessage::", "kSM_"), + ("CPlayer::EPlayerOrbitState::", "CPlayer::kOS_"), + ("CPlayer::ESurfaceRestraints::", "CPlayer::kSR_"), + ("CPlayer::EPlayerCameraState::", "CPlayer::kCS_"), + ("CPlayer::EPlayerMorphBallState::", "CPlayer::kMS_"), + ("CPlayer::EPlayerOrbitType::", "CPlayer::kOT_"), + ("CPlayer::EPlayerOrbitRequest::", "CPlayer::kOR_"), + ("CPlayer::EPlayerZoneInfo::", "CPlayer::kZI_"), + ("CPlayer::EPlayerZoneType::", "CPlayer::kZT_"), + ("CPlayer::EPlayerScanState::", "CPlayer::kSS_"), + ("CPlayer::EGrappleState::", "CPlayer::kGS_"), + ("CPlayer::EFootstepSfx::", "CPlayer::kFS_"), + ("CPlayer::EGunHolsterState::", "CPlayer::kGH_"), + ("CPlayerState::EPlayerVisor::", "CPlayerState::kPV_"), + ("CPlayerState::EPlayerSuit::", "CPlayerState::kPS_"), + ("CPlayerState::EBeamId::", "CPlayerState::kBI_"), + ("CPlayerState::EItemType::", "CPlayerState::kIT_"), +] +_RE_REPLACEMENTS = [ + (re.compile(r"SObjectTag{FOURCC\('(.*)'\),\s*(.*)}"), r"SObjectTag('\1', \2)"), +] + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("file", type=Path) + args = parser.parse_args() + + contents: str = args.file.read_text() + + for sub, replacement in _LITERAL_REPLACEMENTS: + contents = contents.replace(sub, replacement) + + for re_obj, replacement in _RE_REPLACEMENTS: + contents = re_obj.sub(replacement, contents) + + args.file.write_text(contents) + + +if __name__ == "__main__": + main()