Struct ExternalEditorApi

Source
pub struct ExternalEditorApi {
    pub listener: TcpListener,
}
Expand description

A struct representing Tabletop Simulators External Editor API.

Fields§

§listener: TcpListener

TcpListener used for listening to incoming messages

Implementations§

Source§

impl ExternalEditorApi

Source

pub fn get_scripts(&self) -> Result<AnswerReload>

Get a list containing the states for every object. Returns an AnswerReload message on success. If no connection to the game can be established, an io::Error gets returned instead.

Source

pub fn reload(&self, script_states: Value) -> Result<AnswerReload>

Update the Lua scripts and UI XML for any objects listed in the message, and then reloads the save file, the same way it does when pressing “Save & Play” within the in-game editor. Returns an AnswerReload message. If no connection to the game can be established, an io::Error gets returned instead.

Any objects mentioned have both their Lua script and their UI XML updated. If no value is set for either the “script” or “ui” key then the corresponding Lua script or UI XML is deleted.

Source

pub fn custom_message(&self, message: Value) -> Result<()>

Send a custom message to be forwarded to the onExternalMessage event handler in the currently loaded game. The value of customMessage must be an object, and is passed as a parameter to the event handler. If no connection to the game can be established, an io::Error gets returned.

If this value is not an object then the event is not triggered.

Source

pub fn execute(&self, script: String) -> Result<AnswerReturn>

Executes a lua script globally and returns the value in a AnswerReturn message. If no connection to the game can be established, an io::Error gets returned instead.

Source

pub fn execute_on_object( &self, script: String, guid: String, ) -> Result<AnswerReturn>

Executes a lua script on an object and returns the value in a AnswerReturn message. If no connection to the game can be established, an io::Error gets returned instead.

To execute Lua code for an object in the game that object must have an associated script in TTS. Otherwise the TTS scripting engine will fail with an error “function <executeScript>: Object reference not set to an instance of an object”. Once the in-game editor shows a script associated with an object then TTS will be able to execute Lua code sent via JSON message for that object.

Source§

impl ExternalEditorApi

Source

pub fn new() -> Self

Creates a new ExternalEditorApi struct and binds the TcpListener to its socket address.

Source

pub fn send(&self, message: Message) -> Result<()>

Sends a Message in a TcpStream. If no connection to the game can be established, an io::Error gets returned.

Source

pub fn read(&self) -> Answer

Accepts the next incoming Answer from the listener and deserializes it. This function will block the calling thread until a new TCP connection is established and an answer gets received.

Source

pub fn read_string(&self) -> String

Accepts the next incoming Answer from the listener as a String. This function will block the calling thread until a new TCP connection is established and an answer gets received.

Source

pub fn wait<T: TryFrom<Answer>>(&self) -> T

Reads incoming Answer messages until an answer matches the generic. This function will block the calling thread until a new TCP connection is established and an answer gets received.

Trait Implementations§

Source§

impl Debug for ExternalEditorApi

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ExternalEditorApi

Creates a new ExternalEditorApi struct and binds the TcpListener to its socket address. This is functionally the same as using ExternalEditorApi::new().

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.