Skip to content

Commit fd921e8

Browse files
committed
Fixed strings
1 parent d4d03b6 commit fd921e8

File tree

5 files changed

+52
-9
lines changed

5 files changed

+52
-9
lines changed

src/main/java/bwapi/BWClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void startGame(BWClientConfiguration configuration) {
8080
break;
8181
}
8282
long frameDurationMillis = System.currentTimeMillis() - lastUpdateTimestampMillis;
83-
if (botWrapper.frameDurationMillis > configuration.asyncFrameDurationMillis && (client.clientData().gameData().getFrameCount() > 0 || ! configuration.asyncWaitOnFrameZero)) {
83+
if (frameDurationMillis > configuration.asyncFrameDurationMillis && (client.clientData().gameData().getFrameCount() > 0 || ! configuration.asyncWaitOnFrameZero)) {
8484
System.out.println("Client: Proceeding because frame " + botWrapper.getGame().getFrameCount() + " lasted " + frameDurationMillis + "ms");
8585
break;
8686
}

src/main/java/bwapi/Game.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ static String formatString(final String string, final Text... colors) {
14851485
*/
14861486
public void printf(final String string, final Text... colors) {
14871487
final String formatted = formatString(string, colors);
1488-
addCommand(Printf, GameDataUtils.addString(gameData(), formatted), 0);
1488+
addCommand(Printf, formatted, 0);
14891489
}
14901490

14911491
/**
@@ -1510,7 +1510,7 @@ public void sendText(final String string, final Text... colors) {
15101510
*/
15111511
public void sendTextEx(final boolean toAllies, final String string, final Text... colors) {
15121512
final String formatted = formatString(string, colors);
1513-
addCommand(SendText, GameDataUtils.addString(gameData(), formatted), toAllies ? 1 : 0);
1513+
addCommand(SendText, formatted, toAllies ? 1 : 0);
15141514
}
15151515

15161516
/**
@@ -1719,8 +1719,7 @@ public List<Player> observers() {
17191719

17201720
public void drawText(final CoordinateType ctype, final int x, final int y, final String string, final Text... colors) {
17211721
final String formatted = formatString(string, colors);
1722-
final int stringId = GameDataUtils.addString(gameData(), formatted);
1723-
addShape(ShapeType.Text, ctype, x, y, 0, 0, stringId, textSize.id, 0, false);
1722+
addShape(ShapeType.Text, ctype, x, y, 0, 0, formatted, textSize.id, 0, false);
17241723
}
17251724

17261725
public void drawTextMap(final int x, final int y, final String string, final Text... colors) {
@@ -2335,7 +2334,7 @@ public boolean setMap(final String mapFileName) {
23352334
return false;
23362335
}
23372336

2338-
addCommand(CommandType.SetMap, GameDataUtils.addString(gameData(), mapFileName), 0);
2337+
addCommand(CommandType.SetMap, mapFileName, 0);
23392338
return true;
23402339
}
23412340

@@ -2674,10 +2673,25 @@ void addCommand(final CommandType type, final int value1, final int value2) {
26742673
sideEffects.enqueue(SideEffect.addCommand(type, value1, value2));
26752674
}
26762675

2676+
2677+
/**
2678+
* Convenience method for adding a game command from raw arguments.
2679+
*/
2680+
void addCommand(final CommandType type, final String value1, final int value2) {
2681+
sideEffects.enqueue(SideEffect.addCommand(type, value1, value2));
2682+
}
2683+
26772684
/**
26782685
* Convenience method for adding a shape from raw arguments.
26792686
*/
26802687
void addShape(final ShapeType type, final CoordinateType coordType, final int x1, final int y1, final int x2, final int y2, final int extra1, final int extra2, final int color, final boolean isSolid) {
26812688
sideEffects.enqueue(SideEffect.addShape(type, coordType, x1, y1, x2, y2, extra1, extra2, color, isSolid));
26822689
}
2690+
2691+
/**
2692+
* Convenience method for adding a shape from raw arguments.
2693+
*/
2694+
void addShape(final ShapeType type, final CoordinateType coordType, final int x1, final int y1, final int x2, final int y2, final String text, final int extra2, final int color, final boolean isSolid) {
2695+
sideEffects.enqueue(SideEffect.addShape(type, coordType, x1, y1, x2, y2, text, extra2, color, isSolid));
2696+
}
26832697
}

src/main/java/bwapi/GameDataUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ of this software and associated documentation files (the "Software"), to deal
2929
* Static functions for modifying GameData.
3030
* These functions live outside GameData because GameData is auto-generated.
3131
*/
32-
public class GameDataUtils {
32+
class GameDataUtils {
3333

3434
static final int MAX_COUNT = 19999;
35-
static final int MAX_STRING_SIZE = 1024;
35+
private static final int MAX_STRING_SIZE = 1024;
3636

3737
static int addString(ClientData.GameData gameData, final String string) {
3838
int stringCount = gameData.getStringCount();

src/main/java/bwapi/SideEffect.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ static SideEffect addCommand(final CommandType type, final int value1, final int
4242
return output;
4343
}
4444

45+
static SideEffect addCommand(final CommandType type, final String text, final int value2) {
46+
SideEffect output = new SideEffect();
47+
output.application = (ClientData clientData) -> {
48+
ClientData.Command command = GameDataUtils.addCommand(clientData.gameData());
49+
command.setType(type);
50+
command.setValue1(GameDataUtils.addString(clientData.gameData(), text));
51+
command.setValue2(value2);
52+
};
53+
return output;
54+
}
55+
4556
static SideEffect addShape(final ShapeType type, final CoordinateType coordType, final int x1, final int y1, final int x2, final int y2, final int extra1, final int extra2, final int color, final boolean isSolid) {
4657
SideEffect output = new SideEffect();
4758
output.application = (ClientData clientData) -> {
@@ -59,4 +70,22 @@ static SideEffect addShape(final ShapeType type, final CoordinateType coordType,
5970
};
6071
return output;
6172
}
73+
74+
static SideEffect addShape(final ShapeType type, final CoordinateType coordType, final int x1, final int y1, final int x2, final int y2, final String text, final int extra2, final int color, final boolean isSolid) {
75+
SideEffect output = new SideEffect();
76+
output.application = (ClientData clientData) -> {
77+
ClientData.Shape shape = GameDataUtils.addShape(clientData.gameData());
78+
shape.setType(type);
79+
shape.setCtype(coordType);
80+
shape.setX1(x1);
81+
shape.setY1(y1);
82+
shape.setX2(x2);
83+
shape.setY2(y2);
84+
shape.setExtra1(GameDataUtils.addString(clientData.gameData(), text));
85+
shape.setExtra2(extra2);
86+
shape.setColor(color);
87+
shape.setIsSolid(isSolid);
88+
};
89+
return output;
90+
}
6291
}

src/main/java/bwapi/SideEffectQueue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Queue of intended bot interactions with the game, to be flushed as JBWAPI returns control to StarCraft after a frame.
77
*/
8-
public class SideEffectQueue {
8+
class SideEffectQueue {
99

1010
private ArrayList<SideEffect> queue = new ArrayList<>();
1111

0 commit comments

Comments
 (0)