Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub Actions: add Nintendo Switch as build target #3928

Merged
merged 2 commits into from
Aug 1, 2021

Conversation

oleg-derevenetz
Copy link
Collaborator

close #3215

Unfortunately, I have no idea how to make a package properly (now I just create a ZIP file with fheroes2 binary file and all usual stuff) and there is no separate README for Switch, so only generic README.txt it is included in the package.

@oleg-derevenetz oleg-derevenetz added GitHub Actions GitHub Actions CI improvement New feature, request or improvement script Things related to various scripts (utility scripts, CI scripts, etc) labels Jul 29, 2021
@oleg-derevenetz oleg-derevenetz added this to the 0.9.6 milestone Jul 29, 2021
@ihhub
Copy link
Owner

ihhub commented Jul 30, 2021

Hi @dimag0g , could you please take a look at this pull request?

@ihhub
Copy link
Owner

ihhub commented Jul 31, 2021

Hi @dimag0g , could you please take a look at this pull request?

@dimag0g , could you please explain why the package should be named as *.nro?

@dimag0g
Copy link
Contributor

dimag0g commented Jul 31, 2021

@ihhub NRO is a "Nintendo Resource Object" which is a custom archive containing sections of an ELF file, an icon and a few description fields. Unlike Java JAR files, NRO is not compatible with ZIP.

This format is mostly used by homebrew SW, the eShop games usually come in NSP files (Nintendo Switch Package) which contain a mountable filesystem image. It's also possible to package homebrew in an NSP, but it only makes sense if all game resources can be distributed together with the executable, which is not the case for fheores2. Typically, NRO files run with current directory set to the SD card folder where they are located, while NSP files run with the current directory set to the mountpoint where the image was mounted.

Here's a make line I use in my switch branch to create an NRO file: https://github.com/dimag0g/fheroes2/blob/switch/Makefile

/opt/devkitpro/tools/bin/nacptool --create "fheroes2" "fheroes2 resurrection team" "0.9.4" $(TARGET).nacp
/opt/devkitpro/tools/bin/elf2nro $(TARGET) $(TARGET).nro --icon=heroes2.jpg --nacp=$(TARGET).nacp

Since fheroes2 needs additional files (*.mo) inside the package, it makes sense to put the NRO file together with files/lang directory inside a ZIP. I made such a ZIP for 0.9.4-ish version of the game, though the only file inside the ZIP which is actually useful is fheroes.cfg: https://apps.fortheusers.org/switch/fheroes2 . The ZIP is automatically extracted when the game is installed via the Homebrew App Store, and then the user must add game data in the /switch/fheroes2 directory.

Note that my switch branch also contains a modification which adds a custom 848x640 resolution, since the native 1280x720 might be a bit uncomfortable to read. There's some custom controls-related code in localevent.cpp as well. I suppose we could put this change conditionally in the main codebase under #ifdef __SWITCH__, and then there will be no reason for me to maintain the switch branch anymore.

@oleg-derevenetz
Copy link
Collaborator Author

Hi @dimag0g

/opt/devkitpro/tools/bin/elf2nro $(TARGET) $(TARGET).nro --icon=heroes2.jpg --nacp=$(TARGET).nacp

I suppose we need an icon? I wasn't able to find heroes2.jpg in your repo in the switch branch. What are the requirements for the icon? Is it possible to make NRO without it?

@dimag0g
Copy link
Contributor

dimag0g commented Jul 31, 2021

@oleg-derevenetz You'll need a 256x256 picture. If you don't supply one, the NRO will get a default icon from devkitPro which I suppose is free to use. I didn't include the icon I use in the repo because its license is not GPL-compatible.

@oleg-derevenetz
Copy link
Collaborator Author

Hi @ihhub @dimag0g Now the NRO file is produced and packed into the ZIP archive with all other stuff.

You'll need a 256x256 picture. If you don't supply one, the NRO will get a default icon from devkitPro which I suppose is free to use.

I copied icon.png from PSV for now (into files/images/platform/switch). It is 128x128, but it seems that it's OK for elf2nro - at least it doesn't complain. However, I don't know how it looks like on the device. I can upscale it, but if there is some source image in vector format, it is better to create an icon using it instead.

@dimag0g if you have a Switch, could you please test the produced NRO? The test release is available here:

https://github.com/oleg-derevenetz/fheroes2/releases/tag/fheroes2-switch-sdl2_dev

Also there are still no installation instructions that could be included in the ZIP package.

@ihhub
Copy link
Owner

ihhub commented Aug 1, 2021

Hi @oleg-derevenetz and @dimag0g , if we need 256x256 image we can use this:
logo_256

@dimag0g
Copy link
Contributor

dimag0g commented Aug 1, 2021

@oleg-derevenetz Your build runs on my Switch just fine. As I explained, the lowest available resolution is a bit too high and the default button mapping is a bit unusual ("A" is mouse right click, "B" is mouse left click), but the game is fully usable otherwise.

@ihhub ihhub merged commit 76a3aad into ihhub:master Aug 1, 2021
@ihhub
Copy link
Owner

ihhub commented Aug 1, 2021

@oleg-derevenetz , a huge thanks for implementing this!

@dimag0g , could you please assist to complete the support of Nintendo Switch: documentation perhaps and extra resolutions like we did for PlayStation Vita?

@dimag0g
Copy link
Contributor

dimag0g commented Aug 1, 2021

@ihhub @oleg-derevenetz Upon further testing I discovered that the game tries to use the root folder of the SD card as the home directory, so the config file is saved in the root, saving a game fails due to missing directory, and language files are not loaded:

10:59:31: [ERROR]	open:  fheroes2.key
10:59:34: [ERROR]	setGameLanguage:  Translation file ru.mo is not found.
11:00:15: [ERROR]	open:  /files/save/Àë__åð___0001.sav

I remember working on this problem in my Switch releases. I will make a PR soon with the changes (custom resolution, button mapping, home directory detection and the README file I have written). For now, it's a great progress to have official Switch builds, thanks to both of you for this effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GitHub Actions GitHub Actions CI improvement New feature, request or improvement script Things related to various scripts (utility scripts, CI scripts, etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Nintendo Switch build in GitHub Actions
3 participants