Skip to content

Commit

Permalink
Merge branch 'pixi-v7'
Browse files Browse the repository at this point in the history
  • Loading branch information
miltoncandelero committed Jan 18, 2023
2 parents 8c9778b + 99d0ec6 commit 966fe48
Show file tree
Hide file tree
Showing 237 changed files with 28,094 additions and 11,560 deletions.
41 changes: 41 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module.exports = {
extends: ['@pixi/eslint-config', 'plugin:prettier/recommended'],
rules: {
'prettier/prettier': [
'warn',
{
semi: true,
trailingComma: 'es5',
singleQuote: true,
printWidth: 180,
tabWidth: 4,
useTabs: false,
},
],

// special rules because most of this code is lifted from spine
// I would love to not have to do this, but I don't have the time nor the energy to fix the entire lib. Milton - 2023

eqeqeq: 0,
'@typescript-eslint/no-unused-vars': 0,
'@typescript-eslint/no-empty-function': 0,
'no-console': 0,
'@typescript-eslint/no-use-before-define': 0,
radix: 0,
'no-eq-null': 0,
'no-constant-condition': 0,
'no-prototype-builtins': 0,
camelcase: 0,
'@typescript-eslint/ban-ts-comment': 0,
'no-case-declarations': 0,
'@typescript-eslint/no-useless-constructor': 0,
'consistent-return': 0,
'no-loop-func': 0,
'@typescript-eslint/ban-types': 0,
'@typescript-eslint/no-empty-interface': 0,
'@typescript-eslint/adjacent-overload-signatures': 0,
'no-fallthrough': 0,
'@typescript-eslint/no-unused-expressions': 0,
'max-params': 0,
},
};
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ lib
dist
bundles/*/index.d.ts
packages/*/index.d.ts

# ignore the npmrc
.npmrc
13 changes: 6 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,21 @@ steps to reproduce, etc. "X isn't working!!!1!" will probably just be closed.

## Making Changes

To build the library you will need to download node.js from [nodejs.org][20]. After it has been installed open a
console and run `npm install -g yarn` to install the global `yarn` executable.
To build the library you will need to download node.js from [nodejs.org][20].

This monorepo uses Lerna and NX in the background.

After that you can clone the repository and run `npm install` inside the cloned folder. This will install
dependencies necessary for building the project. You can rebuild the project by running `yarn build` in the cloned
dependencies necessary for building the project. You can rebuild the project by running `npm build` in the cloned
folder.

Please, before sending your commit make sure that `npm run lint` returns no errors nor warnings. You can use `npm run lint:fix` to automagically fix most issues but you still might need to fix them manually.

Once that is ready, you can make your changes and submit a Pull Request:

- **Send Pull Requests to the `master` branch.** All Pull Requests must be sent to the `master` branch, which is where
all "bleeding-edge" development takes place.

- **Never commit new builds.** When making a code change you should always run `yarn build` which will rebuild the project
so you can test, *however* please do not commit the new builds placed in `dist/` or your PR will be closed. By default
the build process will output to an ignored folder (`build/`) you should be fine.

- **Only commit relevant changes.** Don't include changes that are not directly relevant to the fix you are making.
The more focused a PR is, the faster it will get attention and be merged. Extra files changing only whitespace or
trash files will likely get your PR closed.
Expand Down
118 changes: 54 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# pixi-spine

Spine 3.7, 3.8, 4.0, 4.1 implementation for PixiJS v5 & v6.
Spine 3.7, 3.8, 4.0, 4.1 implementation for PixiJS.

Typescript definitions are up-to-date with PixiJS v6.
### Versions Compatibility

| PixiJS | pixi-spine |
|---|---|
| v5.x - v6.x | v3.x |
| v7.x | v4.x |

For spine < 3.7 support is limited, but accepting PR's for `runtime-3.7` package.

For previous versions of pixi & typescript definitions - please refer to [README in pixi5](https://github.com/pixijs/pixi-spine/tree/pixi5/#readme)
For previous versions of pixi refer to
- [README in pixi6](https://github.com/pixijs/pixi-spine/tree/pixi6/#readme)
- [README in pixi5](https://github.com/pixijs/pixi-spine/tree/pixi5/#readme)

Demos:

Expand All @@ -18,86 +25,73 @@ https://sbfkcel.github.io/pixi-spine-debug/

## Basic Usage

Please read this carefully: there are three ways to add this lib to your app.
Please read this carefully: there are many ways to add this lib to your app.

1. Angular, React, Webpack, Rollup - if you know those words, use ES6 bundles
2. Good old `<script src="pixi-spine.umd.js">` , also named vanilla JS
3. Custom bundle, for guys who really want to shake da tree
1. npm, Webpack, Rollup, Vite - if you know those words, use `npm i pixi-spine`
2. Good old `<script src="pixi-spine.js">`, also named vanilla JS
3. The modern `<script type="module" src="pixi-spine.mjs">`, for ES modules
4. Single version, check the `all-X.Y` bundles
5. Custom bundle, for specific combinations of versions.

### ES6 bundles
### Bundles example

```js
import 'pixi-spine' // Do this once at the very start of your code. This registers the loader!

import * as PIXI from 'pixi.js';
import {Spine} from 'pixi-spine';

const app = new PIXI.Application();
document.body.appendChild(app.view);

app.loader
.add('spineCharacter', 'spine-data-1/HERO.json')
.load(function (loader, resources) {
const animation = new Spine(resources.spineCharacter.spineData);

// add the animation to the scene and render...
app.stage.addChild(animation);

if (animation.state.hasAnimation('run')) {
// run forever, little boy!
animation.state.setAnimation(0, 'run', true);
// dont run too fast
animation.state.timeScale = 0.1;
}

app.start();
});
PIXI.Assets.load("spine-data-1/HERO.json").then((resource) => {
const animation = new Spine(resource.spineData);
app.stage.addChild(animation);

// add the animation to the scene and render...
app.stage.addChild(animation);

if (animation.state.hasAnimation('run')) {
// run forever, little boy!
animation.state.setAnimation(0, 'run', true);
// dont run too fast
animation.state.timeScale = 0.1;
// update yourself
animation.autoUpdate = true;
}
});
```

Alternatively, you may use `@pixi-spine/all-3.8` package.

### Where are spine core classes?

Classes like `AttachmentType`, `TextureAtlas`, `TextureRegion` and `Utils` are shared across all spine versions, and re-exported by all bundles. But if you want to see them directly, they are in `@pixi-spine-base`.
Classes like `AttachmentType`, `TextureAtlas`, `TextureRegion` and `Utils` are shared across all spine versions, and re-exported by all bundles. But if you want to see them directly, they are in `@pixi-spine/base`.

Base also contains unified interfaces, `ISkeleton`, `ISkeletonData`, `IAnimationData` and so on, see `ISkeleton.ts` file.

Most of classes are spine-version-dependant, including `Skeleton`, `SkeletonData`, they are stored in corresponding packages `@pixi-spine/runtime-3.8` and so on.

### Vanilla JS, UMD build

All pixiJS v6 plugins has special `umd` build suited for vanilla.
Navigate `pixi-spine` npm package, take `dist/pixi-spine.umd.js` file.
Alternatively, you can look in `@pixi-spine/all-3.8` npm package.

```html
<script src='lib/pixi.js'></script>
<script src='lib/pixi-spine.umd.js'></script>
```

```js
const animation = new PIXI.spine.Spine(resources.spineCharacter.spineData);
```
### Browser builds

Unfortunately, there are no typescript definitions for vanilla build on both `pixi` v6 and `pixi-spine`
For browser builds, you will need to grab either the `.js` (for CJS) file or the `.mjs` (for ESM) from the `dist` folder or from your CDN of choice.

### Custom bundle

Main bundle `pixi-spine` weights more than 1 MB.
Main bundle `pixi-spine` weights 374 KB (unzipped).

Bundle `@pixi-spine/all-3.8` weights about 400 KB.
Bundle `@pixi-spine/all-3.8` weights about 165 KB (unzipped).

If you want to use different version (3.7) please look how modules `loader-3.8` and `pixi-spine-3.8` are made.

Basically, you have to copy its code in a separate file in your project, and alter imports to corresonding version.
Basically, you have to copy its code in a separate file in your project, and alter imports to corresponding version.

For example, here's bundle for 3.8:

```js
import {SpineParser} from '@pixi-spine/loader-3.8';
export {SpineParser};
import '@pixi-spine/loader-3.8'; // Side effect install the loader
// eslint-disable-next-line @typescript-eslint/no-duplicate-imports
export * from '@pixi-spine/runtime-3.8';
export * from '@pixi-spine/base';

SpineParser.registerLoaderPlugin();
```

In case author was too lazy to publish`loader-3.7`, you can do the same trick with them, just look in sources of `loader-3.8`.
Expand All @@ -109,7 +103,7 @@ Read our [docs](examples/index.md).
### Two-color tint

Light-dark tint is supported with help of [pixi-heaven](https://github.com/gameofbombs/pixi-heaven)
Currently supported only by UMD build.
Currently supported only by UMD build. (and most likely on PixiJS < 7.x)

```js
let spine = new PIXI.heaven.Spine(spineData);
Expand Down Expand Up @@ -165,27 +159,23 @@ If you want to create your own debugger you can extend `SpineDebugRenderer` or c

You will need to have [node][node] setup on your machine.

Make sure you have [rush][rush] installed:

```bash
npm install -g @microsoft/rush
```

Then you can install dependencies and build:

```bash
npm run prepare
npm install
npm run build
```

That will output the built all modules. UMD can be found in `./bundles/pixi-spine/dist`.
That will build all packages and bundles. Browser packages are inside `dist` and npm packages are inside `lib`

If you use IntellIJ Idea / Webstorm to navigate the project, take this line and set it in **project settings** / **exclude files**

```
packages/*/node_modules;packages/*/compile;bundles/*/node_modules;bundles/*/compile;lib;dist
```
`npm link` will misbehave because of the monorepo setup.

[node]: https://nodejs.org/
[typescript]: https://www.typescriptlang.org/
[rush]: https://rushjs.io/

## Deploying

If you have enough rights to publish this monorepo, you can publish by running `npm run lernaPublish`
This is so that it runs with the internal npm v8 since npm v9 doesn't play nice with Lerna.

If for some reason your publish failed, use `npm run lernaPublish:fromPackage` to try to force a publish without creating a new version
65 changes: 44 additions & 21 deletions bundles/all-3.8/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,50 @@
"name": "@pixi-spine/all-3.8",
"version": "3.1.2",
"description": "Pixi integration with EsotericSoftware Spine, big, contains runtime for 3.8",
"main": "lib/all-3.8.js",
"module": "lib/all-3.8.es.js",
"bundle": "dist/pixi-spine-3.8.umd.js",
"main": "lib/index.js",
"module": "lib/index.mjs",
"types": "./index.d.ts",
"namespace": "PIXI.spine",
"exports": {
".": {
"import": "./lib/index.mjs",
"require": "./lib/index.js",
"types": "./index.d.ts"
}
},
"extensionConfig": {
"namespace": "PIXI.spine",
"bundle": "dist/pixi-spine-3.8.js",
"bundleModule": "dist/pixi-spine-3.8.mjs",
"globals": {
"@pixi-spine/base": "PIXI.spine",
"@pixi-spine/loader-3.8": "PIXI.spine",
"@pixi-spine/loader-base": "PIXI.spine",
"@pixi-spine/runtime-3.8": "PIXI.spine38"
}
},
"dependencies": {
"@pixi-spine/base": "~3.1.2",
"@pixi-spine/loader-3.8": "~3.1.2",
"@pixi-spine/loader-base": "~3.1.2",
"@pixi-spine/runtime-3.8": "~3.1.2"
"@pixi-spine/base": "*",
"@pixi-spine/loader-3.8": "*",
"@pixi-spine/loader-base": "*",
"@pixi-spine/runtime-3.8": "*"
},
"peerDependencies": {
"@pixi/constants": "^7.0.0",
"@pixi/core": "^7.0.0",
"@pixi/display": "^7.0.0",
"@pixi/graphics": "^7.0.0",
"@pixi/math": "^7.0.0",
"@pixi/mesh": "^7.0.0",
"@pixi/mesh-extras": "^7.0.0",
"@pixi/sprite": "^7.0.0",
"@pixi/utils": "^7.0.0"
},
"scripts": {
"build": "rollup -c rollup.config.js --silent",
"build:types": "rimraf compile && tsc -p tsconfig-api.json && api-extractor run"
"build": "run-p build:*",
"build:rollup": "rollup -c rollup.config.mjs --silent",
"build:types": "rimraf compile && tsc -p tsconfig-api.json && api-extractor run",
"lint": "eslint src/**/*.ts",
"lint:fix": "eslint src/**/*.ts --fix"
},
"repository": {
"type": "git",
Expand All @@ -39,22 +69,15 @@
"Chad Engler <[email protected]>",
"Richard Davey <[email protected]>",
"Shukant K. Pal <[email protected]>",
"Yevhenii Huselietov <[email protected]>"
"Yevhenii Huselietov <[email protected]>",
"Milton Candelero <[email protected]>"
],
"bugs": {
"url": "https://github.com/pixijs/pixi-spine/issues"
},
"license": "SEE SPINE-LICENSE",
"homepage": "https://github.com/pixijs/pixi-spine/#readme",
"devDependencies": {
"@pixi-spine/eslint-config": "~1.0.0",
"@pixi-spine/rollup-config": "~1.0.0",
"chai": "~4.2.0",
"eslint": "~7.13.0",
"prepend": "=1.0.2",
"rimraf": "3.0.2",
"rollup": "^2.53.3",
"tslib": "~2.2.0",
"typescript": "~4.3.0"
"@pixi-spine/rollup-config": "*"
}
}
}
35 changes: 0 additions & 35 deletions bundles/all-3.8/rollup.config.js

This file was deleted.

4 changes: 4 additions & 0 deletions bundles/all-3.8/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import configBuilder from '@pixi-spine/rollup-config';
import pkg from './package.json' assert { type: 'json' };

export default configBuilder(pkg.extensionConfig, pkg);
Loading

0 comments on commit 966fe48

Please sign in to comment.