logo
pub struct Applet {}
Expand description

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

Implementations

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

Retrieve all input events for the given player.

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

Returns None in headless.

Retrieve the WindowState data for the player for the current frame.

Returns None in headless.

Retrieve the PlayerId of all connected players

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

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

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

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

Set the shape and appearance of the mouse cursor.

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

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.

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.

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

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.

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

Get the module update and physics simulation frequency in Hz. Default is 60 Hz.

Set the module update and physics simulation frequency in Hz. Default is 60 Hz.

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.

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.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.