Skip to content
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

Feature: Allow vehicle dragger tool to snap vehicles to track #124

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

guysv
Copy link
Contributor

@guysv guysv commented Oct 20, 2024

To my understanding this is useful for shoestringing

demo:
https://github.com/user-attachments/assets/8a1e764e-b0d6-4c17-95ce-7973902d3a7f

@guysv guysv force-pushed the vehicle-dragger-snap-to-track-3 branch from a9c7b2b to 339c41b Compare October 20, 2024 16:53
Copy link
Owner

@Basssiiie Basssiiie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR! This one was a bit harder to review but I think it can be optimized a bit before I'd like to merge it.🙂

readonly _spacing = store<number | null>(0);
readonly _x = store<number>(0);
readonly _y = store<number>(0);
readonly _z = store<number>(0);
readonly _xyz = compute(this._x, this._y, this._z, (x, y, z) => { return {x, y, z}; });
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's necessary to introduce a new store for this, there's already the separate available stores and I prefer not to add memory and computing usage if it's not strictly necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. will fix.

state: DragState;
}

/**
* Get a possible position to drag the vehicle to.
*/
function getPositionFromTool(args: ToolEventArgs, vehicleType: RideObjectVehicle | null): CoordsXYZ | null
function getPositionFromTool(args: ToolEventArgs, vehicleType: RideObjectVehicle | null, currentId: number): [CoordsXYZ | null, CarTrackLocation | null]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to make this return type a single object with all the required fields, instead of a tuple with two different objects and some duplicate fields? 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure will fix.

} else {
// internally, travelBy calls MoveTo so the car will render on the holding
// track
// HACK: seems to make the vehicle update render properly
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please no hacks here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a new scripting API for it. something like Car.redraw()

Copy link
Owner

@Basssiiie Basssiiie Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm it sounds more like setting the track location property should just invalidate/redraw the vehicle on the cpp side. Such a fix could also be done/merged separately without having to put this PR in a wait for a new API. 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umm I still think the hack is needed though. for now at least. Having the vehicle render in the wrong place can be unpleasent to use.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to just travelBy once without the getDestination method?

car.travelBy(1);

Or possibly with 0 instead of 1 if that works too.

@@ -84,25 +112,33 @@ const enum DragState
Cancel
}

interface DragPosition
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this can be merged with DragVehicleArgs as well with reducing all duplicate fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right. mb.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is now embedded within DragVehicleArgs. I still needed DragPosition to be stand alone to keep away from adding alot of new code to getPositionFromTool

@guysv guysv force-pushed the vehicle-dragger-snap-to-track-3 branch from 339c41b to 4e32721 Compare December 7, 2024 19:55
@guysv guysv force-pushed the vehicle-dragger-snap-to-track-3 branch 4 times, most recently from 46a2634 to 15eba54 Compare December 9, 2024 19:07
@Basssiiie Basssiiie force-pushed the vehicle-dragger-snap-to-track-3 branch from 278f4ea to b58edab Compare December 15, 2024 16:00
Copy link
Owner

@Basssiiie Basssiiie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I'll merge it after OpenRCT2/OpenRCT2#23359 is completed and merged. 🙂

@guysv guysv force-pushed the vehicle-dragger-snap-to-track-3 branch from b58edab to 16a0236 Compare January 1, 2025 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants