Skip to content

Commit

Permalink
add fixed gl-tiled
Browse files Browse the repository at this point in the history
  • Loading branch information
bazumo committed Dec 28, 2020
1 parent c141387 commit 51f6d48
Show file tree
Hide file tree
Showing 109 changed files with 88,150 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules


.eslintcache
.eslintcache
16 changes: 16 additions & 0 deletions gl-tiled/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file is for unifying the coding style for different editors and IDEs.
# More information at http://EditorConfig.org
root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[*.md]
trim_trailing_whitespace = false

[{package.json,bower.json,*.yml}]
indent_size = 2
37 changes: 37 additions & 0 deletions gl-tiled/.github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build & Test

on:
push:
branches: [master]
pull_request:
branches: [master]
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build
env:
CI: true
- name: Publish Version
if: success() && github.event_name == 'release'
run: |
git config user.email "englercj@live.com"
git config user.name "Chad Engler"
npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN
npm publish --access public
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
27 changes: 27 additions & 0 deletions gl-tiled/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# sublime text files
*.sublime*
*.*~*.TMP

# temp files
.DS_Store
Thumbs.db
Desktop.ini
npm-debug.log

# project files
.project
.idea

# vim swap files
*.sw*

# emacs temp files
*~
\#*#

# project ignores
!.gitkeep
.rpt2_cache/
node_modules/
dist/
docs/
21 changes: 21 additions & 0 deletions gl-tiled/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2017-2020 Chad Engler

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
57 changes: 57 additions & 0 deletions gl-tiled/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# gl-tiled

A WebGL renderer for maps created with the [Tiled Editor](http://mapeditor.org).

Tested with Tiled Map Editor v1.3.3.

## Contents

- [Usage](#usage)
- [API Reference](bundles/gl-tiled/#api-reference)
- [Framework Bundles](#framework-bundles)

## Usage

For the most basic usage, you only need to provide a JS object that represents the parsed JSON Tiled
map and a WebGL Context to render with.

```js
// Create the map instance. `mapData` is the parsed Tiled JSON map,
// and `gl` is the WebGLRenderingContext.
var tilemap = new glTiled.Tilemap(mapData, { gl });

// size the viewport of the map
tileMap.resizeViewport(gl.canvas.width, gl.canvas.height);

// setup a update and render loop
var lastTime = 0;
(function draw(now)
{
requestAnimationFrame(draw);

// update animations, if your map has no animated tiles
// you can skip this step.
var dt = now - lastTime;
lastTime = now;
tileMap.update(dt); // dt is expected to be elapsed ms since last call.

// draw!
tileMap.draw();
})();
```

## Framework Bundles

This library also ships with a number of bundles (`gl-tiled.<bundle-name>.js`). These bundles contain
the code necessary for gl-tiled to integrate with other frameworks. Each bundle is listed below, with
a short description of what they do. For more information click their _Documentation_ link.

### Core (`gl-tiled.js`) - [Documentation](bundles/gl-tiled/)

This is the core library bundle. It is meant to work with WebGL, and therefore can work with any
framework. However, it does not provide any special code to ease integration with those frameworks.

### Resource Loader (`gl-tiled.resource-loader.js`) - [Documentation](bundles/resource-loader/)

The Resource Loader bundle a [resource-loader](https://github.com/englercj/resource-loader)
middleware that makes it easy to load Tiled JSON maps.
21 changes: 21 additions & 0 deletions gl-tiled/bundles/gl-tiled/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# gl-tiled.js

This is the core library bundle. It is meant to work with WebGL, and therefore can work with any framework. However, it does not provide any special code to ease integration with those frameworks.

## API Reference

Exported classes:

- [`GLTilemap`](https://englercj.github.io/gl-tiled/classes/gltilemap.html)
- [`GLTileset`](https://englercj.github.io/gl-tiled/classes/gltileset.html)
- [`GLTilelayer`](https://englercj.github.io/gl-tiled/classes/gltilelayer.html)
- [`GLImagelayer`](https://englercj.github.io/gl-tiled/classes/glimagelayer.html)

## Unsupported features

- Objectgroups
* Haven't decided what support for this would mean.
- Map tile render order
* Currently only "Right Down" is supported, which is default. PRs welcome.
- Isometric, Isometric (Staggered), Hexagonal (Staggered)
* Currently only orthographic is supported. PRs welcome.
17 changes: 17 additions & 0 deletions gl-tiled/bundles/gl-tiled/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export * from '../../src/ELayerType';
export * from '../../src/GLImagelayer';
export * from '../../src/GLTilelayer';
export * from '../../src/GLTilemap';
export * from '../../src/GLTileset';
export * from '../../src/IAssetCache';
export * from '../../src/IDictionary';
export * from '../../src/IPoint';

export * from '../../src/tiled/IProperty';
export * from '../../src/tiled/layers';
export * from '../../src/tiled/objects';
export * from '../../src/tiled/Tilemap';
export * from '../../src/tiled/Tileset';

export * from '../../src/utils/GLProgram';
export * from '../../src/utils/parseColorStr';
22 changes: 22 additions & 0 deletions gl-tiled/bundles/resource-loader/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# gl-tiled.resource-loader.js

The Resource Loader bundle provides a [resource-loader](https://github.com/englercj/resource-loader) middleware that makes it easy to load Tiled JSON maps.

This bundle is unique in that it actually does not depend on the gl-tiled core, and therefore this bundle doesn't actually contain the core library. That means you can combine this bundle with any other bundle without conflicts.

For example, you can include the core library (for use with WebGL) and this bundle (for use with resource-loader):

```html
<script src="node_modules/resource-loader/dist/resource-loader.js"></script>

<script src="dist/gl-tiled.js"></script>
<script src="dist/gl-tiled.resource-loader.js"></script>
```

> **Note:** This bundle requires resource-loader v4.x
## API Reference

Exported functions:

- [`tiledMiddlewareFactory()`](https://englercj.github.io/gl-tiled/modules/_bundles_resource_loader_index_.html#tiledmiddlewarefactory)
96 changes: 96 additions & 0 deletions gl-tiled/bundles/resource-loader/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { Loader, Resource, ResourceType, ImageLoadStrategy } from 'resource-loader';
import { IAddOptions } from 'resource-loader/dist/Loader';

/**
* Creates the tiled loader middleware function and returns it.
*
* @example
* const loader = new Loader();
*
* // add this middleware so that any map files we load will also have all their sub resources
* // loaded too.
* loader.use(glTiled['resource-loader'].tiledMiddlewareFactory());
* loader.add('lightworld', 'maps/lttp/lightworld/lightworld.json');
* loader.load(function ()
* {
* // create the tilemap using the loaded map data (`resources.lightworld.data`) and passing
* // all resources as the third parameter which is the resource cache the Tilemap object
* // will search for map resources in before trying to load them itself.
* var tilemap = new glTiled.Tilemap(gl, loader.resources.lightworld.data, loader.resources);
* })
*/
export function tiledMiddlewareFactory()
{
return function tiledMiddleware(this: Loader, resource: Resource, next: Function)
{
if (!resource.data
|| resource.type !== ResourceType.Json
|| !resource.data.layers
|| !resource.data.tilesets)
{
next();
return;
}

let urlDir = resource.url.replace(this.baseUrl, '');
urlDir = urlDir.substr(0, urlDir.lastIndexOf('/')) + '/';

const addOptions: IAddOptions = {
url: '',
crossOrigin: resource.strategy.config.crossOrigin,
strategy: ImageLoadStrategy,
metadata: resource.metadata ? resource.metadata.imageMetadata : undefined,
parentResource: resource,
};

for (let i = 0; i < resource.data.tilesets.length; ++i)
{
const tileset = resource.data.tilesets[i];

if (tileset.image)
{
if (!this.resources[tileset.image])
{
const options = Object.assign({}, addOptions);
options.name = tileset.image;
options.url = urlDir + tileset.image;
this.add(options);
}
}

if (resource.data.tiles)
{
for (const key in resource.data.tiles)
{
const tile = resource.data.tiles[key];

if (tile.image && !this.resources[tile.image])
{
const options = Object.assign({}, addOptions);
options.name = tile.image;
options.url = urlDir + tile.image;
this.add(options);
}
}
}
}

for (let i = 0; i < resource.data.layers.length; ++i)
{
const layer = resource.data.layers[i];

if (layer.image)
{
if (!this.resources[layer.image])
{
const options = Object.assign({}, addOptions);
options.name = layer.image;
options.url = urlDir + layer.image;
this.add(options);
}
}
}

next();
}
}
Loading

0 comments on commit 51f6d48

Please sign in to comment.