return ("\n" + indentPatter.matcher(fragment).replaceAll(spaces));
}
public String fillTemplate(Config config) throws IOException {
String template = Resources.toString(Client.class.getClassLoader().getResource("config.tpl"), Charsets.UTF_8);
Engine engine = new Engine();
Map<String, Object> model = new HashMap<>();
model.put("update", config.getUpdate());
model.put("port", config.getPort());
model.put("locale", config.getLocale());
model.put("score_display_duration", config.getScore_display_duration());
model.put("ai_place_tile_delay", config.getAi_place_tile_delay());
model.put("beep_alert", config.getBeep_alert());
model.put("client_name", config.getClient_name());
if (config.getConfirm() != null) {
model.put("confirm", indent(1, yaml.dumpAs(config.getConfirm(), Tag.MAP, FlowStyle.BLOCK)));
}
PlayersConfig pc = config.getPlayers();
if (pc != null) {
if (pc.getColors() != null && !pc.getColors().isEmpty()) {
StringBuilder colors = new StringBuilder();
for (ColorConfig cfg : pc.getColors()) {
colors.append("\n - ");
colors.append(yaml.dumpAs(cfg, Tag.MAP, FlowStyle.FLOW).trim());
}
model.put("colors", colors.toString());
}
if (pc.getNames() != null && !pc.getNames().isEmpty()) {
model.put("player_names", yaml.dumpAs(pc.getNames(), Tag.SEQ, FlowStyle.FLOW).trim());
}
if (pc.getAi_names() != null && !pc.getAi_names().isEmpty()) {
model.put("ai_names", yaml.dumpAs(pc.getAi_names(), Tag.SEQ, FlowStyle.FLOW).trim());
}
}
if (config.getPlugins() != null && !config.getPlugins().isEmpty()) {
model.put("plugins", indent(1, yaml.dumpAs(config.getPlugins(), Tag.SEQ, FlowStyle.BLOCK)));
}
if (config.getPresets() != null && !config.getPresets().isEmpty()) {
model.put("presets", indent(1, yaml.dumpAs(config.getPresets(), Tag.MAP, FlowStyle.BLOCK)));
}
if (config.getConnection_history() != null && !config.getConnection_history().isEmpty()) {
model.put("connection_history", yaml.dumpAs(config.getConnection_history(), Tag.SEQ, FlowStyle.FLOW).trim());
}
DebugConfig dc = config.getDebug();
model.put("hasDebug", dc != null);
if (dc != null) {
model.put("save_format", dc.getSave_format());
model.put("autosave", dc.getAutosave());
if (dc.getAutostart() != null) {
model.put("autostart", indent(2, yaml.dumpAs(dc.getAutostart(), Tag.MAP, FlowStyle.BLOCK)));
}
if (dc.getTile_definitions() != null) {
model.put("tile_definitions", indent(2, yaml.dumpAs(dc.getTile_definitions(), Tag.MAP, FlowStyle.BLOCK)));
}
if (dc.getDraw() != null) {
model.put("draw", indent(1, yaml.dumpAs(dc.getDraw(), Tag.SEQ, FlowStyle.BLOCK)));
}
if (dc.getOff_capabilities() != null) {
model.put("off_capabilities", indent(2, yaml.dumpAs(dc.getOff_capabilities(), Tag.SEQ, FlowStyle.BLOCK)));
}
model.put("area_highlight", dc.getArea_highlight());
}
String result = engine.transform(template, model);
result = result.replace(" !!"+PresetConfig.class.getName(), "");
result = result.replace("\n", System.lineSeparator());
return result;
}