use of com.bladecoder.engine.model.AnimationRenderer in project bladecoder-adventure-engine by bladecoder.
the class IfAttrAction method run.
@Override
public boolean run(VerbRunner cb) {
Scene s = actor.getScene();
final String actorId = actor.getActorId();
if (actorId == null) {
// if called inside a scene verb and no actor is specified, return
EngineLogger.error(getClass() + ": No actor specified");
return false;
}
BaseActor a = s.getActor(actorId, true);
if (attr.equals(ActorAttribute.STATE) && a instanceof InteractiveActor) {
InteractiveActor ia = (InteractiveActor) a;
if (!ActionUtils.compareNullStr(value, ia.getState())) {
gotoElse((VerbRunner) cb);
}
} else if (attr.equals(ActorAttribute.VISIBLE)) {
boolean val = Boolean.parseBoolean(value);
if (val != a.isVisible()) {
gotoElse((VerbRunner) cb);
}
} else if (attr.equals(ActorAttribute.INTERACTIVE)) {
boolean val = Boolean.parseBoolean(value);
if (a instanceof InteractiveActor) {
if (val != ((InteractiveActor) a).getInteraction()) {
gotoElse((VerbRunner) cb);
}
} else if (val == true) {
gotoElse((VerbRunner) cb);
}
} else if (attr.equals(ActorAttribute.IN_INVENTORY)) {
boolean val = Boolean.parseBoolean(value);
SpriteActor item = null;
if (a != null)
item = World.getInstance().getInventory().get(a.getId());
if ((val && item == null) || (!val && item != null)) {
gotoElse((VerbRunner) cb);
}
} else if (attr.equals(ActorAttribute.TARGET)) {
if (!ActionUtils.compareNullStr(value, cb.getCurrentTarget())) {
gotoElse((VerbRunner) cb);
}
} else if (attr.equals(ActorAttribute.IN_SCENE)) {
boolean val = Boolean.parseBoolean(value);
BaseActor a2 = s.getActor(actorId, false);
if ((val && a2 == null) || (!val && a2 != null))
gotoElse((VerbRunner) cb);
} else if (attr.equals(ActorAttribute.LAYER) && a instanceof InteractiveActor) {
InteractiveActor ia = (InteractiveActor) a;
if (!ActionUtils.compareNullStr(value, ia.getLayer())) {
gotoElse((VerbRunner) cb);
}
} else if (attr.equals(ActorAttribute.DIRECTION) && a instanceof SpriteActor) {
SpriteActor sa = (SpriteActor) a;
if (sa.getRenderer() instanceof AnimationRenderer) {
String dir = null;
String anim = ((AnimationRenderer) sa.getRenderer()).getCurrentAnimationId();
int idx = anim.lastIndexOf('.');
if (idx != -1)
dir = anim.substring(idx + 1);
if (!ActionUtils.compareNullStr(value, dir)) {
gotoElse((VerbRunner) cb);
}
}
}
return false;
}
use of com.bladecoder.engine.model.AnimationRenderer in project bladecoder-adventure-engine by bladecoder.
the class EditAnimationDialog method inputsToModel.
@Override
protected void inputsToModel(boolean create) {
String sourceStr = source.getText();
AnimationRenderer renderer = (AnimationRenderer) parent.getRenderer();
if (create) {
if (renderer instanceof SpineRenderer) {
e = new SpineAnimationDesc();
if (spineAtlasExists(sourceStr)) {
((SpineAnimationDesc) e).atlas = null;
setVisible(atlas, false);
} else {
if (!atlas.isVisible()) {
setVisible(atlas, true);
}
((SpineAnimationDesc) e).atlas = atlas.getText();
}
} else if (renderer instanceof AtlasRenderer) {
e = new AtlasAnimationDesc();
} else {
e = new AnimationDesc();
}
} else {
HashMap<String, AnimationDesc> animations = renderer.getAnimations();
animations.remove(e.id);
if (e.id.equals(renderer.getInitAnimation()))
renderer.setInitAnimation(null);
}
e.id = id.getText();
e.sound = sound.getText();
e.source = sourceStr;
e.count = Integer.parseInt(count.getText());
e.preload = Boolean.parseBoolean(preload.getText());
e.disposeWhenPlayed = Boolean.parseBoolean(dispose.getText());
e.animationType = Type.valueOf(repeat.getText());
e.inD = Param.parseVector2(in.getText());
e.outD = Param.parseVector2(out.getText());
e.duration = Float.parseFloat(speed.getText());
((AnimationRenderer) parent.getRenderer()).addAnimation(e);
if (renderer instanceof ImageRenderer && Boolean.parseBoolean(localizable.getText()) && e.source != null && e.source.length() > 0) {
e.source = I18N.PREFIX + e.source;
}
if (renderer.getInitAnimation() == null)
renderer.setInitAnimation(e.id);
// TODO UNDO OP
// UndoOp undoOp = new UndoAddElement(doc, e);
// Ctx.project.getUndoStack().add(undoOp);
Ctx.project.setModified();
}
use of com.bladecoder.engine.model.AnimationRenderer in project bladecoder-adventure-engine by bladecoder.
the class AnimationWidget method draw.
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
if (renderer == null || ((AnimationRenderer) renderer).getCurrentAnimation() == null)
return;
Color tmp = batch.getColor();
batch.setColor(Color.WHITE);
renderer.update(Gdx.graphics.getDeltaTime());
RectangleRenderer.draw((SpriteBatch) batch, getX(), getY(), getWidth(), getHeight(), Color.MAGENTA);
float scalew = getWidth() / renderer.getWidth();
float scaleh = getHeight() / renderer.getHeight();
float scale = scalew > scaleh ? scaleh : scalew;
renderer.draw((SpriteBatch) batch, getX() + renderer.getWidth() * scale / 2, getY(), scale, 0f, null);
batch.setColor(tmp);
}
use of com.bladecoder.engine.model.AnimationRenderer in project bladecoder-adventure-engine by bladecoder.
the class AnimationDrawer method setActor.
public void setActor(BaseActor a) {
if (renderer != null) {
renderer.dispose();
renderer = null;
}
if (a instanceof SpriteActor && ((SpriteActor) a).getRenderer() instanceof AnimationRenderer) {
ActorRenderer r = ((SpriteActor) a).getRenderer();
if (r instanceof Sprite3DRenderer) {
renderer = new Sprite3DRenderer();
((Sprite3DRenderer) renderer).setSpriteSize(new Vector2(r.getWidth(), r.getHeight()));
} else if (r instanceof SpineRenderer) {
renderer = new SpineRenderer();
((SpineRenderer) renderer).enableEvents(false);
((SpineRenderer) renderer).setSkin(((SpineRenderer) r).getSkin());
} else if (r instanceof ImageRenderer) {
renderer = new ImageRenderer();
} else if (r instanceof AtlasRenderer) {
renderer = new AtlasRenderer();
}
renderer.setOrgAlign(Align.bottom);
}
}
use of com.bladecoder.engine.model.AnimationRenderer in project bladecoder-adventure-engine by bladecoder.
the class SpriteList method flipInit.
private void flipInit() {
int pos = list.getSelectedIndex();
if (pos == -1)
return;
AnimationRenderer renderer = (AnimationRenderer) ((SpriteActor) Ctx.project.getSelectedActor()).getRenderer();
String id = list.getItems().get(pos).id;
String newValue = AnimationRenderer.getFlipId(id);
renderer.setInitAnimation(newValue);
Ctx.project.setModified(this, "init_animation", id, newValue);
}
Aggregations