Skip to content

Commit 8e4a1d1

Browse files
Merge branch '5343-sdk-spritesheetsplitter-could-take-the-full-height-or-weigth-if-none-given' into 'master'
feature(spriteSheetSplitter): crop using full height or width of spritesheet if no h/w given See merge request codingame/game-engine!257
2 parents 20c6bf4 + 2209457 commit 8e4a1d1

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,8 @@ public Optional<String> serializeCreateEntities(List<Entity<?>> entities) {
221221

222222
private String serializeLoadSpriteSheet(SpriteSheetSplitter spriteSheet) {
223223
return join(
224-
spriteSheet.getName(), spriteSheet.getSourceImage(),
225-
spriteSheet.getWidth(), spriteSheet.getHeight(), spriteSheet.getOrigRow(), spriteSheet.getOrigCol(), spriteSheet.getImageCount(),
226-
spriteSheet.getImagesPerRow()
224+
spriteSheet.getName(), spriteSheet.getSourceImage(), spriteSheet.getWidth(), spriteSheet.getHeight(),
225+
spriteSheet.getOrigRow(), spriteSheet.getOrigCol(), spriteSheet.getImageCount(), spriteSheet.getImagesPerRow()
227226
);
228227
}
229228

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
public class SpriteSheetSplitter {
1515
private String name;
1616
private String sourceImage;
17-
private Integer width;
18-
private Integer height;
17+
private Integer width = 0; // 0 means take full width of spritesheet
18+
private Integer height = 0; // 0 means take full height of spritesheet
1919
private Integer origRow;
2020
private Integer origCol;
2121
private Integer imageCount;
@@ -120,20 +120,28 @@ public SpriteSheetSplitter setSourceImage(String sourceImage) {
120120

121121
/**
122122
* Sets the width of the subimages to extract
123+
* Defaults to full width of spritesheet if not set
123124
* @param width the width of the subimages
124125
* @return this <code>SpriteSheetSplitter</code>
125126
*/
126127
public SpriteSheetSplitter setWidth(int width) {
128+
if (width <= 0) {
129+
throw new IllegalStateException("invalid width");
130+
}
127131
this.width = width;
128132
return this;
129133
}
130134

131135
/**
132136
* Sets the height of the subimages to extract
137+
* Defaults to full height of spritesheet if not set
133138
* @param height the height of the subimages
134139
* @return this <code>SpriteSheetSplitter</code>
135140
*/
136141
public SpriteSheetSplitter setHeight(int height) {
142+
if (height <= 0) {
143+
throw new IllegalStateException("invalid height");
144+
}
137145
this.height = height;
138146
return this;
139147
}
@@ -193,12 +201,6 @@ public String[] split() {
193201
if (sourceImage == null) {
194202
throw new IllegalStateException("invalid sourceImage");
195203
}
196-
if (width == null || width <= 0) {
197-
throw new IllegalStateException("invalid width");
198-
}
199-
if (height == null || height <= 0) {
200-
throw new IllegalStateException("invalid height");
201-
}
202204
if (imageCount == null || imageCount <= 0) {
203205
throw new IllegalStateException("invalid imageCount");
204206
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ export class LoadCommand {
8181
constructor ([assetName, sourceImage, imageWidth, imageHeight, origRow, origCol, imageCount, imagesPerRow], globalData) {
8282
this.loader = new PIXI.loaders.Loader()
8383

84+
if (imageWidth === '0') {
85+
imageWidth = PIXI.utils.TextureCache[sourceImage].width
86+
}
87+
if (imageHeight === '0') {
88+
imageHeight = PIXI.utils.TextureCache[sourceImage].height
89+
}
90+
8491
const _imagesPerRow = imagesPerRow > 0 ? imagesPerRow : imageCount
8592
const data = {
8693
frames: {},

playground/misc/misc-3-release-notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The CodinGame SDK is regularly updated and improved. This document lets you know
77
### 🎁 Features
88

99
- Added text-align property to TextBasedEntity
10+
- SpriteSheetSplitter splits using full width and/or height of spritesheet when width and/or height not set.
1011

1112
### 🐞 Bug fix
1213

0 commit comments

Comments
 (0)