Skip to content

Commit 89f017e

Browse files
committed
refactor(sdk): create a blendableEntity class
1 parent ca4f771 commit 89f017e

File tree

2 files changed

+51
-44
lines changed

2 files changed

+51
-44
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.codingame.gameengine.module.entities;
2+
3+
public abstract class BlendableEntity<T extends Entity<?>> extends Entity<T> {
4+
/**
5+
* The list of supported PIXI blend modes and their associated constant.
6+
*
7+
* @see <a href="http://pixijs.download/dev/docs/PIXI.html#.BLEND_MODES">PIXI BLEND_MODES</a>
8+
*/
9+
public static enum BlendMode {
10+
NORMAL(0), ADD(1), MULTIPLY(2), SCREEN(3);
11+
private int value;
12+
13+
private BlendMode(int value) {
14+
this.value = value;
15+
}
16+
17+
private int getValue() {
18+
return value;
19+
}
20+
}
21+
22+
private BlendMode blendMode;
23+
24+
/**
25+
* Returns the <code>BlendMode</code> this <code>TextureBasedEntity</code> is to be drawn with.
26+
*
27+
* @see <a href="http://pixijs.download/dev/docs/PIXI.html#.BLEND_MODES">PIXI BLEND_MODES</a>
28+
* @return the <code>BlendMode</code> this <code>TextureBasedEntity</code> is to be drawn with.
29+
*/
30+
public BlendMode getBlendMode() {
31+
return blendMode;
32+
}
33+
34+
/**
35+
* Sets the blend mode for this <code>TextureBasedEntity</code>.
36+
* <p>
37+
* The possible values are found in <code>BlendMode</code>.
38+
*
39+
* @see <a href="http://pixijs.download/dev/docs/PIXI.html#.BLEND_MODES">PIXI BLEND_MODES</a>
40+
* @param blendMode
41+
* @return this <code>TextureBasedEntity</code>.
42+
*/
43+
public T setBlendMode(BlendMode blendMode) {
44+
this.blendMode = blendMode;
45+
set("blendMode", blendMode.getValue(), null);
46+
return self();
47+
}
48+
}

engine/modules/entities/src/main/java/com/codingame/gameengine/module/entities/TextureBasedEntity.java

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,17 @@
55
*
66
* @param <T> a subclass inheriting Entity, used in order to return <b>this</b> as a T instead of a <code>TextureBasedEntity</code>.
77
*/
8-
public abstract class TextureBasedEntity<T extends Entity<?>> extends Entity<T> {
8+
public abstract class TextureBasedEntity<T extends BlendableEntity<?>> extends BlendableEntity<T> {
99

10-
/**
11-
* The list of supported PIXI blend modes and their associated constant.
12-
*
13-
* @see <a href="http://pixijs.download/dev/docs/PIXI.html#.BLEND_MODES">PIXI BLEND_MODES</a>
14-
*/
15-
public static enum BlendMode {
16-
NORMAL(0), ADD(1), MULTIPLY(2), SCREEN(3);
17-
private int value;
18-
19-
private BlendMode(int value) {
20-
this.value = value;
21-
}
22-
23-
private int getValue() {
24-
return value;
25-
}
26-
}
27-
28-
private BlendMode blendMode;
10+
2911
private double anchorX = 0, anchorY = 0;
3012
private int tint = 0xFFFFFF;
3113

3214
TextureBasedEntity() {
3315
super();
3416
}
3517

36-
/**
37-
* Returns the <code>BlendMode</code> this <code>TextureBasedEntity</code> is to be drawn with.
38-
*
39-
* @see <a href="http://pixijs.download/dev/docs/PIXI.html#.BLEND_MODES">PIXI BLEND_MODES</a>
40-
* @return the <code>BlendMode</code> this <code>TextureBasedEntity</code> is to be drawn with.
41-
*/
42-
public BlendMode getBlendMode() {
43-
return blendMode;
44-
}
45-
46-
/**
47-
* Sets the blend mode for this <code>TextureBasedEntity</code>.
48-
* <p>
49-
* The possible values are found in <code>BlendMode</code>.
50-
*
51-
* @see <a href="http://pixijs.download/dev/docs/PIXI.html#.BLEND_MODES">PIXI BLEND_MODES</a>
52-
* @param blendMode
53-
* @return this <code>TextureBasedEntity</code>.
54-
*/
55-
public T setBlendMode(BlendMode blendMode) {
56-
this.blendMode = blendMode;
57-
set("blendMode", blendMode.getValue(), null);
58-
return self();
59-
}
18+
6019

6120
/**
6221
* Sets both the X and Y anchors of this <code>TextureBasedEntity</code> as a percentage of its width and height.

0 commit comments

Comments
 (0)