From 7262cfc53b4af978d6db1b91e3143200f906587f Mon Sep 17 00:00:00 2001 From: troido Date: Sun, 23 Feb 2020 01:18:17 +0100 Subject: rooms have named locations to be used by portals --- content/maps/broom.json | 5 ++++- content/maps/room.json | 2 +- src/components/mod.rs | 15 +++++++++++---- src/componentwrapper.rs | 13 +++++++++++-- src/defaultencyclopedia.rs | 4 ++-- src/playerstate.rs | 14 +++++++++++++- src/resources/mod.rs | 5 +++-- src/room.rs | 19 ++++++++++++++----- src/roomtemplate.rs | 14 +++++++++++--- src/systems/migrate.rs | 2 +- src/world.rs | 11 ++++++----- 11 files changed, 77 insertions(+), 27 deletions(-) diff --git a/content/maps/broom.json b/content/maps/broom.json index f6044a6..c9f3762 100644 --- a/content/maps/broom.json +++ b/content/maps/broom.json @@ -1,7 +1,10 @@ { "width": 42, "height": 23, - "spawn": [5, 5], + "spawn": [5, 15], + "places": { + "northentry": [6, 1] + }, "field": [ " %%% ", "XXXXX,.,XXXXXXXXXX~~~XXXXXXXXXXXXXXXXXXXXX", diff --git a/content/maps/room.json b/content/maps/room.json index 5631b24..4bfd923 100644 --- a/content/maps/room.json +++ b/content/maps/room.json @@ -40,7 +40,7 @@ "X": "rock", "*": ["grass", "pebble"], "o": ["grass", "stone"], - "%": {"type": "portal", "kwargs": {"destination": "broom"}}, + "%": {"type": "portal", "kwargs": {"destination": "broom", "dest_pos": "northentry"}}, " ": [] } } diff --git a/src/components/mod.rs b/src/components/mod.rs index 459590b..682af65 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -11,9 +11,15 @@ use specs::{ Component }; -use crate::{Pos, PlayerId, RoomId, Sprite}; -use crate::controls::Control; -use crate::template::Template; +use crate::{ + Pos, + PlayerId, + RoomId, + Sprite, + controls::Control, + template::Template, + playerstate::RoomPos +}; #[derive(Debug, Clone)] pub struct Position{ @@ -100,5 +106,6 @@ pub struct Serialise { #[derive(Component, Debug, Clone)] pub struct RoomExit { - pub destination: RoomId + pub destination: RoomId, + pub dest_pos: RoomPos } diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs index fb2a80a..27e0783 100644 --- a/src/componentwrapper.rs +++ b/src/componentwrapper.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use specs::Builder; -use crate::{PlayerId, RoomId, Sprite}; +use crate::{PlayerId, RoomId, Sprite, playerstate::RoomPos}; use crate::components::{Visible, Blocking, Player, Floor, Item, Inventory, Health, Serialise, RoomExit}; use crate::parameter::{Parameter, ParameterType}; @@ -98,7 +98,16 @@ components!( Inventory (capacity: Int) {Inventory{items: Vec::new(), capacity: capacity as usize}}; Health (health: Int, maxhealth: Int) {Health{health, maxhealth}}; Serialise (template: Template) {Serialise{template}}; - RoomExit (destination: String) {RoomExit{destination: RoomId::from_str(&destination)}}; + RoomExit (destination: String, dest_pos: String) { + RoomExit { + destination: RoomId::from_str(&destination), + dest_pos: if dest_pos.is_empty() { + RoomPos::Unknown + } else { + RoomPos::Name(dest_pos) + } + } + }; ); diff --git a/src/defaultencyclopedia.rs b/src/defaultencyclopedia.rs index 260c5f7..7179989 100644 --- a/src/defaultencyclopedia.rs +++ b/src/defaultencyclopedia.rs @@ -112,9 +112,9 @@ pub fn default_encyclopedia() -> Encyclopedia { ] }, "portal": { - "arguments": [["destination", "string", null]], + "arguments": [["destination", "string", null], ["dest_pos", "string", ""]], "components": [ - ["RoomExit", {"destination": ["arg", "destination"]}], + ["RoomExit", {"destination": ["arg", "destination"], "dest_pos": ["arg", "dest_pos"]}], "Floor" ] }, diff --git a/src/playerstate.rs b/src/playerstate.rs index ff9565b..8e3d99f 100644 --- a/src/playerstate.rs +++ b/src/playerstate.rs @@ -10,25 +10,35 @@ use crate::{ Result, aerr, Sprite, - Encyclopedia + Encyclopedia, + Pos }; #[derive(Debug, Clone)] pub struct PlayerState { pub id: PlayerId, pub room: Option, + pub pos: RoomPos, pub inventory_capacity: usize, pub inventory: Vec