Java Code Examples for com.badlogic.gdx.utils.StringBuilder#append()

The following examples show how to use com.badlogic.gdx.utils.StringBuilder#append() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DialogSceneComposerJavaBuilder.java    From skin-composer with MIT License 6 votes vote down vote up
private static String alignmentToName(int align) {
    StringBuilder buffer = new StringBuilder(13);
    if ((align & Align.top) != 0)
        buffer.append("top");
    else if ((align & Align.bottom) != 0)
        buffer.append("bottom");
    else {
        if ((align & Align.left) != 0)
            buffer.append("left");
        else if ((align & Align.right) != 0)
            buffer.append("right");
        else
            buffer.append("center");
        return buffer.toString();
    }
    if ((align & Align.left) != 0)
        buffer.append("Left");
    else if ((align & Align.right) != 0)
        buffer.append("Right");
    return buffer.toString();
}
 
Example 2
Source File: BehaviorTreeViewer.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
private static void appendFieldString (StringBuilder sb, Task<?> task, TaskAttribute ann, Field field) {
	// prefer name from annotation if there is one
	String name = ann.name();
	if (name == null || name.length() == 0) name = field.getName();
	Object value;
	try {
		field.setAccessible(true);
		value = field.get(task);
	} catch (ReflectionException e) {
		Gdx.app.error("", "Failed to get field", e);
		return;
	}
	sb.append(name).append(":");
	Class<?> fieldType = field.getType();
	if (fieldType.isEnum() || fieldType == String.class) {
		sb.append('\"').append(value).append('\"');
	} else if (Distribution.class.isAssignableFrom(fieldType)) {
		sb.append('\"').append(DAs.toString((Distribution)value)).append('\"');
	} else
		sb.append(value);
}
 
Example 3
Source File: DungeonUtils.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
public static String mapToString (int[][] map) {
	StringBuilder sb = new StringBuilder(map.length * (map[0].length + 1)); // +1 is due to the new line char
	for (int x = 0; x < map.length; x++) {
		for (int y = 0; y < map[0].length; y++) {
			switch (map[x][y]) {
			case TILE_EMPTY:
				sb.append(' ');
				break;
			case TILE_FLOOR:
				sb.append('.');
				break;
			case TILE_WALL:
				sb.append('#');
				break;
			default:
				sb.append('?');
				break;
			}
		}
		sb.append('\n');
	}
	return sb.toString();
}
 
Example 4
Source File: HUD.java    From gdx-proto with Apache License 2.0 6 votes vote down vote up
public void showChatMessages(StringBuilder sb) {
	for (ChatMessage chat : chatMessages) {
		long elapsed = TimeUtils.timeSinceMillis(chat.createTime);
		if (elapsed >= chatMessageLifeTime) {
			chatMessages.removeValue(chat, true);
		} else {
			sb.append("\n[");
			if (chat.playerId == -1) {
				sb.append("Server");
			} else {
				sb.append("Player ").append(chat.playerId);
			}
			sb.append("]: ").append(chat.text);
		}
	}
}
 
Example 5
Source File: Dialogs.java    From vis-ui with Apache License 2.0 6 votes vote down vote up
private static void getStackTrace (Throwable throwable, StringBuilder builder) {
	String msg = throwable.getMessage();
	if (msg != null) {
		builder.append(msg);
		builder.append("\n\n");
	}

	for (StackTraceElement element : throwable.getStackTrace()) {
		builder.append(element);
		builder.append("\n");
	}

	if (throwable.getCause() != null) {
		builder.append("\nCaused by: ");
		getStackTrace(throwable.getCause(), builder);
	}
}
 
Example 6
Source File: SHA1.java    From libgdx-snippets with MIT License 6 votes vote down vote up
@Override
public String toString() {

	StringBuilder builder = algorithm.stringBuilder.get();
	builder.setLength(0);

	int v;
	char c;

	for (byte b : value) {
		v = (b & 0xf0) >> 4;
		c = (v < 10) ? (char) ('0' + v) : (char) ('a' + v - 10);
		builder.append(c);
		v = b & 0x0f;
		c = (v < 10) ? (char) ('0' + v) : (char) ('a' + v - 10);
		builder.append(c);
	}

	return builder.toString();
}
 
Example 7
Source File: TextFileUtils.java    From libgdx-snippets with MIT License 6 votes vote down vote up
public static void writeString(FileHandle file, String text) throws IOException {

		StringBuilder builder = new StringBuilder(text.length());
		String newLine = Host.os != Host.OS.Windows ? "\n" : "\r\n";

		try (BufferedReader reader = new BufferedReader(new StringReader(text))) {

			String line;
			while ((line = reader.readLine()) != null) {

				if (builder.length() > 0) {
					builder.append(newLine);
				}

				builder.append(line);
			}
		}

		file.writeString(builder.toString(), false);
	}
 
Example 8
Source File: TXT.java    From riiablo with Apache License 2.0 6 votes vote down vote up
private static String[] split(int len, String str, char token) {
  StringBuilder builder = new StringBuilder(32);
  String[] tokens = new String[len];
  char c;
  int numTokens = 0;
  final int strLen = str.length();
  for (int i = 0; i < strLen; i++) {
    c = str.charAt(i);
    if (c == token) {
      tokens[numTokens++] = builder.toString();
      builder.setLength(0);
    } else {
      builder.append(c);
    }
  }
  if (numTokens < len) Arrays.fill(tokens, numTokens, len, StringUtils.EMPTY);
  return tokens;
}
 
Example 9
Source File: PlayDataAccessor.java    From beatoraja with GNU General Public License v3.0 6 votes vote down vote up
private String getReplayDataFilePath(String[] hashes, boolean ln, int lnmode, int index,
		CourseData.CourseDataConstraint[] constraint) {
	StringBuilder hash = new StringBuilder();
	for (String s : hashes) {
		hash.append(s.substring(0, 10));
	}
	StringBuilder sb = new StringBuilder();
	for (CourseData.CourseDataConstraint c : constraint) {
		if (c != CLASS && c != MIRROR && c != RANDOM) {
			for(int i = 0;i < CourseDataConstraint.values().length;i++) {
				if(c == CourseDataConstraint.values()[i]) {
					sb.append(String.format("%02d", i + 1));
					break;
				}
			}
		}
	}
	return this.getReplayDataFolder() + File.separatorChar
			+ (ln ? replay[lnmode] : "") + hash + (sb.length() > 0 ? "_" + sb.toString() : "")
			+ (index > 0 ? "_" + index : "");
}
 
Example 10
Source File: PlayDataAccessor.java    From beatoraja with GNU General Public License v3.0 6 votes vote down vote up
private String getScoreHash(ScoreData score) {
	byte[] cipher_byte;
	try {
		MessageDigest md = MessageDigest.getInstance("SHA-256");
		md.update((hashkey + score.getSha256() + "," + score.getExscore() + "," + score.getEpg() + ","
				+ score.getLpg() + "," + score.getEgr() + "," + score.getLgr() + "," + score.getEgd() + ","
				+ score.getLgd() + "," + score.getEbd() + "," + score.getLbd() + "," + score.getEpr() + ","
				+ score.getLpr() + "," + score.getEms() + "," + score.getLms() + "," + score.getClear() + ","
				+ score.getMinbp() + "," + score.getCombo() + "," + score.getMode() + "," + score.getClearcount()
				+ "," + score.getPlaycount() + "," + score.getOption() + "," + score.getRandom() + ","
				+ score.getTrophy() + "," + score.getDate()).getBytes());
		cipher_byte = md.digest();
		StringBuilder sb = new StringBuilder(2 * cipher_byte.length);
		for (byte b : cipher_byte) {
			sb.append(String.format("%02x", b & 0xff));
		}
		return "035" + sb.toString();
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 11
Source File: ExportData.java    From talos with Apache License 2.0 6 votes vote down vote up
@Override
public String toString () {
    StringBuilder stringBuilder = new StringBuilder();

    stringBuilder.append(name);
    stringBuilder.append("\n");

    for (AbstractModule module : modules) {
        stringBuilder.append("\t");
        stringBuilder.append("ModuleID: ");
        stringBuilder.append(module.getIndex());
        stringBuilder.append("\n");
    }

    stringBuilder.append("\n");
    for (ConnectionData connection : connections) {
        stringBuilder.append("\t");
        stringBuilder.append("Connection: ");
        stringBuilder.append(connection);
        stringBuilder.append("\n");
    }

    return stringBuilder.toString();
}
 
Example 12
Source File: ObjectValueLabel.java    From GdxDemo3D with Apache License 2.0 5 votes vote down vote up
@Override
public void act (float delta) {
	T newValue = getValue();
	if (!oldValue.equals(newValue)) {
		copyValue(newValue, oldValue);
		StringBuilder sb = getText();
		sb.setLength(appendIndex);
		sb.append(oldValue);
		invalidateHierarchy();
	}
	super.act(delta);
}
 
Example 13
Source File: JsonFloatSerializer.java    From libgdx-snippets with MIT License 5 votes vote down vote up
public static String encodeFloatBits(float value) {

		StringBuilder builder = stringBuilder.get();

		builder.setLength(0);
		builder.append("0x");
		builder.append(String.format("%08X", Float.floatToRawIntBits(value)));
		builder.append("|");
		builder.append(value);

		return builder.toString();
	}
 
Example 14
Source File: JsonFloatSerializer.java    From libgdx-snippets with MIT License 5 votes vote down vote up
public static String encodeDoubleBits(double value) {

		StringBuilder builder = stringBuilder.get();

		builder.setLength(0);
		builder.append("0x");
		builder.append(String.format("%016X", Double.doubleToRawLongBits(value)));
		builder.append("|");
		builder.append(value);

		return builder.toString();
	}
 
Example 15
Source File: FloatValueLabel.java    From GdxDemo3D with Apache License 2.0 5 votes vote down vote up
@Override
public void act (float delta) {
	float newValue = getValue();
	if (oldValue != newValue) {
		oldValue = newValue;
		StringBuilder sb = getText();
		sb.setLength(appendIndex);
		sb.append(oldValue);
		invalidateHierarchy();
	}
	super.act(delta);
}
 
Example 16
Source File: IntValueLabel.java    From GdxDemo3D with Apache License 2.0 5 votes vote down vote up
@Override
public void act (float delta) {
	int newValue = getValue();
	if (oldValue != newValue) {
		oldValue = newValue;
		StringBuilder sb = getText();
		sb.setLength(appendIndex);
		sb.append(oldValue);
		invalidateHierarchy();
	}
	super.act(delta);
}
 
Example 17
Source File: Spinor.java    From box2dlights with Apache License 2.0 5 votes vote down vote up
@Override public String toString() {
  StringBuilder result = new StringBuilder();
  float radians = angle();
  result.append("radians: ");
  result.append(radians);
  result.append(", degrees: ");
  result.append(radians * MathUtils.radiansToDegrees);
  return result.toString();
}
 
Example 18
Source File: IntValueLabel.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
@Override
public void act (float delta) {
	int newValue = getValue();
	if (oldValue != newValue) {
		oldValue = newValue;
		StringBuilder sb = getText();
		sb.setLength(appendIndex);
		sb.append(oldValue);
		invalidateHierarchy();
	}
	super.act(delta);
}
 
Example 19
Source File: FloatValueLabel.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
@Override
public void act (float delta) {
	float newValue = getValue();
	if (oldValue != newValue) {
		oldValue = newValue;
		StringBuilder sb = getText();
		sb.setLength(appendIndex);
		sb.append(oldValue);
		invalidateHierarchy();
	}
	super.act(delta);
}
 
Example 20
Source File: BehaviorTreeViewer.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
private static StringBuilder appendTaskAttributes (StringBuilder attrs, Task<?> task) {
	Class<?> aClass = task.getClass();
	Field[] fields = ClassReflection.getFields(aClass);
	for (Field f : fields) {
		Annotation a = f.getDeclaredAnnotation(TaskAttribute.class);
		if (a == null) continue;
		TaskAttribute annotation = a.getAnnotation(TaskAttribute.class);
		attrs.append('\n');
		appendFieldString(attrs, task, annotation, f);
	}
	return attrs;
}