//! Turns events of the core into dictionaries that GDScript can read. use godot::prelude::*; use grovewright_core::world::Event; /// One event as a dictionary with a `type` entry and the event's fields. pub fn to_dictionary(event: &Event) -> VarDictionary { match event { Event::PlayerJoined { player } => vdict! { "type" => "player_joined", "player" => i64::from(player.0), }, Event::PlayerLeft { player } => vdict! { "type" => "player_left", "player" => i64::from(player.0), }, Event::JoinRefused { .. } => vdict! { "type" => "join_refused", }, Event::TileHit { player, pos } => vdict! { "type" => "tile_hit", "player" => i64::from(player.0), "x" => i64::from(pos.x), "y" => i64::from(pos.y), }, Event::TileChanged { pos } => vdict! { "type" => "tile_changed", "x" => i64::from(pos.x), "y" => i64::from(pos.y), }, Event::ItemGained { player, item, count, } => vdict! { "type" => "item_gained", "player" => i64::from(player.0), "item" => i64::from(item.0), "count" => i64::from(*count), }, Event::InventoryFull { player } => vdict! { "type" => "inventory_full", "player" => i64::from(player.0), }, } }