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

View File

@@ -357,135 +357,139 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
} }
public void add( State state ) { public void add( State state ) {
switch (state) { synchronized (State.class) {
case BURNING: switch (state) {
burning = emitter(); case BURNING:
burning.pour( FlameParticle.FACTORY, 0.06f ); burning = emitter();
if (visible) { burning.pour(FlameParticle.FACTORY, 0.06f);
Sample.INSTANCE.play( Assets.Sounds.BURNING ); if (visible) {
} Sample.INSTANCE.play(Assets.Sounds.BURNING);
break; }
case LEVITATING: break;
levitation = emitter(); case LEVITATING:
levitation.pour( Speck.factory( Speck.JET ), 0.02f ); levitation = emitter();
break; levitation.pour(Speck.factory(Speck.JET), 0.02f);
case INVISIBLE: break;
if (invisible != null) { case INVISIBLE:
invisible.killAndErase(); if (invisible != null) {
} invisible.killAndErase();
invisible = new AlphaTweener( this, 0.4f, 0.4f ); }
if (parent != null){ invisible = new AlphaTweener(this, 0.4f, 0.4f);
parent.add(invisible); if (parent != null) {
} else parent.add(invisible);
alpha( 0.4f ); } else
break; alpha(0.4f);
case PARALYSED: break;
paused = true; case PARALYSED:
break; paused = true;
case FROZEN: break;
iceBlock = IceBlock.freeze( this ); case FROZEN:
break; iceBlock = IceBlock.freeze(this);
case ILLUMINATED: break;
GameScene.effect( light = new TorchHalo( this ) ); case ILLUMINATED:
break; GameScene.effect(light = new TorchHalo(this));
case CHILLED: break;
chilled = emitter(); case CHILLED:
chilled.pour(SnowParticle.FACTORY, 0.1f); chilled = emitter();
break; chilled.pour(SnowParticle.FACTORY, 0.1f);
case DARKENED: break;
darkBlock = DarkBlock.darken( this ); case DARKENED:
break; darkBlock = DarkBlock.darken(this);
case MARKED: break;
marked = emitter(); case MARKED:
marked.pour(ShadowParticle.UP, 0.1f); marked = emitter();
break; marked.pour(ShadowParticle.UP, 0.1f);
case HEALING: break;
healing = emitter(); case HEALING:
healing.pour(Speck.factory(Speck.HEALING), 0.5f); healing = emitter();
break; healing.pour(Speck.factory(Speck.HEALING), 0.5f);
case SHIELDED: break;
if (shield != null) { case SHIELDED:
shield.killAndErase(); if (shield != null) {
} shield.killAndErase();
GameScene.effect(shield = new ShieldHalo(this)); }
break; GameScene.effect(shield = new ShieldHalo(this));
case HEARTS: break;
hearts = emitter(); case HEARTS:
hearts.pour(Speck.factory(Speck.HEART), 0.5f); hearts = emitter();
break; hearts.pour(Speck.factory(Speck.HEART), 0.5f);
break;
}
} }
} }
public void remove( State state ) { public void remove( State state ) {
switch (state) { synchronized (State.class) {
case BURNING: switch (state) {
if (burning != null) { case BURNING:
burning.on = false; if (burning != null) {
burning = null; burning.on = false;
} burning = null;
break; }
case LEVITATING: break;
if (levitation != null) { case LEVITATING:
levitation.on = false; if (levitation != null) {
levitation = null; levitation.on = false;
} levitation = null;
break; }
case INVISIBLE: break;
if (invisible != null) { case INVISIBLE:
invisible.killAndErase(); if (invisible != null) {
invisible = null; invisible.killAndErase();
} invisible = null;
alpha( 1f ); }
break; alpha(1f);
case PARALYSED: break;
paused = false; case PARALYSED:
break; paused = false;
case FROZEN: break;
if (iceBlock != null) { case FROZEN:
iceBlock.melt(); if (iceBlock != null) {
iceBlock = null; iceBlock.melt();
} iceBlock = null;
break; }
case ILLUMINATED: break;
if (light != null) { case ILLUMINATED:
light.putOut(); if (light != null) {
} light.putOut();
break; }
case CHILLED: break;
if (chilled != null){ case CHILLED:
chilled.on = false; if (chilled != null) {
chilled = null; chilled.on = false;
} chilled = null;
break; }
case DARKENED: break;
if (darkBlock != null) { case DARKENED:
darkBlock.lighten(); if (darkBlock != null) {
darkBlock = null; darkBlock.lighten();
} darkBlock = null;
break; }
case MARKED: break;
if (marked != null){ case MARKED:
marked.on = false; if (marked != null) {
marked = null; marked.on = false;
} marked = null;
break; }
case HEALING: break;
if (healing != null){ case HEALING:
healing.on = false; if (healing != null) {
healing = null; healing.on = false;
} healing = null;
break; }
case SHIELDED: break;
if (shield != null){ case SHIELDED:
shield.putOut(); if (shield != null) {
} shield.putOut();
break; }
case HEARTS: break;
if (hearts != null){ case HEARTS:
hearts.on = false; if (hearts != null) {
hearts = null; hearts.on = false;
} hearts = null;
break; }
break;
}
} }
} }
@@ -524,34 +528,36 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip
if (flashTime > 0 && (flashTime -= Game.elapsed) <= 0) { if (flashTime > 0 && (flashTime -= Game.elapsed) <= 0) {
resetColor(); resetColor();
} }
if (burning != null) { synchronized (State.class) {
burning.visible = visible; if (burning != null) {
} burning.visible = visible;
if (levitation != null) { }
levitation.visible = visible; if (levitation != null) {
} levitation.visible = visible;
if (iceBlock != null) { }
iceBlock.visible = visible; if (iceBlock != null) {
} iceBlock.visible = visible;
if (chilled != null) { }
chilled.visible = visible; if (chilled != null) {
} chilled.visible = visible;
if (marked != null) { }
marked.visible = visible; if (marked != null) {
} marked.visible = visible;
if (healing != null){ }
healing.visible = visible; if (healing != null) {
} healing.visible = visible;
if (hearts != null){ }
hearts.visible = visible; if (hearts != null) {
} hearts.visible = visible;
if (aura != null){ }
if (aura.parent == null){ if (aura != null) {
aura.show(this, 0); if (aura.parent == null) {
aura.show(this, 0);
}
aura.visible = visible;
aura.point(center());
} }
aura.visible = visible;
aura.point(center());
} }
if (sleeping) { if (sleeping) {
showSleep(); showSleep();