v3.0.0: added some sync safety checks to CharSprite

This commit is contained in:
Evan Debenham
2024-10-21 16:13:57 -04:00
parent e1e6c8714b
commit e3f9619c6b
@@ -357,43 +357,44 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
} }
public void add( State state ) { public void add( State state ) {
synchronized (State.class) {
switch (state) { switch (state) {
case BURNING: case BURNING:
burning = emitter(); burning = emitter();
burning.pour( FlameParticle.FACTORY, 0.06f ); burning.pour(FlameParticle.FACTORY, 0.06f);
if (visible) { if (visible) {
Sample.INSTANCE.play( Assets.Sounds.BURNING ); Sample.INSTANCE.play(Assets.Sounds.BURNING);
} }
break; break;
case LEVITATING: case LEVITATING:
levitation = emitter(); levitation = emitter();
levitation.pour( Speck.factory( Speck.JET ), 0.02f ); levitation.pour(Speck.factory(Speck.JET), 0.02f);
break; break;
case INVISIBLE: case INVISIBLE:
if (invisible != null) { if (invisible != null) {
invisible.killAndErase(); invisible.killAndErase();
} }
invisible = new AlphaTweener( this, 0.4f, 0.4f ); invisible = new AlphaTweener(this, 0.4f, 0.4f);
if (parent != null){ if (parent != null) {
parent.add(invisible); parent.add(invisible);
} else } else
alpha( 0.4f ); alpha(0.4f);
break; break;
case PARALYSED: case PARALYSED:
paused = true; paused = true;
break; break;
case FROZEN: case FROZEN:
iceBlock = IceBlock.freeze( this ); iceBlock = IceBlock.freeze(this);
break; break;
case ILLUMINATED: case ILLUMINATED:
GameScene.effect( light = new TorchHalo( this ) ); GameScene.effect(light = new TorchHalo(this));
break; break;
case CHILLED: case CHILLED:
chilled = emitter(); chilled = emitter();
chilled.pour(SnowParticle.FACTORY, 0.1f); chilled.pour(SnowParticle.FACTORY, 0.1f);
break; break;
case DARKENED: case DARKENED:
darkBlock = DarkBlock.darken( this ); darkBlock = DarkBlock.darken(this);
break; break;
case MARKED: case MARKED:
marked = emitter(); marked = emitter();
@@ -415,8 +416,10 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
break; break;
} }
} }
}
public void remove( State state ) { public void remove( State state ) {
synchronized (State.class) {
switch (state) { switch (state) {
case BURNING: case BURNING:
if (burning != null) { if (burning != null) {
@@ -435,7 +438,7 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
invisible.killAndErase(); invisible.killAndErase();
invisible = null; invisible = null;
} }
alpha( 1f ); alpha(1f);
break; break;
case PARALYSED: case PARALYSED:
paused = false; paused = false;
@@ -452,7 +455,7 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
} }
break; break;
case CHILLED: case CHILLED:
if (chilled != null){ if (chilled != null) {
chilled.on = false; chilled.on = false;
chilled = null; chilled = null;
} }
@@ -464,30 +467,31 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
} }
break; break;
case MARKED: case MARKED:
if (marked != null){ if (marked != null) {
marked.on = false; marked.on = false;
marked = null; marked = null;
} }
break; break;
case HEALING: case HEALING:
if (healing != null){ if (healing != null) {
healing.on = false; healing.on = false;
healing = null; healing = null;
} }
break; break;
case SHIELDED: case SHIELDED:
if (shield != null){ if (shield != null) {
shield.putOut(); shield.putOut();
} }
break; break;
case HEARTS: case HEARTS:
if (hearts != null){ if (hearts != null) {
hearts.on = false; hearts.on = false;
hearts = null; hearts = null;
} }
break; break;
} }
} }
}
public void aura( int color ){ public void aura( int color ){
if (aura != null){ if (aura != null){
@@ -525,6 +529,7 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
resetColor(); resetColor();
} }
synchronized (State.class) {
if (burning != null) { if (burning != null) {
burning.visible = visible; burning.visible = visible;
} }
@@ -540,19 +545,20 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
if (marked != null) { if (marked != null) {
marked.visible = visible; marked.visible = visible;
} }
if (healing != null){ if (healing != null) {
healing.visible = visible; healing.visible = visible;
} }
if (hearts != null){ if (hearts != null) {
hearts.visible = visible; hearts.visible = visible;
} }
if (aura != null){ if (aura != null) {
if (aura.parent == null){ if (aura.parent == null) {
aura.show(this, 0); aura.show(this, 0);
} }
aura.visible = visible; aura.visible = visible;
aura.point(center()); aura.point(center());
} }
}
if (sleeping) { if (sleeping) {
showSleep(); showSleep();
} else { } else {