devynspencer / zomboid-mod-tools

Development tools, configurations, templates, and build scripts for Project Zomboid mod development.
MIT License
4 stars 0 forks source link

Add function(s) for getting common game directories #8

Open devynspencer opened 2 years ago

devynspencer commented 2 years ago

Add another quality of life function to get frequently needed directories for modding:

image

image

devynspencer commented 2 years ago

Parameter Sets and Reusable Modifier Parameters

After a moment of thought, the above is a good candidate for refactoring the just added Get-ZomboidModLocation function. The function could be renamed to a more general Get-ZomboidLocation or similar, and have additional switch parameters for major parent directories.

Parent Location Parameters

Add parameter sets that narrow the context into a major area, specified by a -Context or -Scope parameter:

Child Location Parameters

To support the above (and to avoid 50+ switch parameters), the above are augmented with a common -Name or -LocationName parameter for specifying the children of the above.

The Name parameters would be reusable, as in each parameter set would have a different set of values for the ValidateSet attribute. This avoids needing a tons of flags while also providing auto-completion for tabbing through potential values.

Examples

The "Mods" value for these two commands would be different, as they refer to the mods directory for the User and Steam directories, respectively:

Get-ZomboidLocation -Context User -Name Mods
Get-ZomboidLocation -Context Steam -Name Mods

Furthermore, discovery is possible so a fledgling modder can easily begin to understand the important locations within the user Zomboid directory (and consistently reference these locations from scripts):

Get-ZomboidLocation -Context User -Name Logs, Lua, SandboxPresets

This isn't necessary by any means, but anything that removes a barrier to development or troubleshooting is a very good thing. Worst case this is something that would likely be refactored into a private function anyways. Making the function easy to use on the shell as well is just a bonus.

devynspencer commented 2 years ago

Oof, it turns out that multiple ValidateSet attributes cannot be applied to a parameter (as it's not designated in the Parameter attribute where ParameterSetName is specified.

It may be worth looking into dynamic parameter sets, but the alternative would appear to be a parameter for locations from each context.

devynspencer commented 2 years ago

Combining an ArgumentCompleter attribute with a ValidateScript attribute. This adds minor code duplication but supports the desired tab-completion.