Skip to content

Commit 65a46e8

Browse files
author
Builder
committed
Merge branch '5140-sdk-shapes-should-have-a-blendmode-property' into 'master'
[FEAT][SDK] sdk shapes should have a blendmode property See merge request codingame/game-engine!145
2 parents 1e99587 + c01effd commit 65a46e8

File tree

4 files changed

+55
-46
lines changed

4 files changed

+55
-46
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/Shape.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @param <T>
88
* a subclass inheriting Entity, used in order to return <b>this</b> as a T instead of a Shape.
99
*/
10-
public abstract class Shape<T extends Entity<?>> extends Entity<T> implements Mask {
10+
public abstract class Shape<T extends BlendableEntity<?>> extends BlendableEntity<T> implements Mask {
1111

1212
private int lineColor = 0x0, lineWidth = 0, fillColor = 0xffffff;
1313
private double fillAlpha = 1, lineAlpha = 1;

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.

engine/modules/entities/src/main/resources/view/entity-module/Shape.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export class Shape extends Entity {
2525
lineWidth: Shape.defaultLineWidth(),
2626
lineColor: Shape.defaultLineColor(),
2727
fillAlpha: Shape.defaultFillAlpha(),
28-
lineAlpha: Shape.defaultLineAlpha()
28+
lineAlpha: Shape.defaultLineAlpha(),
29+
blendMode: PIXI.BLEND_MODES.NORMAL
2930
})
3031
}
3132

@@ -40,5 +41,6 @@ export class Shape extends Entity {
4041

4142
updateDisplay (state, changed, globalData) {
4243
super.updateDisplay(state, changed, globalData)
44+
this.graphics.blendMode = state.blendMode
4345
}
4446
}

0 commit comments

Comments
 (0)