-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Expose suggestedGuestMaximum via a hook. #21521
base: develop
Are you sure you want to change the base?
Expose suggestedGuestMaximum via a hook. #21521
Conversation
83a759d
to
738bebe
Compare
a679eba
to
b37e54c
Compare
How could I stop the max guest calculations being run every 13 seconds as it overwrites the effects of the plugin? |
Maybe the plugin code should go here instead? OpenRCT2/src/openrct2/world/Park.cpp Lines 535 to 581 in 4ccecd6
Then the plugin code would be part of that calculation being run every 13 seconds, so it could override that code every time it gets run. Downside: when initially changing the soft guest cap, it might not update instantly, so you might have to wait up to 13 seconds for the change to be applied. |
This was purposely made readonly as it shouldn't be settable from plugins. |
Can you only edit the variable if it is not made readonly? Or can you edit the variable another way? |
My idea when starting the discussion topic was that there would be some new separate variable. You would expose that to the API, let plugins set it, and then add it to the calculated soft guest cap internally. You'd have to save it to the park data though; not sure how easy that would be to add. |
I think it might be best to just call a hook at this point, if the hook returns something take that value otherwise use whatever the builtin returns, I think this function isn't called as much so it should be safe from performance issues. I'm however not sure how hooks currently work when multiple plugins want to hook this function, but the same problem also exists with fighting over the variable I guess. |
146cee1
to
f8c8bca
Compare
I'm not sure the current implementation of the hook is correct. What if I want to double the suggested max, e.g. For having multiple plugins hook it, it would also be nice if you could also get the current suggested max, so the hooks for multiple plugins can be executed in a chain, e.g.
Of course, a plugin could still discard the original suggestion and override it completely, but it wouldn't be a necessity. |
7c54991
to
043f79f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late reply, I've been a bit busy!
Also might be due to my delay, but this PR will need a plugin API version increment. 🙂 |
de82030
to
a5219df
Compare
70c7781
to
4631df9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, thanks for the quick changes. I've tested it and it looks good to me! 🙂
For reference, click here for my test code
var frozenGuestCap = false;
var originalGuestCap = 0;
var modifiedGuestCap = 0;
var guestCapEvent;
registerPlugin({
name: "Test for guest cap",
version: "1",
authors: ['Basssiiie'],
targetApiVersion: 82,
type: "local",
licence: "MIT",
main() {
ui.registerMenuItem("Test guest cap", function() {
originalGuestCap = park.suggestedGuestMaximum;
var window = ui.openWindow({
classification: "test-guest-cap",
title: "Set guest cap",
width: 200,
height: 125,
onUpdate: function()
{
var label1 = window.findWidget("original-guest-cap-label");
var label2 = window.findWidget("current-guest-cap-label");
label1.text = "Original guest cap: " + originalGuestCap;
label2.text = "Current guest cap: " + park.suggestedGuestMaximum;
},
widgets: [
{
name: "original-guest-cap-label",
type: "label",
x: 10,
y: 25,
width: 180,
height: 15,
},
{
name: "current-guest-cap-label",
type: "label",
x: 10,
y: 50,
width: 180,
height: 15,
},
{
type: "checkbox",
x: 10,
y: 75,
width: 180,
height: 15,
text: "Freeze guest cap",
isChecked: frozenGuestCap,
onChange: function(check)
{
frozenGuestCap = check;
if (check)
{
guestCapEvent = context.subscribe("park.calculateGuestCap", function(evt)
{
originalGuestCap = evt.suggestedGuestMaximum;
evt.suggestedGuestMaximum = modifiedGuestCap;
})
}
else if (guestCapEvent)
{
guestCapEvent.dispose();
guestCapEvent = null;
}
}
},
{
type: "textbox",
x: 10,
y: 100,
width: 180,
height: 15,
text: modifiedGuestCap.toString(),
onChange: function(text)
{
modifiedGuestCap = Number.parseInt(text);
}
}
]
});
})
}
});
Thanks for the help and patience. |
4631df9
to
56db057
Compare
56db057
to
ea6403d
Compare
Is there anything else that I need to implement for this PR - or is it all good? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't tested, but I like the implementation via the hook.
ea6403d
to
f429e7c
Compare
I have renamed |
Exposes the suggestedGuestMaximum variable through the API - it used to only be a readonly variable. This adds the functionality for plugins like requested in #21507. I have created a demo using this functionality. Also implemented a hook called "park.calculateGuestCap" to handle setting this value.