Add GithubTags mod source#416
Conversation
|
Could you also mock up some doc for this, so that we could see how it should be implemented and so that it could be easily copied into the MSU wiki later? |
37bcd3d to
b9a3280
Compare
Not sure what do you mean. I have an example in commit message above, can copy that to Wiki. Or you mean a way to implement an extra type of source? I don't know a way to document it concise enough so that it will be more useful than reading actual source code :) |
|
Maybe change this: function addModSource( _domain, _url )
{
::MSU.requireOneFromTypes(["string", "table"], _url);
this.__ModSources[_domain] <- ::MSU.System.Registry.ModSources[_domain](_url);
}to function addModSource( _domain, _url, _opts = null )
{
::MSU.requireString(_url);
if (_opts != null) ::MSU.requireTable(_opts);
this.__ModSources[_domain] <- ::MSU.System.Registry.ModSources[_domain](_url, _opts);
}? |
|
I mean the method of implementing the additional source, this would have to be documented in the MSU wiki as that is standard practice for MSU, and it's supposed to make it more accessible. We don't really point people at the source code, an explanation + an implementation example is required :/. |
|
and yes I much prefer your suggested change |
Heh, do you mean implementing inside or outside MSU? And someone adding this simply from docs is just not realistic :). Say you have docs for custom mod settings items, but there is no way I could have done that not reading source throughly. I will try to come up with something though. |
42aca3a to
d1fd215
Compare
|
Ok, added the suggested change. |
|
I think custom mod settings is a fair example, but admittedly that stuff is pretty complex and requires working with a lot of existing systems within MSU. The GitHub tags shouldn't actually be that complicated to implement from what I understand, and doesn't require interfacing with any internal stuff, so I don't think it should be that problematic? |
|
Ok, here it is: To add new mod source one needs to do several things:
Here is a minimal example needed to add a new source, I am providing a way to add links to ::MSU.System.Registry.ModSourceDomain.add("HackyStash");
::YourNamespace.ModSourceHackyStash <- class extends ::MSU.Class.ModSource
{
static ModSourceDomain = ::MSU.Class.RegistrySystem.ModSourceDomain.HackyStash;
}
::MSU.System.Registry.addNewModSource(::HackMSU.ModSourceHackyStash);Let's add URL validation and some icon: ::YourNamespace.ModSourceHackyStash <- class extends ::MSU.Class.ModSource
{
...
static Regex = regexp(@"https://hacky-stash.game/mods/([-\w]+)");
static BadURLMessage = "A link must point into directly to a mod page, e.g. 'https://hacky-stash.game/mods/cleaver-axe-overhaul'";
static Icon = "github"; // Only github or nexusmods images go with MSU
}Now any typos and other mishaps in the URL will be caught, like people typing in To enable update checking for our mod source we will need to add two extra methods: ::YourNamespace.ModSourceHackyStash <- class extends ::MSU.Class.ModSource
{
...
function getUpdateURL()
{
local capture = this.Regex.capture(this.__URL);
local slug = ::MSU.regexMatch(capture, this.__URL, 1);
// Forturnately hacky slash provides an API
return format("https://api.hacky-stash.game/mods/%s/releases", slug)
}
function extractRelease(_data) {
// say we get a JSON with with all releases and the latest one goes first
if (_data.len() == 0) // protect against no releases
return null; // null means no info, MSU gets it
local release = _data[0];
// For MSU to understand us we need to send a table with 2 keys:
// Version - a semver string of latest available release
// Changes - a description of changes brought by it, pass empty string if absent
return {Version = release.version, Changes = release.message || ""}
}
} |
d1fd215 to
fd757fe
Compare
|
Thank you, this is all pretty great, one final thing that I'd ask that will be pretty annoying, but could you separate the |
aa8bbc0 to
39ac5f1
Compare
|
Ok, done. |
TaroEld
left a comment
There was a problem hiding this comment.
Good idea, thanks for the refactor, just needs a few adaptations.
- extract URL validation to the base class - add a way to supply extra options - add Icon static attr to disentangle icon from enum/class - add `.extractRelease()` to cleanup data in a source-specific manner - map fetched data to update info in `.checkIfModVersionsAreNew()` instead of passing through and patching it
e611d14 to
0497431
Compare
Usage:
```squirrel
mod.Mod.Registry.addModSource(
::MSU.System.Registry.ModSourceDomain.GitHubTags,
"https://github.com/Suor/battle-brothers-mods/tree/master/autopilot"
// tag prefix, for i.e. tag autopilot-new-2.2.0 be 2.2.0 release
{Prefix = "autopilot-new-"});
mod.Mod.Registry.setUpdateSource(::MSU.System.Registry.ModSourceDomain.GitHubTags);
// Can still add this for icon with a link
mod.Mod.Registry.addModSource(
::MSU.System.Registry.ModSourceDomain.NexusMods,
"https://www.nexusmods.com/battlebrothers/mods/675");
```
0497431 to
26415de
Compare
* refactor: mod sources
- extract URL validation to the base class
- add a way to supply extra options
- add Icon static attr to disentangle icon from enum/class
- add `.extractRelease()` to cleanup data in a source-specific manner
- map fetched data to update info in `.checkIfModVersionsAreNew()`
instead of passing through and patching it
* feat: add GithubTags mod source
Usage:
```squirrel
mod.Mod.Registry.addModSource(
::MSU.System.Registry.ModSourceDomain.GitHubTags,
"https://github.com/Suor/battle-brothers-mods/tree/master/autopilot"
// tag prefix, for i.e. tag autopilot-new-2.2.0 be 2.2.0 release
{Prefix = "autopilot-new-"});
mod.Mod.Registry.setUpdateSource(::MSU.System.Registry.ModSourceDomain.GitHubTags);
// Can still add this for icon with a link
mod.Mod.Registry.addModSource(
::MSU.System.Registry.ModSourceDomain.NexusMods,
"https://www.nexusmods.com/battlebrothers/mods/675");
```
Usage: