pub struct Applet {}
Expand description
The applet api gives you access to applet specific functionality, like accessing host events.
Implementations
sourceimpl Applet
impl Applet
sourcepub fn input_events(self) -> Vec<EventEnum>
pub fn input_events(self) -> Vec<EventEnum>
Retrieve all input events for the current (local) player.
sourcepub fn input_events_player(self, player_id: PlayerId) -> Vec<EventEnum>
pub fn input_events_player(self, player_id: PlayerId) -> Vec<EventEnum>
Retrieve all input events for the given player.
sourcepub fn window_state(self) -> Option<WindowState>
pub fn window_state(self) -> Option<WindowState>
Retrieve the WindowState
data for the current (local) player for the current frame.
Returns None
in headless.
sourcepub fn window_state_player(self, player_id: PlayerId) -> Option<WindowState>
pub fn window_state_player(self, player_id: PlayerId) -> Option<WindowState>
Retrieve the WindowState
data for the player for the current frame.
Returns None
in headless.
sourcepub fn connected_players(self) -> Vec<PlayerId>
pub fn connected_players(self) -> Vec<PlayerId>
Retrieve the PlayerId
of all connected players
sourcepub fn game_delta_time(self) -> f32
pub fn game_delta_time(self) -> f32
The time between the last and the current frame (game time, not real_time_since_start
time).
sourcepub fn game_time(self) -> f64
pub fn game_time(self) -> f64
Returns the game time passed since the module started, in seconds.
sourcepub fn real_time_since_start(self) -> f64
pub fn real_time_since_start(self) -> f64
Returns the real time in seconds that has passed since the module was started.
sourcepub fn set_cursor_mode(self, mode: CursorMode)
pub fn set_cursor_mode(self, mode: CursorMode)
Set if the mouse cursor should be visible, hidden or grabbed.
sourcepub fn set_cursor_shape(self, shape: CursorShape)
pub fn set_cursor_shape(self, shape: CursorShape)
Set the shape and appearance of the mouse cursor.
sourcepub fn random_seed_value(self) -> u128
pub fn random_seed_value(self) -> u128
Retrieves a fixed but random value (different each execution of the applet).
sourcepub fn set_clipboard_string(self, string: &str)
pub fn set_clipboard_string(self, string: &str)
Sets the contents of the system clipboard to the supplied string.
NOTE: This doesn’t really have much in the way of security implications, but it can be annoying for the user to get their clipboard contents overridden at any time. Use with care.
sourcepub fn set_player_clipboard_string(self, player_id: PlayerId, string: &str)
pub fn set_player_clipboard_string(self, player_id: PlayerId, string: &str)
Try to set the contents of the system clipboard of the given player to the supplied string.
If there is no such player, this does nothing.
NOTE: This doesn’t really have much in the way of security implications, but it can be annoying for the user to get their clipboard contents overridden at any time. Use with care.
sourcepub fn clipboard_string(self) -> Option<String>
pub fn clipboard_string(self) -> Option<String>
Gets the contents of the system clipboard, if any.
NOTE: The existence of this has serious security implications that we need to work through later. We might need to add limitations like only allowing reading the clipboard after a certain keyboard shortcut, or Paste message, or something similar. Maybe a special permission flag for clipboard access. The clipboard could contain sensitive information so it’s not good to allow just any app to easily sniff it.
sourcepub fn launch_argument(self) -> String
pub fn launch_argument(self) -> String
Gets the launch argument string, if one is available
This can be used to implement module-specific deep-linking to launch a module into a specific mode or action described by a URL parameter
Example
If an applet is launched with the URL https://ark.link/module/cube-simple?cid=zUnGgApwEF8PP4NqxYjHcS8NdxQXzLuc3L5F9DDgGqcc5&arg=THIS%20is%20TEST
this would make this function return THIS is TEST
.
NOTE: Only a single URL parameter named arg
is allowed. Any parameters will be ignored.
sourcepub fn launch_applet_with_url(self, url: &str)
pub fn launch_applet_with_url(self, url: &str)
Launch a module applet from a URL
This will panic if the URL is not a correctly formatted Ark module URL, example valid URLs:
https://ark.link/module/cube-simple?cid=zUnGgApwEF8PP4NqxYjHcS8NdxQXzLuc3L5F9DDgGqcc5&arg=THIS%20is%20TEST
ark://module/cube-simple
Ark will start to load the applet specified in the URL, and if it fails it will prompt the user that. In the meantime the current module will continue to run. There is currently no way for the module itself to know if the other applet module was successfully launched.
Ark will load the latests published module by the given name if no cid
is specified.
Example
Load a module with some argument:
/// Start `module` with the `applet().launch_argument() == arg`
fn launch_module_with_arg(module: &str, arg: &str) {
applet().launch_applet_with_url(format!("ark://module/{}?arg={}", module, percent_encode(arg)));
}
sourcepub fn simulation_rate(&self) -> f64
pub fn simulation_rate(&self) -> f64
Get the module update and physics simulation frequency in Hz. Default is 60 Hz.
sourcepub fn set_simulation_rate(&self, simulation_rate: f64)
pub fn set_simulation_rate(&self, simulation_rate: f64)
Set the module update and physics simulation frequency in Hz. Default is 60 Hz.
sourcepub fn request_quit(self)
pub fn request_quit(self)
Requests that the applet is terminated gracefully.
The module will not quit immediately but will continue running its current update loop.
The host is free to ignore this request, delay it, or ask the user for confirmation.
sourcepub fn broadcast_message(msg: &str, duration: f32)
pub fn broadcast_message(msg: &str, duration: f32)
Broadcasts a message to the entire world, in multiplayer sessions, to be displayed for the specified duration (in milliseconds). This doesn’t show up in single player sessions.
sourcepub fn show_virtual_keyboard(
self,
player_id: PlayerId,
command: VirtualKeyboardCommand
)
pub fn show_virtual_keyboard(
self,
player_id: PlayerId,
command: VirtualKeyboardCommand
)
Request the virtual keyboard to be shown or hidden for the specified player
Key events generated by the virtual keyboard can be retrieved through Applet::input_events_player
Calling this for players on non touch devices will be ignored
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Applet
impl Send for Applet
impl Sync for Applet
impl Unpin for Applet
impl UnwindSafe for Applet
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more