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