Skip to content

Menu Variants is now compatible with Fortrise new version! - #16

Merged
CoolModder merged 4 commits into
CoolModder:mainfrom
lynconEBB:MenuVariantsUpdate
Jan 11, 2025
Merged

Menu Variants is now compatible with Fortrise new version!#16
CoolModder merged 4 commits into
CoolModder:mainfrom
lynconEBB:MenuVariantsUpdate

Conversation

@lynconEBB

@lynconEBB lynconEBB commented Jan 9, 2025

Copy link
Copy Markdown
Contributor

This pull request fixes issue #6

Updated Atlas Creation:

I Replaced the deprecated new Atlas() with the recommended AtlasExt.CreateAtlas() method to ensure compatibility with the latest system architecture.

Improved Logo and Bezel Loading:

Modified the logo and bezel loading process so that assets no longer need to be placed in the root Content folder. Instead, logos and bezels can now be stored directly within the Mod's Content folder for better organization and modularity.

Enhanced Mod Settings Menu:

Updated the Mod Settings menu to utilize the new CreateModSettings(TextContainer textContainer) hook, allowing players to change logos and bezels in real-time without the need to restart the game.

Let me know if you need any clarification or further adjustments. I’m happy to assist with any questions or issues that may arise.

@Terria-K Terria-K left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I request a small changes on changing the obsolete signature that will be removed next major version. The path concatenation with _separator could be replaced with Path.Combine instead.

Comment thread MenuVariantsMod/BezelLoad.cs Outdated
Console.WriteLine(text);
var text2 = text.Replace("Content" + _separator, "");
Atlas atlas = new Atlas(text2 + _separator + "atlas.xml", text2 + _separator + "atlas.png", true);
Atlas atlas = AtlasExt.CreateAtlas(content, text2 + _separator + "atlas.xml", text2 + _separator + "atlas.png", true, ContentAccess.Content);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should remove the 4th argument since this signature is obsolete and will be removed in 5.0

Comment thread MenuVariantsMod/LogoLoad.cs Outdated
Atlas atlas = new Atlas(text2 + _separator + "atlas.xml", text2 + _separator + "atlas.png", true);
var LogoData = Calc.LoadXML(text + _separator + "LogoData.xml");
Console.WriteLine(customLogoPath);
Atlas atlas = AtlasExt.CreateAtlas(content, customLogoPath + _separator + "atlas.xml", customLogoPath + _separator + "atlas.png", true, ContentAccess.Root);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one as well is using the obsolete signature

@lynconEBB

Copy link
Copy Markdown
Contributor Author

Hi @Terria-K,

Thank you for the feedback!

I've followed your instructions and updated the code to use Path.Combine for creating the custom assets path. Additionally, I have changed the CreateAtlas method to use the non-obsolete signature as recommended.

I also made several corrections to some mistakes I had made and renamed the main module class to something more appropriate, rather than leaving it as ExampleModModule.

One concern I had was the hardcoding of the mod's folder name. I wanted to avoid assuming that players will always use the same folder name. Is there a way to dynamically retrieve the mod folder name, perhaps via ContentAccess.ModContent or another method? Any guidance here would be greatly appreciated!

private static readonly string CUSTOM_LOGOS_DIR = Path.Combine("Mods", "MenuVariantsMod", "Content", "CustomLogos" );

@Terria-K

Terria-K commented Jan 10, 2025

Copy link
Copy Markdown
Contributor

@lynconEBB

There's a way to do this if you want to look inside of the mod content itself which uses Content field. You had to use it inside of the LoadContent. It's quite complicated to use for now, but the API has been improved in the later version.

Content is like a resource map that map to a path of all mod's resources, and it also has an get_Item getter which acts like Dictionary when you use it. It is relative to the mod's content path itself and its safe to use this.

Basic usage would be like:

private static readonly string CUSTOM_LOGOS_DIR = Path.Combine("Content", "CustomLogos" );

/*    inside of LoadContent    */

string anotherPath = Path.Combine(CUSTOM_LOGOS_DIR, "path/to/file").Replace('\\'. '/');
using Stream stream = Content[anotherPath].Stream;
// Do someting with the stream

The Content get_Item itself is an abstraction to the lookup for RiseCore.ResourceTree which is how FortRise map all the mod's resources. You also had to use forward slashes instead of backslashes, this API still being improved. It returns a RiseCore.Resource which contains atleast 4 path information:

  • Root - A prefix of a mod from a resource tree based on the metadata name (ex: mod:ExampleMod/)
  • Path - A relative path to a mod, starting from a level of meta.json
  • FullPath - If a mod is a directory, it will contains an absolute path to a mod folder, if a mod is a zip file, it will contain a Root prefix. RiseCore.ResourceTree.Treemap can contain an absolute path as well, so no need to be afraid of using this
  • RootPath - However, if you are not sure with the integrity of FullPath, you can just use this instead, it's a combination of Root and Path.

RiseCore.Resource also contains Childrens which if a Resource has childrens, its probably a folder.

If you need to iterate all files from a directory, you need to lookup a directory from a Content field, and iterate its childrens.

@lynconEBB lynconEBB left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I have completed all the changes I intended, and the code is now stable and ready for a new release. If you encounter any issues, please let me know, and I will address them.

{
Atlas atlas = AtlasExt.CreateAtlas(content, Path.Combine(customBezelPath, "atlas.xml"), Path.Combine(customBezelPath,"atlas.png"));
var BezelData = Calc.LoadXML(Path.Combine(customBezelPath, "BezelData.xml"));
Atlas atlas = AtlasExt.CreateAtlas(content, $"{resource.Path}/atlas.xml", $"{resource.Path}/atlas.png", ContentAccess.ModContent);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loading based on Mod Content Folder concatenating string with $, i also needed to get the logo xml resource and then then load the XML, i think its better then using a path from root

{
public static void MyLoad()
{
if (MenuVariantModModule.Settings.BezelVariant > 0 && !BezelLoad.BezelList.Any())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this check so that when the configuration is set to use a custom logo, if on the next start this custom bezel is not present it will use the default one (user can delete the custom bezel folder and it dont crash)

Comment thread MenuVariantsMod/MyLogo.cs
var towerTarget = LogoData.Get<Vector2>("towerTarget");
var coreTarget = LogoData.Get<Vector2>("towerTarget");

if (MenuVariantModModule.Settings.MenuVariant >= MenuVariantModModule.Vanilla.Count)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing for logos

Comment thread MenuVariantsMod/MenuVariantsMod.csproj Outdated
<NoWarn>1701;1702;0104;1061;0246;0118;0123</NoWarn>
<WarningLevel>0</WarningLevel>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<OutputPath>..\Towerfall - Ascension\Mods\MenuVariantsMod\</OutputPath>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For simplicity, output in the mod base folder; Fortrise ONLY loads from the Towerfall\Mods folder.

Add credits
@CoolModder
CoolModder merged commit 24cdfa6 into CoolModder:main Jan 11, 2025
@CoolModder

Copy link
Copy Markdown
Owner

Merged! A later update will be added for more QOL features and customization options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants