basic documentation for SchemaPiston

master
Ales Katona 6 years ago
parent 4ec29fa0a6
commit 5e72662e94
Signed by: almindor
GPG Key ID: 08C459E2D8ABB7E8

@ -12,35 +12,46 @@ where TUserAction: Clone + Serialize,
schema: Schema<Event, usize, TUserAction>, schema: Schema<Event, usize, TUserAction>,
} }
/// Schema implementation using the Piston backend
impl<TUserAction> SchemaPiston<TUserAction> impl<TUserAction> SchemaPiston<TUserAction>
where TUserAction: Clone + Serialize, where TUserAction: Clone + Serialize,
{ {
/// Create a new Schema with given name
pub fn new(name: &str) -> Self { pub fn new(name: &str) -> Self {
SchemaPiston { SchemaPiston {
schema: Schema::new(name) schema: Schema::new(name)
} }
} }
/// Assigns assigns the controller from next registered input event
/// to this schema if it passes through the input flags
pub fn assign_controller(&mut self, event: &Event, iaf: InputTypeFlags) -> bool { pub fn assign_controller(&mut self, event: &Event, iaf: InputTypeFlags) -> bool {
self.schema.assign_controller(event, iaf) self.schema.assign_controller(event, iaf)
} }
/// Assigns specified user action to the next registered event from piston
pub fn assign_input(&mut self, event: &Event, action: TUserAction, iaf: InputTypeFlags) -> bool { pub fn assign_input(&mut self, event: &Event, action: TUserAction, iaf: InputTypeFlags) -> bool {
self.schema.assign_input(event, action, iaf) self.schema.assign_input(event, action, iaf)
} }
/// Main event processing hook. Will result in ProcessingResult for user's action if
/// a mapping is withing the schema for the given event.
pub fn process_event(&mut self, event: &Event) -> Option<ProcessingResult<TUserAction>> { pub fn process_event(&mut self, event: &Event) -> Option<ProcessingResult<TUserAction>> {
self.schema.process_event(event) self.schema.process_event(event)
} }
/// Assigns a player_id to this schema
pub fn set_player_id(&mut self, player_id: Option<usize>) { pub fn set_player_id(&mut self, player_id: Option<usize>) {
self.schema.set_player_id(player_id); self.schema.set_player_id(player_id);
} }
/// Returns the current player_id (or None if not assigned)
pub fn player_id(&self) -> Option<usize> { pub fn player_id(&self) -> Option<usize> {
self.schema.player_id self.schema.player_id
} }
/// Returns the currently assigned controller (or None if not assigned)
/// *NOTE* keyboard and mouse have no controller ID by definition in piston
pub fn controller_id(&self) -> Option<usize> { pub fn controller_id(&self) -> Option<usize> {
self.schema.controller_id self.schema.controller_id
} }

Loading…
Cancel
Save