//public void createTileAtMousePos(Vector3 mousePos, SpriteLayer layer, int type) {
 //    var tileInstance = TileSpriteManager.Instance.GetInstance(type, layer, mousePos);
 //    currentLevel.layers[layer].SetValue(Vector2int.FromVector2(mousePos), (byte)(type + 1));
 //    resources.Add(tileInstance);
 //}
 public void createTileAtMousePos(Vector3 mousePos, SpriteLayer layer, string type)
 {
     var tileInstance = TileSpriteManager.Instance.GetInstance(type, layer, mousePos);
     int id = TileSpriteManager.Instance.GetIDForName(type, layer) + 1;
     currentLevel.layers[layer].SetValue(Vector2int.FromVector2(mousePos), (byte)(id + 1));
     resources.Add(tileInstance);
 }
Ejemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        layer = (SpriteLayer)0;
        Index = 0;

        CollisionMap2D.Instance.SetVisualsEnabled(true);
    }
Ejemplo n.º 3
0
        public RemoveSpriteCommand(SpriteLayer spriteLayer, Coordinate coordinate)
        {
            spriteLayer.ThrowIfNull("spriteLayer");

            _spriteLayer = spriteLayer;
            _coordinate = coordinate;
        }
        public SetSpriteCommand(SpriteLayer spriteLayer, Sprite sprite)
        {
            spriteLayer.ThrowIfNull("spriteLayer");
            sprite.ThrowIfNull("sprite");

            _spriteLayer = spriteLayer;
            _sprite = sprite;
        }
Ejemplo n.º 5
0
 public TileMap2D(SpriteLayer ly, string ln, bool autoSave = true)
     : this(autoSave)
 {
     levelname = ln;
     layer = ly;
     if (AutoSave) {
         maps = MapLoader2D.LoadAll(layer, levelname);
     }
 }
Ejemplo n.º 6
0
 public void NewLayer(int x, int y, int size)
 {
     SpriteLayer newLayer = new SpriteLayer();
     newLayer.source = baseSheet;
     newLayer.x = x;
     newLayer.y = y;
     newLayer.size = size;
     layers.Add(newLayer);
 }
Ejemplo n.º 7
0
 public GameObject GetInstance(int id, SpriteLayer layer, Vector2 position)
 {
     var tileInstance = Instantiate(prefab);
     tileInstance.transform.parent = tileParent;
     tileInstance.GetComponent<SpriteRenderer>().sprite = GetSprite(id, layer);
     tileInstance.GetComponent<SpriteRenderer>().sortingLayerName = layer.ToString();
     tileInstance.transform.position = position;
     return tileInstance;
 }
Ejemplo n.º 8
0
    public static string TileDirectoryPath(SpriteLayer layer, string levelname)
    {
        string path = LevelsDirectoryPath + levelname + "/" + layer + "/";

        if (!Directory.Exists(path)) {
            Directory.CreateDirectory(path);
        }

        return path;
    }
Ejemplo n.º 9
0
 public SpriteLayer GetLayer(string mat, Color color )
 {
     foreach(SpriteLayer layer in LayerCache)
     {
         if (layer.Equals(mat, color))
             return layer;
     }
     SpriteLayer l = new SpriteLayer(mat, color);
     LayerCache.Add(l);
     return l;
 }
        public XElement Serialize(SpriteLayer spriteLayer, string elementName = "spriteLayer")
        {
            spriteLayer.ThrowIfNull("spriteLayer");
            elementName.ThrowIfNull("elementName");

            return new XElement(
                elementName,
                spriteLayer.Sprites.Select(arg => SpriteSerializer.Instance.Serialize(arg)),
                new XAttribute("boardId", spriteLayer.BoardId),
                new XAttribute("size", SizeSerializer.Instance.Serialize(spriteLayer.Size)));
        }
Ejemplo n.º 11
0
 public static byte[] Load(Vector2int mapLocation, SpriteLayer layer, string levelname)
 {
     if (File.Exists(TileDirectoryPath(layer, levelname) + mapLocation)) {
         string s;
         using (var reader = new StreamReader(TileDirectoryPath(layer, levelname) + mapLocation)) {
             s = reader.ReadLine();
         }
         return s.ConvertHexToByteArray();
     }
     else {
         return null;
     }
 }
Ejemplo n.º 12
0
    public static Dictionary<Vector2int, byte[]> LoadAll(SpriteLayer l, string levelname)
    {
        //create dictionary for layer l
        var dict = new Dictionary<Vector2int, byte[]>();

        //load each tile in layer l and place in dictionary
        foreach (var file in Directory.GetFiles(TileDirectoryPath(l, levelname))) {
            var name = Path.GetFileName(file);
            var stringSplit = name.Replace("(", "").Replace(")", "").Split(',');
            var vec = new Vector2int(int.Parse(stringSplit[0]), int.Parse(stringSplit[1]));
            dict[vec] = Load(vec, l, levelname);
        }
        return dict;
    }
Ejemplo n.º 13
0
 public Sprite[] GetAllSprites(SpriteLayer layer)
 {
     //if (layer == 0) {
     //    sprites = pathSprites.Values.Select(e => e.Sprite).ToArray();
     //} else if (layer == 1) {
     //    sprites = buildingSprites;
     //} else if (layer == 2) {
     //    sprites = doorSprites;
     //} else {
     //    sprites = envirSprites;
     //}
     return (from s in GetSpriteDataForLayer(layer)
             orderby s.Value.Index
             select s.Value.Sprite).ToArray();
 }
Ejemplo n.º 14
0
        public void AddSprite(Sprite s, Int32 x, Int32 y, float t, bool additive)
        {
            // shift into object space
              const Int32 MidPoint = (Constants.RoomSize * Constants.TileSize) / 2;
              x = (-MidPoint + (Constants.TileSize / 2)) + x;
              y = (MidPoint - (Constants.TileSize / 2)) - (y - Constants.TileSize);

              SpriteLayer sl = new SpriteLayer();
              sl.uid = s.getUID();
              sl.x = (byte)x;
              sl.y = (byte)y;
              sl.trans = (byte)(t * 255.0f);
              sl.glow = (byte)(additive ? 1 : 0);

              layers.Add(sl);
        }
Ejemplo n.º 15
0
		public TextGisLayer(Game game, int capacity, GlobeCamera camera) : base(game)
		{
			GlobeCamera		= camera;
			TextSpriteLayer = new SpriteLayer(Game.RenderSystem, 2048);

			GeoTextArray		= new GeoText[capacity];
			LinesCountToDraw	= capacity;
			Font				= Game.Content.Load<DiscTexture>("conchars");
			//spriteFont		= Game.Content.Load<SpriteFont>(@"Fonts\textFont");

			MinZoom = 6380;
			MaxZoom = 6500;

			Scale		= 1.0f;
			MaxScale	= 1.5f;
		}
Ejemplo n.º 16
0
        public Board(
			Guid id,
			string name,
			string description,
			Size size,
			SpriteLayer backgroundLayer,
			SpriteLayer foregroundLayer,
			ActorInstanceLayer actorInstanceLayer,
			IEnumerable<BoardExit> exits,
			IEnumerable<Timer> timers,
			EventHandlerCollection eventHandlerCollection = null)
        {
            name.ThrowIfNull("name");
            description.ThrowIfNull("description");
            backgroundLayer.ThrowIfNull("backgroundLayer");
            foregroundLayer.ThrowIfNull("foregroundLayer");
            actorInstanceLayer.ThrowIfNull("actorInstanceLayer");
            exits.ThrowIfNull("exits");
            timers.ThrowIfNull("timers");

            if (backgroundLayer.BoardId != id)
            {
                throw new ArgumentException("Background layer must belong to board.", "backgroundLayer");
            }
            if (foregroundLayer.BoardId != id)
            {
                throw new ArgumentException("Foreground layer must belong to board.", "backgroundLayer");
            }
            if (actorInstanceLayer.BoardId != id)
            {
                throw new ArgumentException("Actor instance layer must belong to board.", "backgroundLayer");
            }

            _id = id;
            Name = name;
            Description = description;
            _size = size;
            _backgroundLayer = backgroundLayer;
            _foregroundLayer = foregroundLayer;
            _actorInstanceLayer = actorInstanceLayer;
            _exits = exits;
            _timers = timers;
            _eventHandlerCollection = eventHandlerCollection;
        }
        public byte[] Serialize(SpriteLayer spriteLayer)
        {
            spriteLayer.ThrowIfNull("spriteLayer");

            var serializer = new CompactSerializer();

            serializer[0] = spriteLayer.BoardId.ToByteArray();
            serializer[1] = SizeSerializer.Instance.Seralize(spriteLayer.Size);

            var spriteSerializer = new CompactSerializer();
            int index = 0;

            foreach (Sprite sprite in spriteLayer.Sprites)
            {
                spriteSerializer[index++] = SpriteSerializer.Instance.Serialize(sprite);
            }

            serializer[2] = spriteSerializer.Serialize();

            return serializer.Serialize();
        }
Ejemplo n.º 18
0
 public static void Save(Vector2int mapLocation, byte[] bytes, SpriteLayer layer, string levelname)
 {
     using (var writer = new StreamWriter(TileDirectoryPath(layer, levelname) + mapLocation.ToString())) {
         writer.WriteLine(bytes.ConvertToHexString());
     }
 }
Ejemplo n.º 19
0
 public int GetListLength(SpriteLayer layer)
 {
     //if (layer == 0) {
     //    return pathSprites.Count;
     //} else if (layer == 1) {
     //    return buildingSprites.Length;
     //} else if (layer == 2) {
     //    return doorSprites.Length;
     //} else {
     //    return envirSprites.Length;
     //}
     return GetSpriteDataForLayer(layer).Count;
 }
Ejemplo n.º 20
0
        // SiDComponent
        public override void LoadFromByteStream(BinaryReader br, Int32 streamLength)
        {
            // check magic bytes
              byte[] magic = br.ReadBytes(Constants.SID_MAGIC_CODE.Length);
              String magicString = ASCIIEncoding.UTF8.GetString(magic, 0, Constants.SID_MAGIC_CODE.Length);
              if (magicString != Constants.SID_MAGIC_CODE)
              {
            throw new InvalidDataException("loading StateObject - data did not start with SID_MAGIC_CODE");
              }

              // validate version
              Int32 objectVersion = (Int32)br.ReadByte();

              // we support loading V2 assets
              if (objectVersion == 2)
              {
            upgradedFromV2 = true;
              }
              else
              {
            if (objectVersion != StateObjectVersionNumber)
            {
              throw new InvalidDataException(String.Format("loading StateObject - version mismatch (got {0}, expected {1})", objectVersion, StateObjectVersionNumber));
            }
              }

              Int32 numLayers = (Int32)br.ReadByte();
              for (Int32 i = 0; i < numLayers; i++)
              {
            SpriteLayer layer = new SpriteLayer();

            byte[] uidbytes = br.ReadBytes(6);
            layer.uid = new UID(uidbytes);

            layer.x = br.ReadByte();
            layer.y = br.ReadByte();
            layer.trans = br.ReadByte();

            // handle V3 glow byte
            if (!upgradedFromV2)
            {
              layer.glow = br.ReadByte();
            }
            else
            {
              layer.glow = 0;
            }

            layers.Add(layer);
              }

              Name = ByteUtils.readNullTermString11(br);
        }
Ejemplo n.º 21
0
 public int GetIDForName(string name, SpriteLayer layer)
 {
     return (from s in sprites[layer]
             where s.Value.Sprite.name == name
             select s.Key).FirstOrDefault();
 }
Ejemplo n.º 22
0
 Dictionary<int, SpriteData> GetSpriteDataForLayer(SpriteLayer layer)
 {
     if (!sprites.ContainsKey(layer)) {
         throw new Exception("Sprite layer is not for tiles");
     } else {
         return sprites[layer];
     }
 }
Ejemplo n.º 23
0
 public Sprite GetSprite(int id, SpriteLayer layer)
 {
     Sprite sprite;
     Sprite[] sprites = GetAllSprites(layer);
     if (id >= 0 && id < sprites.Length) {
         sprite = sprites[id];
     } else {
         Debug.Log("index out of range");
         id = 0;
         sprite = sprites[id];
     }
     return sprite;
 }
Ejemplo n.º 24
0
 //public GameObject GetInstance(int type, SpriteLayer layer, Vector2 position) {
 //    var tileInstance = Instantiate(prefab);
 //    tileInstance.transform.parent = tileParent;
 //    tileInstance.GetComponent<SpriteRenderer>().sprite = GetSprite(type, (int)layer);
 //    tileInstance.GetComponent<SpriteRenderer>().sortingLayerName = layer.ToString();
 //    tileInstance.transform.position = position;
 //    //add box collider if tile is in Environment layer so that player cannot walk over this tile
 //    //if (layer == SpriteLayer.Building || layer == SpriteLayer.Door || layer == SpriteLayer.Environment) {
 //    //    tileInstance.AddComponent<BoxCollider2D>();
 //    //}
 //    return tileInstance;
 //}
 public string GetNameForIndex(int index, SpriteLayer layer)
 {
     return (from s in sprites[layer]
             where s.Value.Index == index
             select s.Value.Sprite.name).FirstOrDefault();
 }
Ejemplo n.º 25
0
 public static SetSpriteCommand SetSprite(SpriteLayer spriteLayer, Sprite sprite)
 {
     return new SetSpriteCommand(spriteLayer, sprite);
 }
Ejemplo n.º 26
0
 public static RemoveSpriteCommand RemoveSprite(SpriteLayer spriteLayer, Coordinate coordinate)
 {
     return new RemoveSpriteCommand(spriteLayer, coordinate);
 }
 public void removeTileAtMousePos(Vector3 mousePos, SpriteLayer layer)
 {
     currentLevel.layers[layer].SetValue(Vector2int.FromVector2(mousePos), 0);
     LoadLevel(currentLevel);
 }
Ejemplo n.º 28
0
    //place tile onscreen
    void tileCreateDestroy()
    {
        var mousePos = Input.mousePosition;
        mousePos = Camera.main.ScreenToWorldPoint(mousePos);
        mousePos.z = 0;
        mousePos.x = Mathf.RoundToInt(mousePos.x);
        mousePos.y = Mathf.RoundToInt(mousePos.y);

        var tListLength = TileSpriteManager.Instance.GetListLength(layer);

        if (Input.GetMouseButtonDown(0) && !UIUtil.MouseOverUI()) {
            Tile2DSceneResourceManager.Instance.createTileAtMousePos(mousePos, layer, type);
        }

        if (Input.GetMouseButtonDown(1) && !UIUtil.MouseOverUI()) {
            Tile2DSceneResourceManager.Instance.removeTileAtMousePos(mousePos, layer);
        }

        if (Input.GetKeyDown(KeyCode.Tab)) {
            Index = (Index + 1) % tListLength;
        }

        if (Input.GetKeyDown(KeyCode.Q)) {
            Index = (Index - 1) % tListLength;
        }

        if (Input.GetKeyDown(KeyCode.LeftControl)) {
            layer = (SpriteLayer)(((int)layer + 1) % 4);
            Index = 0;
        }
    }
Ejemplo n.º 29
0
    Texture2D GetTexture(int type, SpriteLayer layer)
    {
        return GetSpriteDataForLayer(layer)[type].Sprite.texture;

        //if (layer == SpriteLayer.Path) {
        //    return pathSprites[type].Sprite.texture;
        //} else if (layer == SpriteLayer.Building) {
        //    return buildingSprites[type].texture;
        //} else if (layer == SpriteLayer.Door) {
        //    return doorSprites[type].texture;
        //} else {
        //    return envirSprites[type].texture;
        //}
    }