mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-12-01 06:08:39 +00:00
fix: Keep menus of IW4 menu lists loaded by an earlier list (#1064)
* fix: Keep menus of IW4 menu lists loaded by an earlier list * chore: add change to all menu loaders, not only IW4 --------- Co-authored-by: Jan Laupetin <[email protected]>
This commit is contained in:
1 parent
737cfecf6d
commit
28605c74ae
12 files changed
+490
-244
No files matched your search
@@ -30,25 +30,15 @@ namespace
|
||||
}
|
||||
};
|
||||
|
||||
class MenuParsingItHelper
|
||||
class MenuLoadingTestHelper
|
||||
{
|
||||
static constexpr const char* DEFAULT_ASSET_NAME = "test.txt";
|
||||
|
||||
Zone m_zone;
|
||||
MockSearchPath m_search_path;
|
||||
std::unique_ptr<IAssetCreator> m_asset_creator;
|
||||
AssetCreatorCollection m_creator_collection;
|
||||
IgnoredAssetLookup m_ignored_asset_lookup;
|
||||
AssetCreationContext m_context;
|
||||
|
||||
public:
|
||||
MenuParsingItHelper()
|
||||
MenuLoadingTestHelper()
|
||||
: m_zone("MockZone", 0, GameId::IW4, GamePlatform::PC),
|
||||
m_creator_collection(m_zone),
|
||||
m_ignored_asset_lookup(),
|
||||
m_context(m_zone, &m_creator_collection, &m_ignored_asset_lookup)
|
||||
{
|
||||
m_asset_creator = ::menu::CreateMenuListLoaderIW4(m_zone.Memory(), m_search_path);
|
||||
m_loader = menu::CreateMenuListLoaderIW4(m_zone.Memory(), m_search_path);
|
||||
}
|
||||
|
||||
void AddFile(std::string fileName, std::string data)
|
||||
@@ -56,11 +46,6 @@ namespace
|
||||
m_search_path.AddFileData(std::move(fileName), std::move(data));
|
||||
}
|
||||
|
||||
void AddFile(std::string data)
|
||||
{
|
||||
AddFile(DEFAULT_ASSET_NAME, std::move(data));
|
||||
}
|
||||
|
||||
Material* AddMaterial(const std::string& name)
|
||||
{
|
||||
auto* material = m_zone.Memory().Alloc<Material>();
|
||||
@@ -71,27 +56,33 @@ namespace
|
||||
return material;
|
||||
}
|
||||
|
||||
AssetCreationResult RunIntegrationTest()
|
||||
AssetCreationResult LoadMenuList(const std::string& name)
|
||||
{
|
||||
return m_asset_creator->CreateAsset(DEFAULT_ASSET_NAME, m_context);
|
||||
return m_loader->CreateAsset(name, m_context);
|
||||
}
|
||||
|
||||
menuDef_t* GetMenuAsset(const std::string& menuName) const
|
||||
[[nodiscard]] menuDef_t* GetMenu(const std::string& name) const
|
||||
{
|
||||
const auto addedAsset = m_zone.m_pools.GetAsset(ASSET_TYPE_MENU, menuName);
|
||||
REQUIRE(addedAsset);
|
||||
REQUIRE(addedAsset->m_type == ASSET_TYPE_MENU);
|
||||
|
||||
return static_cast<menuDef_t*>(addedAsset->m_ptr);
|
||||
const auto* asset = m_zone.m_pools.GetAsset(ASSET_TYPE_MENU, name);
|
||||
REQUIRE(asset);
|
||||
return static_cast<menuDef_t*>(asset->m_ptr);
|
||||
}
|
||||
|
||||
private:
|
||||
Zone m_zone;
|
||||
MockSearchPath m_search_path;
|
||||
std::unique_ptr<IAssetCreator> m_loader;
|
||||
AssetCreatorCollection m_creator_collection;
|
||||
IgnoredAssetLookup m_ignored_asset_lookup;
|
||||
AssetCreationContext m_context;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("MenuParsingIW4IT: Can convert simple menu without properties", "[parsing][converting][menu][it]")
|
||||
{
|
||||
MenuParsingItHelper helper;
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile(R"testmenu(
|
||||
helper.AddFile("test.txt", R"testmenu(
|
||||
{
|
||||
menuDef
|
||||
{
|
||||
@@ -100,11 +91,11 @@ TEST_CASE("MenuParsingIW4IT: Can convert simple menu without properties", "[pars
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
const auto result = helper.RunIntegrationTest();
|
||||
const auto result = helper.LoadMenuList("test.txt");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menuList = (MenuList*)result.GetAssetInfo()->m_ptr;
|
||||
const auto* menu = helper.GetMenuAsset("Hello");
|
||||
const auto* menuList = static_cast<MenuList*>(result.GetAssetInfo()->m_ptr);
|
||||
const auto* menu = helper.GetMenu("Hello");
|
||||
|
||||
REQUIRE(menuList->menuCount == 1);
|
||||
REQUIRE(menuList->menus);
|
||||
@@ -118,9 +109,9 @@ TEST_CASE("MenuParsingIW4IT: Can convert simple menu without properties", "[pars
|
||||
|
||||
TEST_CASE("MenuParsingIW4IT: Can convert simple menu", "[parsing][converting][menu][it]")
|
||||
{
|
||||
MenuParsingItHelper helper;
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile(R"testmenu(
|
||||
helper.AddFile("test.txt", R"testmenu(
|
||||
#define COOL_STYLE 5
|
||||
#define VISIBILITY_ENABLED 1
|
||||
#define HIDE_STUPID_ELEMENTS 0
|
||||
@@ -181,11 +172,11 @@ TEST_CASE("MenuParsingIW4IT: Can convert simple menu", "[parsing][converting][me
|
||||
|
||||
const auto* funnyDogMaterial = helper.AddMaterial("funny_dog.png");
|
||||
|
||||
const auto result = helper.RunIntegrationTest();
|
||||
const auto result = helper.LoadMenuList("test.txt");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menuList = (MenuList*)result.GetAssetInfo()->m_ptr;
|
||||
const auto* menu = helper.GetMenuAsset("Bla");
|
||||
const auto* menuList = static_cast<MenuList*>(result.GetAssetInfo()->m_ptr);
|
||||
const auto* menu = helper.GetMenu("Bla");
|
||||
|
||||
REQUIRE(menuList->menuCount == 1);
|
||||
REQUIRE(menuList->menus);
|
||||
@@ -315,9 +306,9 @@ TEST_CASE("MenuParsingIW4IT: Can convert simple menu", "[parsing][converting][me
|
||||
|
||||
TEST_CASE("MenuParsingIW4IT: Can use numeric focus dvar values", "[parsing][converting][menu][it]")
|
||||
{
|
||||
MenuParsingItHelper helper;
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile(R"testmenu(
|
||||
helper.AddFile("test.txt", R"testmenu(
|
||||
{
|
||||
menuDef
|
||||
{
|
||||
@@ -330,10 +321,10 @@ TEST_CASE("MenuParsingIW4IT: Can use numeric focus dvar values", "[parsing][conv
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
const auto result = helper.RunIntegrationTest();
|
||||
const auto result = helper.LoadMenuList("test.txt");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menu = helper.GetMenuAsset("NumericFocusDvar");
|
||||
const auto* menu = helper.GetMenu("NumericFocusDvar");
|
||||
REQUIRE(menu->itemCount == 1);
|
||||
REQUIRE(menu->items != nullptr);
|
||||
|
||||
@@ -345,9 +336,9 @@ TEST_CASE("MenuParsingIW4IT: Can use numeric focus dvar values", "[parsing][conv
|
||||
|
||||
TEST_CASE("MenuParsingIW4IT: Can omit list box column alignment", "[parsing][converting][menu][it]")
|
||||
{
|
||||
MenuParsingItHelper helper;
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile(R"testmenu(
|
||||
helper.AddFile("test.txt", R"testmenu(
|
||||
{
|
||||
menuDef
|
||||
{
|
||||
@@ -368,10 +359,10 @@ TEST_CASE("MenuParsingIW4IT: Can omit list box column alignment", "[parsing][con
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
const auto result = helper.RunIntegrationTest();
|
||||
const auto result = helper.LoadMenuList("test.txt");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menu = helper.GetMenuAsset("ListBoxColumns");
|
||||
const auto* menu = helper.GetMenu("ListBoxColumns");
|
||||
REQUIRE(menu->itemCount == 2);
|
||||
REQUIRE(menu->items != nullptr);
|
||||
|
||||
@@ -398,9 +389,9 @@ TEST_CASE("MenuParsingIW4IT: Can omit list box column alignment", "[parsing][con
|
||||
|
||||
TEST_CASE("MenuParsingIW4IT: Can specify event handler multiple times", "[parsing][converting][menu][it]")
|
||||
{
|
||||
MenuParsingItHelper helper;
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile(R"testmenu(
|
||||
helper.AddFile("test.txt", R"testmenu(
|
||||
{
|
||||
menuDef
|
||||
{
|
||||
@@ -433,11 +424,11 @@ TEST_CASE("MenuParsingIW4IT: Can specify event handler multiple times", "[parsin
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
const auto result = helper.RunIntegrationTest();
|
||||
const auto result = helper.LoadMenuList("test.txt");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menuList = (MenuList*)result.GetAssetInfo()->m_ptr;
|
||||
const auto* menu = helper.GetMenuAsset("Blab");
|
||||
const auto* menuList = static_cast<MenuList*>(result.GetAssetInfo()->m_ptr);
|
||||
const auto* menu = helper.GetMenu("Blab");
|
||||
|
||||
REQUIRE(menuList->menuCount == 1);
|
||||
REQUIRE(menuList->menus);
|
||||
@@ -476,9 +467,9 @@ TEST_CASE("MenuParsingIW4IT: Can specify event handler multiple times", "[parsin
|
||||
|
||||
TEST_CASE("MenuParsingIW4IT: Optimized exp rect considers parent pos", "[parsing][converting][menu][it]")
|
||||
{
|
||||
MenuParsingItHelper helper;
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile(R"testmenu(
|
||||
helper.AddFile("test.txt", R"testmenu(
|
||||
{
|
||||
menuDef
|
||||
{
|
||||
@@ -501,11 +492,11 @@ TEST_CASE("MenuParsingIW4IT: Optimized exp rect considers parent pos", "[parsing
|
||||
}
|
||||
})testmenu");
|
||||
|
||||
const auto result = helper.RunIntegrationTest();
|
||||
const auto result = helper.LoadMenuList("test.txt");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menuList = static_cast<MenuList*>(result.GetAssetInfo()->m_ptr);
|
||||
const auto* menu = helper.GetMenuAsset("Blab");
|
||||
const auto* menu = helper.GetMenu("Blab");
|
||||
|
||||
REQUIRE(menuList->menuCount == 1);
|
||||
REQUIRE(menuList->menus);
|
||||
@@ -544,9 +535,9 @@ TEST_CASE("MenuParsingIW4IT: Optimized exp rect considers parent pos", "[parsing
|
||||
|
||||
TEST_CASE("MenuParsingIW4IT: Optimized exp rect considers parent optimized pos", "[parsing][converting][menu][it]")
|
||||
{
|
||||
MenuParsingItHelper helper;
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile(R"testmenu(
|
||||
helper.AddFile("test.txt", R"testmenu(
|
||||
{
|
||||
menuDef
|
||||
{
|
||||
@@ -568,11 +559,11 @@ TEST_CASE("MenuParsingIW4IT: Optimized exp rect considers parent optimized pos",
|
||||
}
|
||||
})testmenu");
|
||||
|
||||
const auto result = helper.RunIntegrationTest();
|
||||
const auto result = helper.LoadMenuList("test.txt");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menuList = static_cast<MenuList*>(result.GetAssetInfo()->m_ptr);
|
||||
const auto* menu = helper.GetMenuAsset("Blab");
|
||||
const auto* menu = helper.GetMenu("Blab");
|
||||
|
||||
REQUIRE(menuList->menuCount == 1);
|
||||
REQUIRE(menuList->menus);
|
||||
@@ -606,14 +597,14 @@ TEST_CASE("MenuParsingIW4IT: Integer text expressions respect permissive mode",
|
||||
CAPTURE(permissive, optimization);
|
||||
ObjLoading::Configuration.MenuPermissiveParsing = permissive;
|
||||
ObjLoading::Configuration.MenuNoOptimization = !optimization;
|
||||
MenuParsingItHelper helper;
|
||||
helper.AddFile(R"MENU({ menuDef { name "test" itemDef { text "fallback" exp text (3); } } })MENU");
|
||||
MenuLoadingTestHelper helper;
|
||||
helper.AddFile("test.txt", R"MENU({ menuDef { name "test" itemDef { text "fallback" exp text (3); } } })MENU");
|
||||
|
||||
REQUIRE(helper.RunIntegrationTest().HasBeenSuccessful() == permissive);
|
||||
REQUIRE(helper.LoadMenuList("test.txt").HasBeenSuccessful() == permissive);
|
||||
if (!permissive)
|
||||
return;
|
||||
|
||||
const auto* menu = helper.GetMenuAsset("test");
|
||||
const auto* menu = helper.GetMenu("test");
|
||||
REQUIRE(menu->itemCount == 1);
|
||||
const auto* item = menu->items[0];
|
||||
REQUIRE(item->text);
|
||||
@@ -643,14 +634,14 @@ TEST_CASE("MenuParsingIW4IT: Double text expressions respect permissive mode", "
|
||||
CAPTURE(permissive, optimization);
|
||||
ObjLoading::Configuration.MenuPermissiveParsing = permissive;
|
||||
ObjLoading::Configuration.MenuNoOptimization = !optimization;
|
||||
MenuParsingItHelper helper;
|
||||
helper.AddFile(R"MENU({ menuDef { name "test" itemDef { text "fallback" exp text (3.5); } } })MENU");
|
||||
MenuLoadingTestHelper helper;
|
||||
helper.AddFile("test.txt", R"MENU({ menuDef { name "test" itemDef { text "fallback" exp text (3.5); } } })MENU");
|
||||
|
||||
REQUIRE(helper.RunIntegrationTest().HasBeenSuccessful() == permissive);
|
||||
REQUIRE(helper.LoadMenuList("test.txt").HasBeenSuccessful() == permissive);
|
||||
if (!permissive)
|
||||
return;
|
||||
|
||||
const auto* menu = helper.GetMenuAsset("test");
|
||||
const auto* menu = helper.GetMenu("test");
|
||||
REQUIRE(menu->itemCount == 1);
|
||||
const auto* item = menu->items[0];
|
||||
REQUIRE(item->text);
|
||||
@@ -671,3 +662,43 @@ TEST_CASE("MenuParsingIW4IT: Double text expressions respect permissive mode", "
|
||||
CHECK(expression->entries[0].data.operand.internals.floatVal == Approx(3.5));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("MenuParsingIW4IT: Keeps the menus of a menu list loaded by an earlier one", "[parsing][converting][menu][it]")
|
||||
{
|
||||
MenuLoadingTestHelper helper;
|
||||
|
||||
helper.AddFile("ui_mp/ingame.txt", R"testmenu(
|
||||
{
|
||||
loadMenu { "ui_mp/scriptmenus/killstreak.menu" }
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
helper.AddFile("ui_mp/scriptmenus/killstreak.menu", R"testmenu(
|
||||
{
|
||||
loadMenu { "ui_mp/killstreak_hint.menu" }
|
||||
menuDef
|
||||
{
|
||||
name "killstreak"
|
||||
}
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
helper.AddFile("ui_mp/killstreak_hint.menu", R"testmenu(
|
||||
{
|
||||
menuDef
|
||||
{
|
||||
name "killstreak_hint"
|
||||
}
|
||||
}
|
||||
)testmenu");
|
||||
|
||||
REQUIRE(helper.LoadMenuList("ui_mp/ingame.txt").HasBeenSuccessful());
|
||||
|
||||
const auto result = helper.LoadMenuList("ui_mp/scriptmenus/killstreak.menu");
|
||||
REQUIRE(result.HasBeenSuccessful());
|
||||
|
||||
const auto* menuList = static_cast<const MenuList*>(result.GetAssetInfo()->m_ptr);
|
||||
REQUIRE(menuList->menuCount == 2);
|
||||
REQUIRE(menuList->menus[0] == helper.GetMenu("killstreak"));
|
||||
REQUIRE(menuList->menus[1] == helper.GetMenu("killstreak_hint"));
|
||||
}
|
||||
Reference in new issue
Block a user