OpenRCT2 icon indicating copy to clipboard operation
OpenRCT2 copied to clipboard

Added additional stats to Plugin interface

Open AT41 opened this issue 1 year ago ā€¢ 27 comments

AT41 avatar Jul 02 '23 13:07 AT41

I'd rather see the getters throw when ride is null, instead of returning a magic number. This can be done later in another PR, just please create an issue for it if you decide to leave it for now.

Please increment the API version, then this is good to go.

I think the error handling should be changed in this PR already, that's quite the different behavior.

ZehMatt avatar Jul 03 '23 12:07 ZehMatt

I think the error handling should be changed in this PR already, that's quite the different behavior.

It's not different from the current behaviour. The existing ride properties don't throw on null either, so it needs to be done for all the other ride properties too, then.

Broxzier avatar Jul 03 '23 12:07 Broxzier

I think the error handling should be changed in this PR already, that's quite the different behavior.

It's not different from the current behaviour. The existing ride properties don't throw on null either, so it needs to be done for all the other ride properties too, then.

Fair point.

ZehMatt avatar Jul 03 '23 14:07 ZehMatt

API incremented, modified return values so that they can be formatted through {VELOCITY} and {LENGTH}. Will make a new issue for throwing exceptions for getters rather than returning 0 once PR is accepted.

AT41 avatar Jul 06 '23 08:07 AT41

About the formatting comments: First, I think it is cluttering the documentation. In my opinion we do not need to cross-reference every function that might be useful in some context. Second, formatString does not "convert to kph" but to a string representation of a localised value and unit. Plugin developers should code in a way that is independent of the actual units. formatString should not be used to convert internal units to some other units that the dev prefers to work with. The documentation should be clear to not suggest that.

All in all, my proposal is to improve the formatString documentation instead (separate PR).

StephanSpengler avatar Jul 21 '23 15:07 StephanSpengler

This pull request has been marked as 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).

github-actions[bot] avatar Aug 26 '23 01:08 github-actions[bot]

Please keep open.

Basssiiie avatar Aug 26 '23 10:08 Basssiiie

This pull request has been marked as 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).

github-actions[bot] avatar Sep 28 '23 01:09 github-actions[bot]

Again, please keep this one open.

SpartanFrederic104 avatar Sep 28 '23 02:09 SpartanFrederic104

@AT41 are you planning to continue this PR?

ZehMatt avatar Sep 28 '23 14:09 ZehMatt

Are there still any unresolved issues? It seems @Sadret's last comment was addressed in the commit after it, without another comment on the PR.

Basssiiie avatar Sep 28 '23 16:09 Basssiiie

Sorry, been busy but I'll see this PR through to the end!

All the requests should be resolved in the latest version - I'll add a new issue for throwing exceptions for null rides. Comments should also be good unless @Sadret has any further suggestions.

There's a CI/CD error that's failing after I implemented the extra enum for formatting, but unless there's a specific reason for those enum values to be set to those values the tests just need to be adjusted. OpenRCT2\test\tests\FormattingTests.cpp(46): error: Expected equality of these values: "[29:{BLACK}][1:Guests: ][8:{INT32}]" actual Which is: "[30:{BLACK}][1:Guests: ][8:{INT32}]"

Let me know if there's anything else that's needed on my end, thanks!

AT41 avatar Sep 29 '23 01:09 AT41

There's a CI/CD error that's failing after I implemented the extra enum for formatting, but unless there's a specific reason for those enum values to be set to those values the tests just need to be adjusted. OpenRCT2\test\tests\FormattingTests.cpp(46): error: Expected equality of these values: "[29:{BLACK}][1:Guests: ][8:{INT32}]" actual Which is: "[30:{BLACK}][1:Guests: ][8:{INT32}]"

Let me know if there's anything else that's needed on my end, thanks!

It would be good if you can change the tests if they need adjustments.

ZehMatt avatar Sep 30 '23 21:09 ZehMatt

Ready for another review @Sadret @Broxzier

AT41 avatar Oct 10 '23 02:10 AT41

Time for another review :)

AT41 avatar Oct 24 '23 01:10 AT41

@Broxzier, @Sadret and @Basssiiie would you give this another review, please?

tupaschoal avatar Nov 12 '23 13:11 tupaschoal

Seems to be an error on the mingw build, can you check @AT41 ?

tupaschoal avatar Nov 16 '23 02:11 tupaschoal

@Broxzier Everything seems to be good to go. Added a new issue as you suggested earlier: https://github.com/OpenRCT2/OpenRCT2/issues/20994. I can squash commits myself, unless PRs get squashed automatically?

Let me know if there's anything else needed

AT41 avatar Nov 20 '23 01:11 AT41

This pull request has been marked as 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).

github-actions[bot] avatar Dec 21 '23 01:12 github-actions[bot]

@AT41 can you add a changelog entry for this, please?

tupaschoal avatar Dec 23 '23 14:12 tupaschoal

Needs updating for the changelog.

Gymnasiast avatar Dec 31 '23 20:12 Gymnasiast

I think this pull request is to support new features in the StatRequirementChecklist plugin.

You may want to coordinate with pull request #20913, which I think has a similar goal in mind.

I think that PR would let you read the requirements from the native openrct2 code, so you wouldn't need to hard-code them in the plugin.

pfroud avatar Jan 02 '24 02:01 pfroud

I've tested the implementation and while most of it looks great and correct, I ran into two issues;

  • The formatted height string of the highest drop height seems to be off by one in some rare cases, like with the Giga Coaster in Six Flags Holland and this blue coaster I built (it's not launched so it doesn't make a full lap).
  • I cannot figure out what the "powered lifts" are supposed to refer to. For some rides it's 0 and for some it's 64 (which is either incorrect or simply a flag instead of a number?):

image image

On other rides everything seems right:

image

Click here to see my plugin script in case anyone would like to test it for themselves. šŸ™‚
registerPlugin({
	name: "Test for ride stats",
	version: "1",
	authors: ['Basssiiie'],
	targetApiVersion: 82,
	type: "local",
	licence: "MIT",
	main() {
		ui.registerMenuItem("Check ride stats", function() {
			var dropdownName = "test-ride-stats-dropdown";
			var listName = "test-ride-stats-list";
			var rides = map.rides.sort(function(a,b){return a.name.localeCompare(b.name)});
			var window = ui.openWindow({
				classification: "test-ride-stats",
				title: "Ride stats",
				width: 300,
				height: 220,
				widgets: [
					{
						type: "listview",
						name: listName,
						showColumnHeaders: true,
						isStriped: true,
						columns: [
							{ header: "Property", width: 150 },
							{ header: "Raw", width: 40 },
							{ header: "Real", width: 80 },
						],
						items: [],
						x: 5,
						y: 20,
						width: 290,
						height: 170,
					},
					{
						type: "dropdown",
						name: dropdownName,
						x: 5,
						y: 200,
						width: 290,
						height: 15,
						items: rides.map(function(r){return r.name})
					},
				],
				onUpdate()
				{
					var dropdown = window.findWidget(dropdownName);
					var ride = rides[dropdown.selectedIndex];
					if (!ride) return;

					var list = window.findWidget(listName);
					list.items = [
						[ "Max speed:", String(ride.maxSpeed), context.formatString('{VELOCITY}', ride.maxSpeed) ],
						[ "Average speed:", String(ride.averageSpeed), context.formatString('{VELOCITY}', ride.averageSpeed) ],
						[ "Ride time:", String(ride.rideTime), context.formatString('{DURATION}', ride.rideTime) ],
						[ "Ride length:", String(ride.rideLength), context.formatString('{LENGTH}', ride.rideLength) ],
						[ "Max positive vertical Gs:", String(ride.maxPositiveVerticalGs), "" ],
						[ "Max negative vertical Gs:", String(ride.maxNegativeVerticalGs), "" ],
						[ "Max lateral Gs:", String(ride.maxLateralGs), "" ],
						[ "Total air time:", String(ride.totalAirTime), "" ],
						[ "Drops:", String(ride.drops), "" ],
						[ "Powered lifts:", String(ride.poweredLifts), "" ],
						[ "Highest drop height (raw):", String(ride.highestDropHeight), context.formatString('{HEIGHT}', ride.highestDropHeight) ]
					];
				}
			})
		})
	}
});

Basssiiie avatar Jan 02 '24 19:01 Basssiiie

Fixed the bug with height and powered lifts. The bit logic on height caused precision to be lost, but the new calculations should fix that. Powered lift values are combined with number of drops in a byte but I didn't truncate off the trailing 0s, so that should be fixed as well

AT41 avatar Jan 08 '24 01:01 AT41

@tupaschoal Yes, Iā€™d like to do another round.

Gymnasiast avatar Jan 10 '24 22:01 Gymnasiast

This pull request has been marked as 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).

github-actions[bot] avatar Mar 04 '24 01:03 github-actions[bot]

@Gymnasiast Is there anything blocking this PR?

AT41 avatar Mar 05 '24 04:03 AT41