-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d95ee9a
commit 48c4555
Showing
8 changed files
with
175 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package net.aegistudio.magick.seal; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
import org.bukkit.configuration.ConfigurationSection; | ||
import org.bukkit.entity.Entity; | ||
|
||
import net.aegistudio.magick.MagickElement; | ||
|
||
public class AnimationFactory implements PainterFactory { | ||
public List<String> order; | ||
public static final String ORDER = "order"; | ||
|
||
public Map<String, PainterFactory> factory; | ||
public Map<String, Integer> ticks; | ||
public static final String CLASS = "Class"; | ||
public static final String CONFIG = "Config"; | ||
public static final String TICKS = "Ticks"; | ||
|
||
@Override | ||
public void load(MagickElement magick, ConfigurationSection config) throws Exception { | ||
this.order = config.getStringList(ORDER); | ||
this.factory = new TreeMap<String, PainterFactory>(); | ||
this.ticks = new TreeMap<String, Integer>(); | ||
|
||
for(String current : order) { | ||
factory.put(current, magick.loadInstance(PainterFactory.class, config, current.concat(CLASS), | ||
null, current.concat(CONFIG), null)); | ||
ticks.put(current, config.getInt(current.concat(TICKS))); | ||
} | ||
} | ||
|
||
@Override | ||
public void save(MagickElement element, ConfigurationSection config) throws Exception { | ||
config.set(ORDER, order); | ||
for(String current : order) { | ||
PainterFactory pFactory = factory.get(current); | ||
config.set(current.concat(CLASS), pFactory.getClass().getName()); | ||
if(!config.contains(current.concat(CONFIG))) config.createSection(current.concat(CONFIG)); | ||
pFactory.save(element, config.getConfigurationSection(current.concat(CONFIG))); | ||
|
||
config.set(current.concat(TICKS), ticks.get(current)); | ||
} | ||
} | ||
|
||
@Override | ||
public void after(MagickElement element) { | ||
for(PainterFactory pf : this.factory.values()) | ||
pf.after(element); | ||
} | ||
|
||
@Override | ||
public Painter newPainter(Entity entity) { | ||
ArrayList<Painter> factory = new ArrayList<Painter>(); | ||
ArrayList<Integer> ticks = new ArrayList<Integer>(); | ||
for(String current : order) { | ||
factory.add(this.factory.get(current).newPainter(entity)); | ||
ticks.add(this.ticks.get(current)); | ||
} | ||
return new AnimationPainter(factory.toArray(new Painter[0]), ticks.toArray(new Integer[0])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package net.aegistudio.magick.seal; | ||
|
||
public class AnimationPainter implements Painter { | ||
protected final Painter[] painter; | ||
protected final Integer[] tick; | ||
|
||
protected int index; | ||
protected int frame; | ||
|
||
public AnimationPainter(Painter[] painter, Integer[] tick) { | ||
this.painter = painter; | ||
this.tick = tick; | ||
|
||
this.index = 0; | ||
this.frame = 0; | ||
} | ||
|
||
@Override | ||
public void paint(double x, double y, double z) { | ||
if(index < painter.length) | ||
painter[index].paint(x, y, z); | ||
} | ||
|
||
@Override | ||
public void end() { | ||
if(index < tick.length) { | ||
painter[index].end(); | ||
frame ++; | ||
|
||
if(tick[index] >= 0 && frame > tick[index]) { | ||
index ++; | ||
frame = 0; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package net.aegistudio.magick.seal; | ||
|
||
import org.bukkit.configuration.ConfigurationSection; | ||
import org.bukkit.entity.Entity; | ||
|
||
import net.aegistudio.magick.MagickElement; | ||
|
||
public class ZoomFactory extends WrappedPainterFactory { | ||
private double init = 0.0; | ||
public static final String INIT = "init"; | ||
private double zoom = 0.1; | ||
public static final String ZOOM = "zoom"; | ||
|
||
@Override | ||
public void load(MagickElement magick, ConfigurationSection config) throws Exception { | ||
super.load(magick, config); | ||
this.init = config.getDouble(INIT); | ||
this.zoom = config.getDouble(ZOOM); | ||
} | ||
|
||
@Override | ||
public void save(MagickElement element, ConfigurationSection config) throws Exception { | ||
super.save(element, config); | ||
config.set(INIT, init); | ||
config.set(ZOOM, zoom); | ||
} | ||
|
||
@Override | ||
public Painter newPainter(Entity entity) { | ||
return new TransformPainter(this.wrapped.newPainter(entity), new double[][] { | ||
{zoom, 0, 0, 0}, | ||
{0, zoom, 0, 0}, | ||
{0, 0, zoom, 0}, | ||
{0, 0, 0, 0} | ||
}, new double[][] { | ||
{init, 0, 0, 0}, | ||
{0, init, 0, 0}, | ||
{0, 0, init, 0}, | ||
{0, 0, 0, 1} | ||
}){ | ||
@Override | ||
public void end() { | ||
this.addTrans(); | ||
this.next.end(); | ||
} | ||
}; | ||
} | ||
} |