Struct ark_api::applet::Applet

source ·
pub struct Applet {}
Expand description

The applet api gives you access to applet specific functionality, like accessing host events.

Implementations§

source§

impl Applet

source

pub fn input_events(self) -> Vec<EventEnum>

Retrieve all input events for the current (local) player.

source

pub fn input_events_player(self, player_id: PlayerId) -> Vec<EventEnum>

Retrieve all input events for the given player.

source

pub fn window_state(self) -> Option<WindowState>

Retrieve the WindowState data for the current (local) player for the current frame.

Returns None in headless.

source

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.

source

pub fn connected_players(self) -> Vec<PlayerId>

Retrieve the PlayerId of all connected players

source

pub fn game_delta_time(self) -> f32

The time between the last and the current frame (game time, not real_time_since_start time).

source

pub fn game_time(self) -> f64

Returns the game time passed since the module started, in seconds.

source

pub fn real_time_since_start(self) -> f64

Returns the real time in seconds that has passed since the module was started.

source

pub fn set_cursor_mode(self, mode: CursorMode)

Set if the mouse cursor should be visible, hidden or grabbed.

source

pub fn set_cursor_shape(self, shape: CursorShape)

Set the shape and appearance of the mouse cursor.

source

pub fn random_seed_value(self) -> u128

Retrieves a fixed but random value (different each execution of the applet).

source

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.

source

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.

source

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.

Tracked in https://github.com/EmbarkStudios/ark/issues/4491

source

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.

source

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)));
}
source

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.

source

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.

source

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

source

pub fn detach_player(player: PlayerId, parameters: &str) -> DetachPlayerRequest

👎Deprecated: Use updated detach_players instead

Requests to detach a player to another instance of this applet that runs with the given command and arguments.

source

pub fn detach_players( players: &[PlayerId], target: DetachPlayerTarget, bubble: &str ) -> Result<DetachPlayerRequest, DetachPlayerError>

Requests to detach one or more players to another instance of this applet within the given bubble. A bubble can be seen as a filter for the matchmaker. For example if I’m looking for a specific world and provide a bubble string the matchmaker will only look at servers that are tagged with the same bubble string and matchmake within those.

The target specifies where the players should end up. See DetachPlayerTarget for the different options.

source

pub fn notify_finished_hot_reload(is_success: bool)

When a detach player requests causes a hot-reload, indicate that the hot-reload is done and that the applet is in a ready state for further use.

This will panic if there was not hot-reload happening. As such it should only be called after the hot-reload entrypoint has been called and the applet is done performing the hot-reloading steps. It should be called only once per hot-reload request, and it will panic if it’s called multiple times for the same hot-reload request.

source

pub fn get_session_id() -> SessionId

Returns a single session identifier that is the same for all the applet instances detached from the same applet instance root.

Trait Implementations§

source§

impl Clone for Applet

source§

fn clone(&self) -> Applet

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Copy for Applet

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.