Majic-Jungle / sapiens-mod-creation

Official tools and examples for mod creation in the game Sapiens
MIT License
54 stars 12 forks source link

Some refactoring regarding plans #32

Closed WitchyMods closed 11 months ago

WitchyMods commented 11 months ago

I wanted to add a new action to the game (flattenTerrain). I was able to but with a looot of hacks. To be able to contribute my code to hammerstone in a "clean" way, I'd like to have the following refactoring done:

planHelper

It is currently possible to override functions to get the available plans and add our own. However, to effectively recalculate the availableCount for each existing plan, we currently have to recopy all of the setups for the plans and recalculate their hashes. Instead of existing in the function themselves, I would like all of those settings and their hashes (ex: "clearPlanInfo" at line 1732) to be part of planHelper itself the same way we have access to the types in "plan".

This way if a modder wants a planInfo and hash, they can do so by: planHelper.plansInfo[planTypeIndex] planHelper.planInfoHashes[planTypeIndex]

actionUI : global functions

Currently, all of the setup for the wheel's buttons are in the local function "updateButtons". It should remain local as it does a lot of the work for us that shouldn't change. However, I would like it to get the infos with some global functions:

actionUI:getWheelButtonsCount() In the vanilla code, that would be the number of planInfos returned by planHelper:getAvailablePlans. Some modders however COULD possibly want a button that does something unrelated to plans (ex: do something instantly)

actionUI:getWheelButtonInfos(planInfoOrNil, buttonIndex) Would return everything to fill the buttonTable with. So all you'd have to do in "updateButtons" would be buttonTable[buttonIndex] = actionUI:getWheelButtonInfos(planInfoOrNil, buttonIndex)

actionUI:getButtonClickFunction(planInfoOrNil, buttonIndex) Called by actionUI:getWheelButtonInfos. It would contain the following code: if planInfoOrNil then return function() local addInfo = actionUI:getAddPlansInfo(planInfoOrNil) logicInterface:callServerFunction("addPlans", addInfo) end end

In the vanilla code, the code would look like this: local clickFunction = actionUI:getButtonClickFunction(planInfoOrNil, buttonIndex) if clickFunction then buttonTable[buttonIndex].clickFunction = function() audio:playUISound(uiCommon.orderSoundFile) clickFunction() animateOutForOptionSelected(buttonIndex, nil) end end

actionUI: all other "click" functions Same as the main "click" for all the other functions (cancel, priority, etc)

actionUI:getAddPlansInfos(planInfo, buttonIndex) Called from actionUI:getButtonClickFunction. Allows modders to fill the "userData" that will be passed to planManager

actionUI : handle more than 6 buttons

With mods now able to add their own buttons, we will quickly run out of buttons. If the # of buttons is greater than 6, a "show more options" button should appear which would show the next 6 options. If we're showing button #7 and up, there should be a "go back" button to show the previous buttons

planManager

It's currently difficult to shadow planManager:AddPlans and its sub functions because some functions they use are still local. I would like the following functions to become global:

That's all :D I know it's a big ask but it's mostly nothing "new" other than the "more than 6 buttons" thing. I could help if you want/allow it :)

Feel free to poke me on discord if some things aren't clear.

WitchyMods commented 11 months ago

Please de-prioritize this issue. I'm working on something on the hammerstone side so that we don't have to request things like that :) I'm leaving it open in case this is needed eventually if my "thing" doesn't work :)

WitchyMods commented 11 months ago

Issue closed. Hammerstone now does patching :)