Skip to content

Commit

Permalink
Use game instance as 1st parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
rexrainbow committed Aug 6, 2023
1 parent ae4137a commit d596d63
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 8 deletions.
10 changes: 7 additions & 3 deletions docs/docs/charactercache.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Generate bitmapfont from [text game object](text.md), or [bbcode text game objec
```
- Add character-cache object
```javascript
var characterCache = scene.plugins.get('rexcharactercacheplugin').add(scene, config);
var characterCache = scene.plugins.get('rexcharactercacheplugin').add(config);
```

#### Import plugin
Expand Down Expand Up @@ -53,7 +53,7 @@ Generate bitmapfont from [text game object](text.md), or [bbcode text game objec
```
- Add character-cache object
```javascript
var characterCache = scene.plugins.get('rexCharacterCache').add(scene, config);
var characterCache = scene.plugins.get('rexCharacterCache').add(config);
```

#### Import class
Expand All @@ -67,14 +67,18 @@ Generate bitmapfont from [text game object](text.md), or [bbcode text game objec
import CharacterCache from 'phaser3-rex-plugins/plugins/charactercache.js';
```
- Add character-cache object
```javascript
var characterCache = new CharacterCache(game, config);
```
or
```javascript
var characterCache = new CharacterCache(scene, config);
```

### Create instance

```javascript
var characterCache = scene.plugins.get('rexCharacterCache').add(scene, {
var characterCache = scene.plugins.get('rexCharacterCache').add({
key: '',
cellWidth: 32,
cellHeight: 32,
Expand Down
2 changes: 1 addition & 1 deletion examples/charactercache/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Demo extends Phaser.Scene {
}

create() {
var characterCache = this.plugins.get('rexCharacterCache').add(this, {
var characterCache = this.plugins.get('rexCharacterCache').add({
key: 'font',

cellWidth: 32, cellHeight: 32,
Expand Down
2 changes: 1 addition & 1 deletion examples/charactercache/settext.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Demo extends Phaser.Scene {
}

create() {
var characterCache = this.plugins.get('rexCharacterCache').add(this, {
var characterCache = this.plugins.get('rexCharacterCache').add({
key: 'font',

cellWidth: 32, cellHeight: 32,
Expand Down
2 changes: 1 addition & 1 deletion examples/charactercache/textbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Demo extends Phaser.Scene {
}

create() {
var characterCache = this.plugins.get('rexCharacterCache').add(this, {
var characterCache = this.plugins.get('rexCharacterCache').add({
key: 'font',

cellWidth: 32, cellHeight: 32,
Expand Down
2 changes: 1 addition & 1 deletion examples/charactercache/typing.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Demo extends Phaser.Scene {
}

create() {
var characterCache = this.plugins.get('rexCharacterCache').add(this, {
var characterCache = this.plugins.get('rexCharacterCache').add({
key: 'font',

cellWidth: 32, cellHeight: 32,
Expand Down
6 changes: 5 additions & 1 deletion plugins/charactercache-plugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import CharacterCache from './charactercache';

export default class CharacterCachePlugin extends Phaser.Plugins.BasePlugin {
add(
scene: Phaser.Scene,
config: CharacterCache.IConfig
): CharacterCache;

add(
scene: Phaser.Scene | Phaser.Game,
config: CharacterCache.IConfig
): CharacterCache;

Expand Down
6 changes: 6 additions & 0 deletions plugins/charactercache-plugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import CharacterCache from './charactercache.js';

const IsPlainObject = Phaser.Utils.Objects.IsPlainObject;

class CharacterCachePlugin extends Phaser.Plugins.BasePlugin {

constructor(pluginManager) {
Expand All @@ -12,6 +14,10 @@ class CharacterCachePlugin extends Phaser.Plugins.BasePlugin {
}

add(scene, config) {
if (IsPlainObject(scene)) {
config = scene;
scene = this.game;
}
return new CharacterCache(scene, config);
}
}
Expand Down
2 changes: 2 additions & 0 deletions plugins/texture/charactercache/CharacterCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class CharacterCache {
if (this.textObject) {
this.textObject.destroy();
}

this.game = null;
}

destroy() {
Expand Down

0 comments on commit d596d63

Please sign in to comment.