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

Add plugin API to VehicleCrashedParticle #22046

Merged
merged 2 commits into from
May 29, 2024

Conversation

spacek531
Copy link
Contributor

@spacek531 spacek531 commented May 17, 2024

Allows plugins to spawn VehicleCrashedParticles the way cpp code can.

I tested both calling SetupValues from plugin and crashing a regular roller coaster. Everything seemed normal.

@github-actions github-actions bot added the requires dependency Another change should be merged first. label May 17, 2024
@spacek531 spacek531 force-pushed the api/crashed-vehicle-particle branch from f018c0f to ba2bea9 Compare May 17, 2024 15:36
distribution/openrct2.d.ts Outdated Show resolved Hide resolved
distribution/openrct2.d.ts Show resolved Hide resolved
distribution/openrct2.d.ts Outdated Show resolved Hide resolved
src/openrct2/scripting/bindings/world/ScMap.cpp Outdated Show resolved Hide resolved
src/openrct2/scripting/bindings/world/ScMap.cpp Outdated Show resolved Hide resolved
distribution/openrct2.d.ts Outdated Show resolved Hide resolved
@spacek531 spacek531 force-pushed the api/crashed-vehicle-particle branch from 0305f3d to c5d37e9 Compare May 19, 2024 18:02
@spacek531
Copy link
Contributor Author

I have removed the double increment for API version from this PR because #22048 is expanding in scope and not ready for merging, while this PR is ready (after review)

@github-actions github-actions bot removed the requires dependency Another change should be merged first. label May 19, 2024
@spacek531 spacek531 force-pushed the api/crashed-vehicle-particle branch from 51fea0f to a698914 Compare May 25, 2024 22:09
Copy link
Member

@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.

Looks good! Would the string union for the particle type still be possible? 😃

Edit: my test script so far btw.
registerPlugin({
	name: 'Test crash particle',
	version: '1',
	authors: ['Basssiiie'],
	type: 'local',
	licence: 'MIT',
	targetApiVersion: 100,
	main() {
		ui.registerMenuItem("Test crash particle", function()
		{
			ui.activateTool({
				id: "crash-particle",
				cursor: "cross_hair",
				onDown: function(args)
				{
					var coords = args.mapCoords;
					if (!coords) return;
					if (args.tileElementIndex !== undefined)
						coords.z = map.getTile(Math.floor(coords.x/32), Math.floor(coords.y/32)).getElement(args.tileElementIndex).baseZ;

					var particle = map.createEntity("crashed_vehicle_particle", coords);

					function setColour(part, colour)
					{
						var colours = particle.colours;
						console.log(colours);
						colours[part] = colour;
						particle.colours = colours;
					}

					console.log(coords, particle);

					var window = ui.openWindow({
						classification: "test-crash-particle",
						title: "Crash particle",
						width: 210,
						height: 280,
						onUpdate: function()
						{
							if (!particle || particle.type != "crashed_vehicle_particle") return;
							var colour1 = window.findWidget("colour1");
							var colour2 = window.findWidget("colour2");
							var timeToLive = window.findWidget("timeToLive");
							var frame = window.findWidget("frame");
							var velocity = window.findWidget("velocity");
							var acceleration = window.findWidget("acceleration");
							var crashParticleType = window.findWidget("crashParticleType");

							colour1.colour = particle.colours.main; // should be body
							colour2.colour = particle.colours.trim;
							timeToLive.text = String(particle.timeToLive);
							frame.text = String(particle.frame);
							velocity.text = [ particle.velocity.x, particle.velocity.y, particle.velocity.z ].join(', ');
							acceleration.text = [ particle.acceleration.x, particle.acceleration.y, particle.acceleration.z ].join(', ');
							crashParticleType.selectedIndex = particle.crashParticleType;
						},
						widgets: [
							{
								type: "colourpicker",
								name: "colour1",
								x: 5,
								y: 20,
								width: 20,
								height: 20,
								onChange: function(col)
								{
									setColour("main", col) // should be body
								}
							},
							{
								type: "colourpicker",
								name: "colour2",
								x: 25,
								y: 20,
								width: 20,
								height: 20,
								onChange: function(col)
								{
									setColour("trim", col)
								}
							},
							{
								type: "textbox",
								name: "timeToLive",
								x: 5,
								y: 40,
								width: 200,
								height: 15,
								onChange: function(text)
								{
									particle.timeToLive = Number(text);
								}
							},
							{
								type: "textbox",
								name: "frame",
								x: 5,
								y: 60,
								width: 200,
								height: 15,
								onChange: function(text)
								{
									particle.frame = Number(text);
								}
							},
							{
								type: "textbox",
								name: "velocity",
								x: 5,
								y: 80,
								width: 200,
								height: 15,
								onChange: function(text)
								{
									var coords = text.split(',');
									particle.velocity = { x: Number(coords[0]), y: Number(coords[1]), z: Number(coords[2]) };
								}
							},
							{
								type: "textbox",
								name: "acceleration",
								x: 5,
								y: 100,
								width: 200,
								height: 15,
								onChange: function(text)
								{
									var coords = text.split(',');
									particle.acceleration = { x: Number(coords[0]), y: Number(coords[1]), z: Number(coords[2]) };
								}
							},
							{
								type: "dropdown",
								name: "crashParticleType",
								x: 5,
								y: 120,
								width: 200,
								height: 15,
								items: [ "Particle 0", "Particle 1", "Particle 2", "Particle 3", "Particle 4" ],
								onChange: function(index)
								{
									particle.crashParticleType = index;
								}
							},
							{
								type: "button",
								x: 5,
								y: 140,
								width: 200,
								height: 15,
								text: "Launch",
								onClick: function() { particle.launch({ main: 0, trim: 1, tertiary: 2 })} // should be body
							},
						]
					})
				}
			})
		});
	},
});

src/openrct2/scripting/bindings/entity/ScParticle.cpp Outdated Show resolved Hide resolved
@spacek531 spacek531 force-pushed the api/crashed-vehicle-particle branch from 83a5e8c to 12ac882 Compare May 27, 2024 17:51
Copy link
Member

@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.

Tested it again and LGTM!

Co-authored-by: Michael Steenbeek <1478678+Gymnasiast@users.noreply.github.com>
@Gymnasiast Gymnasiast merged commit 94750f4 into OpenRCT2:develop May 29, 2024
22 checks passed
@tupaschoal tupaschoal added this to the v0.4.12 milestone May 29, 2024
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.

None yet

4 participants