Starsector API
Loading...
Searching...
No Matches
CharAnim.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.eventide;
2
3import java.util.ArrayList;
4import java.util.LinkedHashSet;
5import java.util.List;
6import java.util.Set;
7
8import org.lwjgl.util.vector.Vector2f;
9
10import com.fs.starfarer.api.Global;
11import com.fs.starfarer.api.graphics.SpriteAPI;
12
13public class CharAnim implements Cloneable {
14
15 public String textureId;
16 public SpriteAPI sprite;
17 public float scale = 1f;
18 public float frameHeight;
19 public float widthSoFar = 0f;
20 public float totalTime = 0f;
21 public List<CharAnimFrame> frames = new ArrayList<CharAnimFrame>();
23 public Float initialRelativeOffset = null;
24 public Vector2f moveToIdle = new Vector2f();
25 public String action;
26
27 public Set<String> interruptableBy = new LinkedHashSet<String>();
28
29 @Override
30 public CharAnim clone() {
31 try {
32 CharAnim copy = (CharAnim) super.clone();
33 copy.frames = new ArrayList<CharAnimFrame>();
34 for (CharAnimFrame frame : frames) {
35 CharAnimFrame cf = frame.clone();
36 copy.frames.add(cf);
37 }
38 copy.sprite = Global.getSettings().getSprite(textureId);
39 copy.totalTime = totalTime;
40 copy.interruptableBy = new LinkedHashSet<String>(interruptableBy);
41 copy.moveToIdle = new Vector2f(moveToIdle);
42 copy.last = last.clone();
43 return copy;
44 } catch (CloneNotSupportedException e) {
45 throw new RuntimeException(e);
46 }
47 }
48
49 public void removeFirstFrame() {
50 CharAnimFrame frame = frames.remove(0);
51 totalTime -= frame.dur;
52 }
53
54 public CharAnim(String textureId, String action, float frameHeight) {
55 this.textureId = textureId;
56 this.action = action;
58 this.frameHeight = frameHeight;
59 }
60
61 public boolean hasBlockFrames() {
62 for (CharAnimFrame frame : frames) {
63 if (!frame.blockArea.isEmpty()) return true;
64 }
65 return false;
66 }
67 public boolean hasAttackFrames() {
68 for (CharAnimFrame frame : frames) {
69 if (!frame.attackArea.isEmpty()) return true;
70 }
71 return false;
72 }
73
74 public void interruptableBy(String ...actions) {
75 for (String action : actions) {
77 }
78 }
79
80// public CharAnim createReverse(String action) {
81// CharAnim rev = new CharAnim(textureId, action, frameHeight);
82// for (CharAnimFrame frame : frames) {
83// CharAnimFrame copy = frame.clone();
84// copy.move.negate();
85// rev.frames.add(0, copy);
86// }
87// rev.last = rev.frames.get(rev.frames.size() - 1);
88// rev.scale = scale;
89// rev.totalTime = totalTime;
90// rev.widthSoFar = widthSoFar;
91// //rev.moveToIdle = // depends on the new last frame; can't auto-figure-this-out
92// return rev;
93// }
94
95 public void skip(CharAnim anim) {
96 widthSoFar += anim.widthSoFar;
97 }
98 public void skip(float frameWidth) {
99 widthSoFar += frameWidth;
100 }
101 public void addFrame(float y, float frameWidth, float dur) {
102 float txPerPixel = sprite.getTextureWidth() / sprite.getWidth();
103 float tyPerPixel = sprite.getTextureHeight() / sprite.getHeight();
104
105 CharAnimFrame frame = new CharAnimFrame();
106 frame.dur = dur;
107 frame.tx = widthSoFar * txPerPixel;
108 frame.ty = y * tyPerPixel;
109 frame.tw = frameWidth * txPerPixel;
110 frame.th = frameHeight * tyPerPixel;
111 frame.width = frameWidth;
112 frame.height = frameHeight;
113 widthSoFar += frameWidth;
114
115 totalTime += dur;
116
117 frames.add(frame);
118 last = frame;
119 }
120
121
122 public float getTotalTime() {
123 return totalTime;
124 }
125
126 public void updateTextureScale(float scale) {
127 for (CharAnimFrame frame : frames) {
128 frame.tx *= scale;
129 frame.ty *= scale;
130 frame.tw *= scale;
131 frame.th *= scale;
132 }
133 }
134}
135
136
137
138
139
140
static SettingsAPI getSettings()
Definition Global.java:51
void addFrame(float y, float frameWidth, float dur)
CharAnim(String textureId, String action, float frameHeight)
Definition CharAnim.java:54
SpriteAPI getSprite(String filename)