Skip to content

Expand api method coverage#18037

Closed
sudofox wants to merge 2 commits into
OpenRCT2:developfrom
sudofox:expand-api-method-coverage
Closed

Expand api method coverage#18037
sudofox wants to merge 2 commits into
OpenRCT2:developfrom
sudofox:expand-api-method-coverage

Conversation

@sudofox

@sudofox sudofox commented Sep 17, 2022

Copy link
Copy Markdown

Foreword

This is my first contribution. Please scrutinize it, especially for api param names. I tried to follow existing convention as much as I could.

This PR adds support to the API for a variety of methods. I would've added more, but I was struggling to figure out the correct syntax for some of them -- I'll keep working on them if/when this gets accepted.

staffsetorders

Example usage (assuming that the first staff member is a handyman) water gardens, empty trash bins:

context.executeAction("staffsetorders", { "staff": map.getAllEntities("staff")[0].id, "orders": 6 })

staffsetname

Example: Set first staff member's name to Foo Bar

context.executeAction("staffsetname", { "staff": map.getAllEntities("staff")[0].id, "name": "Foo Bar" })

staffsetcolour

Example: Set handyman uniforms to orange

context.executeAction("staffsetcolour", { "staffType": 0, "colour": 20 })

parksetresearchfunding

Example usage (maximum funding on rollercoasters and thrill rides):

context.executeAction("parksetresearchfunding", { "priorities": 12, "fundingAmount": 3 })

parksetparameter

Example usages (note that the value doesn't matter for close/open park):

context.executeAction("parksetparameter", { "parameter": 0, "value": 0 }) // close the park
context.executeAction("parksetparameter", { "parameter": 1, "value": 0 }) // open the park
context.executeAction("parksetparameter", { "parameter": 2, "value": 12345 }) // set the flags (uint64_t bitmask) for "Same price for item across park"

staffsetcostume

Example usage (changes costume of first entertainer):

context.executeAction("staffsetcostume", { "staff": map.getAllEntities("staff").filter(function(staff) { return staff.staffType == "entertainer" })[0].id, "costume": 0 })

scenariosetsetting

Example call (changes ParkChargeMethod to "Free park entry, pay for ride":

context.executeAction("scenariosetsetting", { "setting": 14, "value": 1 })

* Implement scenariosetsetting API call
Example call (changes ParkChargeMethod, which is 14, to 1, which is Free park entry, pay for ride):
`context.executeAction("scenariosetsetting", { "setting": 14, "value": 1 })`

* Implement StaffSetCostume API call
Example usage (changes costume of first entertainer):
`context.executeAction("staffsetcostume", { "staff": map.getAllEntities("staff").filter(function(staff) { return staff.staffType == "entertainer" })[0].id, "costume": 0 })`

* Implement parksetparameter API method
Example usages (note that the value doesn't matter for close/open park):
```
context.executeAction("parksetparameter", { "parameter": 0, "value": 0 }) // close the park
context.executeAction("parksetparameter", { "parameter": 1, "value": 0 }) // open the park
context.executeAction("parksetparameter", { "parameter": 2, "value": 12345 }) // set the flags (uint64_t) for "Same price for item across park"
```

* Implement parksetresearchfunding API method
Example usage (maximum funding on rollercoasters and thrill rides):
```
context.executeAction("parksetresearchfunding", { "priorities": 12, "fundingAmount": 3 })
```

* Implement staffsetcolour API method
Example usage (set handyman uniforms to orange):
`context.executeAction("staffsetcolour", { "staffType": 0, "colour": 20 })`

* Implement staffsetname API method
Example usage: `context.executeAction("staffsetname", { "staff": map.getAllEntities("staff")[0].id, "name": "Foo Bar" })`

* Implement staffsetorders API method
Example usage (assuming that the first staff member is a handyman: water gardens, empty trash bins):
`context.executeAction("staffsetorders", { "staff": map.getAllEntities("staff")[0].id, "orders": 6 })`

* add myself to contributors.md
@sudofox

sudofox commented Sep 17, 2022

Copy link
Copy Markdown
Author

Hopefully this fixes the commit message check

@duncanspumpkin

Copy link
Copy Markdown
Contributor

Could you add helper enums and such to the ts file so that callers don't need to know what the constants mean. Also you should bump the plug-in api number.

@sudofox

sudofox commented Sep 18, 2022

Copy link
Copy Markdown
Author

Sure thing, I'll need a day or two. Sorry I didn't see this sooner, I didn't get a GitHub notification for some reason.

@Broxzier Broxzier changed the title Expand api method coverage (#1) Expand api method coverage Sep 19, 2022
@Broxzier

Copy link
Copy Markdown
Member

In the future, you can rewrite the git history and force-push to your branch to update the PR. No need to close one and open the next one. Opening multiple of the same PRs is annoying for reviewers.

@sudofox

sudofox commented Sep 19, 2022

Copy link
Copy Markdown
Author

In the future, you can rewrite the git history and force-push to your branch to update the PR. No need to close one and open the next one. Opening multiple of the same PRs is annoying for reviewers.

I apologize for the trouble. I tried to fix the commit history but I kept goofing up git rebase worse and worse so I ended up giving up.

Will look into making the changes requested by @duncanspumpkin soon, thanks for your patience

@Sadret

Sadret commented Sep 27, 2022

Copy link
Copy Markdown
Contributor

We should really update the .d.ts to include the action args types for all actions.

@sudofox

sudofox commented Sep 27, 2022

Copy link
Copy Markdown
Author

We should really update the .d.ts to include the action args types for all actions.

Thanks for the reminder -- I was trying to work on this but was struggling a bit with time/finding examples of how to do it/time to do that. I wouldn't mind a bit of help doing that; otherwise I'll try to get that done sometime next week when I get home from visiting my brother.

@Sadret

Sadret commented Sep 27, 2022

Copy link
Copy Markdown
Contributor

We should really update the .d.ts to include the action args types for all actions.

Thanks for the reminder -- I was trying to work on this but was struggling a bit with time/finding examples of how to do it/time to do that. I wouldn't mind a bit of help doing that; otherwise I'll try to get that done sometime next week when I get home from visiting my brother.

I already have the documentation for all place and remove actions - I use them in Scenery Manager.

@Sadret

Sadret commented Sep 28, 2022

Copy link
Copy Markdown
Contributor

We should really update the .d.ts to include the action args types for all actions.

Thanks for the reminder -- I was trying to work on this but was struggling a bit with time/finding examples of how to do it/time to do that. I wouldn't mind a bit of help doing that; otherwise I'll try to get that done sometime next week when I get home from visiting my brother.

I already have the documentation for all place and remove actions - I use them in Scenery Manager.

https://github.com/Sadret/openrct2-scenery-manager/blob/master/src/definitions/Actions.d.ts
Place Actions: L22-L88
Remove Actions: L104-L143

@sudofox

sudofox commented Oct 6, 2022

Copy link
Copy Markdown
Author

Still struggling to work out what to put for those exactly, so I've just been trying to create types/enums based on the different parameters in the added methods. I'll make a commit soon and see if I'm on the right track.

One of the things I'm struggling with is testing the bitmask operations for different parameters to actually verify that I have things correct, such as staff orders or "same price throughout park" item types in the park. That's partially why I've been hesitant to make a commit, but I guess I'll just do it anyway so this doesn't sit in limbo longer.

@sudofox

sudofox commented Oct 17, 2022

Copy link
Copy Markdown
Author

Is this sorta what is needed?

$ git --no-pager diff
diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts
index ceb687adf..93c3d39cb 100644
--- a/distribution/openrct2.d.ts
+++ b/distribution/openrct2.d.ts
@@ -510,6 +510,86 @@ declare global {
         "waterraise" |
         "watersetheight";
 
+    enum EntertainerCostume {
+        "panda",
+        "tiger",
+        "elephant",
+        "roman",
+        "gorilla",
+        "snowman",
+        "knight",
+        "astronaut",
+        "bandit",
+        "sheriff",
+        "pirate"
+    }
+
+    enum StaffOrders {
+        "sweeping",
+        "water_flowers",
+        "empty_bins",
+        "mowing",
+        "inspect_rides",
+        "fix_rides"
+    }
+
+    type ColourType =
+        "black" |
+        "grey" |
+        "white" |
+        "dark_purple" |
+        "light_purple" |
+        "bright_purple" |
+        "dark_blue" |
+        "light_blue" |
+        "icy_blue" |
+        "teal" |
+        "aquamarine" |
+        "saturated_green" |
+        "dark_green" |
+        "moss_green" |
+        "bright_green" |
+        "olive_green" |
+        "dark_olive_green" |
+        "bright_yellow" |
+        "yellow" |
+        "dark_yellow" |
+        "light_orange" |
+        "dark_orange" |
+        "light_brown" |
+        "saturated_brown" |
+        "dark_brown" |
+        "salmon_pink" |
+        "bordeaux_red" |
+        "saturated_red" |
+        "bright_red" |
+        "dark_pink" |
+        "bright_pink" |
+        "light_pink";
+
+    enum ResearchPriorities {
+        "new_transport_rides",
+        "new_gentle_rides",
+        "new_roller_coasters",
+        "new_thrill_rides",
+        "new_water_rides",
+        "new_shops_and_stalls",
+        "new_scenery_and_theming"
+    }
+
+    type ResearchFunding =
+        "none" |
+        "minimum" |
+        "normal" |
+        "maximum";
+    
+    type ParkParameterType =
+        "close" |
+        "open" |
+        "same_price_in_park";
+
+    
+
     interface GameActionEventArgs {
         readonly player: number;
         readonly type: number;
diff --git a/src/openrct2/scripting/ScriptEngine.h b/src/openrct2/scripting/ScriptEngine.h
index b11cabd1b..1c7bec8c5 100644
--- a/src/openrct2/scripting/ScriptEngine.h
+++ b/src/openrct2/scripting/ScriptEngine.h
@@ -46,7 +46,7 @@ namespace OpenRCT2
 
 namespace OpenRCT2::Scripting
 {
-    static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 60;
+    static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 61;
 
     // Versions marking breaking changes.
     static constexpr int32_t API_VERSION_33_PEEP_DEPRECATION = 33;

I'm not entirely sure if this is what you're asking for. I might switch from enum/type, I guess I'm not sure if I'm putting it in the right spot or anything, but I figured enum would be good since some keys have specific values not in the same order and are used for bitmask logic

@Sadret

Sadret commented Oct 19, 2022

Copy link
Copy Markdown
Contributor

For e.g. the costumes, I would prefer

 enum EntertainerCostume {
    Panda,
    Tiger,
    Elephant,
    Roman,
    Gorilla,
    Snowman,
    Knight,
    Astronaut,
    Bandit,
    Sheriff,
    Pirate,
}

You should use the same approach for the others: The string union type is not helpful at all because the GameAction expects integers and not strings. Also, you must be careful here, because e.g. the research priorities are given by flags. So the enum should be sth like:

enum ResearchCategory {
    Transport = 1 << 0,
    Gentle = 1 << 1,
    Rollercoaster = 1 << 2,
    Thrill = 1 << 3,
    Water = 1 << 4,
    Shop = 1 << 5,
    SceneryGroup = 1 << 6,
}

@tupaschoal

Copy link
Copy Markdown
Member

Hi @sudofox any updates regarding @Sadret 's comments? Also there is a rebase conflict on the PR

@sudofox

sudofox commented Nov 1, 2022

Copy link
Copy Markdown
Author

Hi @sudofox any updates regarding @Sadret 's comments? Also there is a rebase conflict on the PR

I got stuck with testing and writing the enums because I was struggling to test setting flags on certain things -- I wanted to be able to calculate the correct int for bitmask operations from the enums I was trying to write and not getting the expected results.

Since I was working on this, I haven't had a lot of time. I would appreciate it if someone were able to help with that part of it, but otherwise, I'll keep working on it when I have a sec. Thanks for the bump!

@github-actions

github-actions Bot commented Mar 8, 2023

Copy link
Copy Markdown

This pull request is stale and will be closed in 14 days if no action is taken. To keep it open, leave a comment or remove the stale-pr label. If you're awaiting feedback from a developer, please send us a reminder (either here or on Discord).

@Broxzier

Broxzier commented Mar 8, 2023

Copy link
Copy Markdown
Member

Superseded by #18826.

@Broxzier Broxzier closed this Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants