Skip to content

Instantly share code, notes, and snippets.

@Interrupt
Created September 30, 2020 20:50
Show Gist options
  • Save Interrupt/c9ea5272c196563c7410cc6d36d6f1c9 to your computer and use it in GitHub Desktop.
Save Interrupt/c9ea5272c196563c7410cc6d36d6f1c9 to your computer and use it in GitHub Desktop.
Conversion between old and new text entities
package com.interrupt.dungeoneer.entities;
import com.badlogic.gdx.graphics.Color;
import com.interrupt.dungeoneer.annotations.EditorProperty;
import com.interrupt.dungeoneer.game.Level;
import com.interrupt.dungeoneer.gfx.drawables.DrawableText;
public class Text extends DirectionalEntity {
@EditorProperty
public String text = "Test";
@EditorProperty
public Color textColor = new Color(Color.WHITE);
@EditorProperty
public DrawableText.TextAlignment textAlignment = DrawableText.TextAlignment.CENTER;
@EditorProperty
public boolean substituteControlLiterals;
@Deprecated
private String fontAtlas = "font";
@Deprecated
private float spacing = 1f;
private short entityVersion = 0;
public Text() {
drawable = new DrawableText();
this.isDynamic = false;
}
@Override
public void init(Level level, Level.Source source) {
// Handle conversion of old text entities.
if(entityVersion == 0) {
drawable = new DrawableText(); // Old drawable was a sprite
scale *= 5; // Scale is different now
textAlignment = DrawableText.TextAlignment.LEFT; // New default is center
attached.clear(); // The old text glyphs were attached sprites, so clear the attached entity list
z += 0.4f; // This is a weird offset, are we bumping the text up a little too high?
}
entityVersion = 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment