-
Notifications
You must be signed in to change notification settings - Fork 1
simple particle support in panda #14
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| use panda::{ | ||
| parse::token::Span, | ||
| runtime::RuntimeError, | ||
| }; | ||
| use crate::{ | ||
| particle, | ||
| particle::Particle, | ||
| }; | ||
| use bb_server_macros::define_ty; | ||
| use crate::plugin::types::util::PFPos; | ||
| use std::str::FromStr; | ||
|
|
||
| #[define_ty] | ||
| impl PParticle { | ||
| info! { | ||
| wrap: Particle, | ||
|
|
||
| panda: { | ||
| path: "bamboo::particle::Particle", | ||
| }, | ||
| } | ||
|
|
||
| pub fn new(name: &str, pos: &PFPos, force: bool, offset: &PFPos, count: u32, data: f32) -> Result<Self, RuntimeError> { | ||
| Ok(PParticle { | ||
| inner: Particle { | ||
| ty: particle::Type::from_str(name) | ||
| .map_err(|e| RuntimeError::Custom(e.to_string(), Span::call_site()))?, | ||
| pos: pos.inner, | ||
| long_distance: force, | ||
| offset: offset.inner, | ||
| count, | ||
| data, | ||
| }, | ||
| }) | ||
| } | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| use bamboo::{ | ||
| particle, | ||
| util, | ||
| } | ||
|
|
||
| on init() { | ||
| bamboo::info("owo") | ||
| } | ||
|
|
||
| on interact(event, flow) { | ||
| let player = event.player | ||
| let world = @bamboo.default_world() | ||
|
|
||
| let particle = particle::Particle::new( | ||
| "witch", | ||
| player.pos(), | ||
| true, | ||
| util::FPos::new(0.0, 0.0, 0.0), | ||
| 100, | ||
| 0.0, | ||
| ) | ||
|
Comment on lines
+14
to
+21
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dislike having a function take 6 arguments. I think using a builder like this would be clearer: particle::Particle::builder("witch", player.pos())
.long_distance(true)
.velocity(0.0, 0.0, 0.0)
.amount(100)
.data(0.0)
.build()plus, the builder can have some defaults, so you don't need to set everything: particle::Particle::builder("witch", player.pos())
.long_distance(true)
.amount(100)
.build() |
||
|
|
||
| world.spawn_particle(particle) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| type = "panda" | ||
| enabled = true |
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.
all the fields are public, no need for a constructor. Forcing users to use struct literals is also clearer, as you can see the field names.
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.
the constructor is still here. forgot to push maybe?