-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraInstruction.java
More file actions
366 lines (327 loc) · 8.74 KB
/
CameraInstruction.java
File metadata and controls
366 lines (327 loc) · 8.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
package cn.nukkitmot.exampleplugin.camera;
import cn.nukkit.Player;
import cn.nukkit.command.CommandSender;
import cn.nukkit.command.data.CommandParamType;
import cn.nukkit.command.data.CommandParameter;
import cn.nukkit.math.Vector3;
import java.util.HashMap;
import java.util.Map;
/**
* 镜头指令封装类
* <p>
* 封装了发送到客户端的相机指令数据,支持多种镜头控制方式。
*
* @author QingTong
* @version 1.0.0
* @since 1.0.0
*/
public class CameraInstruction {
private final InstructionType type;
private final CameraMode mode;
private final CameraPosition position;
private final CameraPreset preset;
private final String presetName;
private final float easeTime;
private final EaseType easeType;
private final boolean defaultPreset;
private CameraInstruction(Builder builder) {
this.type = builder.type;
this.mode = builder.mode;
this.position = builder.position;
this.preset = builder.preset;
this.presetName = builder.presetName;
this.easeTime = builder.easeTime;
this.easeType = builder.easeType;
this.defaultPreset = builder.defaultPreset;
}
/**
* 获取指令类型
*
* @return 指令类型
*/
public InstructionType getType() {
return type;
}
/**
* 获取镜头模式
*
* @return 镜头模式
*/
public CameraMode getMode() {
return mode;
}
/**
* 获取镜头位置
*
* @return 镜头位置
*/
public CameraPosition getPosition() {
return position;
}
/**
* 获取预设配置
*
* @return 预设配置
*/
public CameraPreset getPreset() {
return preset;
}
/**
* 获取预设名称
*
* @return 预设名称
*/
public String getPresetName() {
return presetName;
}
/**
* 获取缓动时间
*
* @return 缓动时间(秒)
*/
public float getEaseTime() {
return easeTime;
}
/**
* 获取缓动类型
*
* @return 缓动类型
*/
public EaseType getEaseType() {
return easeType;
}
/**
* 是否为默认预设
*
* @return true 如果是默认预设
*/
public boolean isDefaultPreset() {
return defaultPreset;
}
/**
* 将指令转换为命令字符串
*
* @param player 目标玩家
* @return 命令字符串
*/
public String toCommandString(Player player) {
StringBuilder cmd = new StringBuilder("/camera ");
cmd.append(player.getName()).append(" ");
switch (type) {
case CLEAR:
cmd.append("clear");
break;
case SET:
cmd.append("set ");
if (presetName != null) {
cmd.append(presetName);
if (defaultPreset) {
cmd.append(" default");
}
} else if (preset != null) {
cmd.append(preset.getName());
}
if (easeTime > 0) {
cmd.append(" ease ").append(easeTime).append(" ").append(easeType.getName());
}
if (position != null) {
Vector3 pos = position.getPosition();
cmd.append(" pos ").append(pos.x).append(" ").append(pos.y).append(" ").append(pos.z);
Vector3 rot = position.getRotation();
if (rot.x != 0 || rot.y != 0) {
cmd.append(" rot ").append(rot.x).append(" ").append(rot.y);
}
}
break;
case FADE:
cmd.append("fade");
break;
}
return cmd.toString();
}
/**
* 指令类型枚举
*/
public enum InstructionType {
/**
* 清除镜头设置,恢复正常视角
*/
CLEAR,
/**
* 设置镜头
*/
SET,
/**
* 镜头淡入淡出效果
*/
FADE
}
/**
* 缓动类型枚举
*/
public enum EaseType {
LINEAR("linear"),
SPRING("spring"),
IN_QUAD("in_quad"),
OUT_QUAD("out_quad"),
IN_OUT_QUAD("in_out_quad"),
IN_CUBIC("in_cubic"),
OUT_CUBIC("out_cubic"),
IN_OUT_CUBIC("in_out_cubic"),
IN_QUART("in_quart"),
OUT_QUART("out_quart"),
IN_OUT_QUART("in_out_quart"),
IN_SINE("in_sine"),
OUT_SINE("out_sine"),
IN_OUT_SINE("in_out_sine"),
IN_EXPO("in_expo"),
OUT_EXPO("out_expo"),
IN_OUT_EXPO("in_out_expo"),
IN_CIRC("in_circ"),
OUT_CIRC("out_circ"),
IN_OUT_CIRC("in_out_circ"),
IN_BOUNCE("in_bounce"),
OUT_BOUNCE("out_bounce"),
IN_OUT_BOUNCE("in_out_bounce"),
IN_BACK("in_back"),
OUT_BACK("out_back"),
IN_OUT_BACK("in_out_back"),
IN_ELASTIC("in_elastic"),
OUT_ELASTIC("out_elastic"),
IN_OUT_ELASTIC("in_out_elastic");
private final String name;
EaseType(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
/**
* 构建器类
*/
public static class Builder {
private InstructionType type = InstructionType.SET;
private CameraMode mode;
private CameraPosition position;
private CameraPreset preset;
private String presetName;
private float easeTime = 0;
private EaseType easeType = EaseType.LINEAR;
private boolean defaultPreset = false;
/**
* 设置指令类型
*
* @param type 指令类型
* @return Builder 实例
*/
public Builder type(InstructionType type) {
this.type = type;
return this;
}
/**
* 设置镜头模式
*
* @param mode 镜头模式
* @return Builder 实例
*/
public Builder mode(CameraMode mode) {
this.mode = mode;
return this;
}
/**
* 设置镜头位置
*
* @param position 镜头位置
* @return Builder 实例
*/
public Builder position(CameraPosition position) {
this.position = position;
return this;
}
/**
* 设置预设配置
*
* @param preset 预设配置
* @return Builder 实例
*/
public Builder preset(CameraPreset preset) {
this.preset = preset;
return this;
}
/**
* 设置预设名称
*
* @param presetName 预设名称
* @return Builder 实例
*/
public Builder presetName(String presetName) {
this.presetName = presetName;
return this;
}
/**
* 设置缓动时间
*
* @param easeTime 缓动时间(秒)
* @return Builder 实例
*/
public Builder easeTime(float easeTime) {
this.easeTime = easeTime;
return this;
}
/**
* 设置缓动类型
*
* @param easeType 缓动类型
* @return Builder 实例
*/
public Builder easeType(EaseType easeType) {
this.easeType = easeType;
return this;
}
/**
* 设置为默认预设
*
* @param defaultPreset 是否为默认
* @return Builder 实例
*/
public Builder defaultPreset(boolean defaultPreset) {
this.defaultPreset = defaultPreset;
return this;
}
/**
* 构建 CameraInstruction 实例
*
* @return CameraInstruction 实例
*/
public CameraInstruction build() {
return new CameraInstruction(this);
}
}
/**
* 创建清除镜头指令
*
* @return CameraInstruction 实例
*/
public static CameraInstruction clear() {
return new Builder().type(InstructionType.CLEAR).build();
}
/**
* 创建设置预设镜头指令
*
* @param preset 预设配置
* @return CameraInstruction 实例
*/
public static CameraInstruction setPreset(CameraPreset preset) {
return new Builder().preset(preset).build();
}
/**
* 创建设置位置镜头指令
*
* @param position 镜头位置
* @return CameraInstruction 实例
*/
public static CameraInstruction setPosition(CameraPosition position) {
return new Builder().position(position).build();
}
}