Coder Social home page Coder Social logo

tiled-types's Introduction

tiled-types

Type definitions of Tiled generated JSON https://github.com/bjorn/tiled.

Build Status

Made for Tiled 1.4.

Based on its documentation https://doc.mapeditor.org/en/stable/reference/json-map-format.

Installation

npm install tiled-types

Use

import TiledMap, { TiledLayerTilelayer } from "tiled-types";

// Assume we're in node context
const map: TiledMap = fs.readFileSync('path/to/schema.json', 'utf8');

const allTilelayers: TiledLayerTilelayer[] = map.layers
    .filter((l): l is TiledLayerTilelayer => l.type === 'tilelayer');

You can find quite the same example here

Credits

Thanks to type-zoo for there repo configuration ๐Ÿ‘

And to Tiled contributors ๐Ÿ’ฏ

tiled-types's People

Contributors

chnapy avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tiled-types's Issues

Thank you

This package looks like a life-saver, thank you for making and maintaining it!

TiledLayer<any> in TiledMapAbstract?

Hello,

I would just like to know the reason for using any instead of TiledMapType in the following definition.

export interface TiledMapAbstract<O extends TiledMapType> {
    ...
    layers: Array<TiledLayer<any>>;
    ...
}

Thank you!

incorrect T extends tilelayer ?

Hi @Chnapy .

I'm trying to type a list of objects with properties and gids.
Looking at your types, I found:

export type TiledMapType = 'orthogonal' | 'isometric' | 'staggered' | 'hexagonal';

export interface TiledObject<T extends TiledMapType> {
    ellipse?: boolean;
    gid: T extends 'tilelayer' ? number : never;
    ...
}

tsserver always returns an error Type 'number' is not assignable to type 'never'

How can T extends 'tilelayer' if T extends TiledMapType ?
Is that a bug in the types ?

TiledObject.properties is optional

We've noticed that objects without properties will not have a properties key initialized to [] as per the types.

Can we update the types as follow ?

/**
 * @see https://doc.mapeditor.org/en/stable/reference/json-map-format/#object
 */
export interface TiledObject {
    ellipse?: boolean;
    gid?: number;
    height: number;
    id: number;
    name: string;
    point?: boolean;
    polygon?: Point[];
    polyline?: Point[];
-    properties: TiledProperty[];
+    properties?: TiledProperty[];

Using tiled v1.5.0

Group Layers do not have an object

This is an example group

        {
         "id":2,
         "layers":[...],
         "name":"group name here",
         "opacity":1,
         "type":"group",
         "visible":true,
         "x":0,
         "y":0

it should be quite simple

export interface TiledLayerGrouplayer extends TiledLayerAbstract<'group'> {
         layers: Array<TiledLayer<any>>;
         type:"group",
}

Super strangled of time, can't test nor PR now, sorry :(

types of property orientation are incompatible

Getting this error when trying to type my Tiled map:

[tsserver 2345] [E] Argument of type '{ compressionlevel: number; height: number; infinite: boolean; layers: { compression: string; data: string; encoding: string; height: number; id: number; name: string; opacity: number; type: string; visible: boolean; width: number; x: number; y: number; }[]; ... 10 more ...; width: number; }' is not assignable to parameter of type 'SetStateAction<TiledMapOrthogonal | TiledMapIsometric | TiledMapHexagonal | TiledMapStaggered | undefined>'.
  Type '{ compressionlevel: number; height: number; infinite: boolean; layers: { compression: string; data: string; encoding: string; height: number; id: number; name: string; opacity: number; type: string; visible: boolean; width: number; x: number; y: number; }[]; ... 10 more ...; width: number; }' is not assignable to type 'TiledMapOrthogonal'.
    Types of property 'orientation' are incompatible.
      Type 'string' is not assignable to type '"orthogonal"'.

My tiled json looks like this:

{
  "compressionlevel": -1,
  "height": 50,
  "infinite": false,
  ...
  "orientation": "orthogonal",
  "renderorder": "right-down",
  "tiledversion": "1.4.2",
  ...
}

Also, compressionlevel seems to be missing from the types definition.

Using typescript 4.1 and tiled-types 1.1.0

Missing TiledProperty types

The current type is

/**
 * @see https://doc.mapeditor.org/en/stable/reference/json-map-format/#property
 */
export interface TiledPropertyAbstract<V extends TiledPropertyValue, T extends TiledPropertyType> {
    name: string;
    value: V;
    type: T;
}

export type TiledProperty =
    TiledPropertyAbstract<string, 'string'>
    | TiledPropertyAbstract<number, 'int'>;

As per the @see link and Custom properties doc, new types have been added

  • since 0.16: float, bool
  • since 0.17: color, file
  • since 1.4: object

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.