Skip to content

Commit 891bda3

Browse files
author
Builder
committed
Merge branch 'enable-bold-text' into 'master'
[FEAT][SDK] Enable bold text See merge request codingame/game-engine!143
2 parents 2f92257 + 3740c1c commit 891bda3

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Serializer {
4848
keys.put("strokeColor", "sc");
4949
keys.put("fontFamily", "ff");
5050
keys.put("fontSize", "s");
51+
keys.put("fontWeight", "fw");
5152
keys.put("text", "T");
5253
keys.put("children", "ch");
5354
keys.put("scaleX", "sx");

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,25 @@
77
*/
88
public class Text extends TextureBasedEntity<Text> {
99

10+
/**
11+
* The list of supported font weights.
12+
*
13+
*/
14+
public static enum FontWeight {
15+
NORMAL, BOLD, BOLDER, LIGHTER;
16+
17+
public String toString() {
18+
return name().toLowerCase();
19+
}
20+
}
21+
1022
private String text = "";
1123
private int strokeColor = 0;
1224
private double strokeThickness = 0;
1325
private int fillColor = 0;
1426
private int fontSize = 26;
1527
private String fontFamily = "Lato";
28+
private FontWeight fontWeight = FontWeight.NORMAL;
1629

1730
Text() {
1831
super();
@@ -132,6 +145,29 @@ public Text setStrokeThickness(double strokeThickness, Curve curve) {
132145
set("strokeThickness", strokeThickness, curve);
133146
return this;
134147
}
148+
/**
149+
* Sets the weight of the font of this <code>Text</code>.
150+
*
151+
* @param style
152+
* the FontWeight of the <code>Text</code>.
153+
* @return this <code>Text</code>.
154+
*/
155+
public Text setFontWeight(FontWeight weight) {
156+
this.fontWeight = weight;
157+
set("fontWeight", weight.toString());
158+
return this;
159+
}
160+
161+
/**
162+
* Returns the weight of the font of this <code>Text</code>.
163+
* <p>
164+
* Default is NORMAL.
165+
*
166+
* @return the weight of the font of this <code>Text</code>.
167+
*/
168+
public FontWeight getFontWeight() {
169+
return this.fontWeight;
170+
}
135171

136172
/**
137173
* Returns the color of the fill of this <code>Text</code> as an RGB integer.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const PROPERTY_KEY_MAP = {
2424
sc: 'strokeColor',
2525
ff: 'fontFamily',
2626
s: 'fontSize',
27+
fw: 'fontWeight',
2728
T: 'text',
2829
ch: 'children',
2930
sx: 'scaleX',

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export class Text extends TextureBasedEntity {
1111
strokeThickness: 0,
1212
fillColor: 0,
1313
fontSize: 26,
14-
fontFamily: 'Lato'
14+
fontFamily: 'Lato',
15+
fontWeight: 'normal'
1516
})
1617
}
1718

@@ -33,5 +34,6 @@ export class Text extends TextureBasedEntity {
3334
this.graphics.style.fill = state.fillColor
3435
this.graphics.style.fontSize = state.fontSize || 1
3536
this.graphics.style.fontFamily = state.fontFamily
37+
this.graphics.style.fontWeight = state.fontWeight
3638
}
3739
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export const PROPERTIES = {
102102
}
103103
},
104104
fontFamily: stringOpts,
105+
fontWeight: stringOpts,
105106
children: {
106107
...stringOpts,
107108
convert (value) {

0 commit comments

Comments
 (0)