fix #40 allow supplying an external colors file with "colors.file" config
parent
43759f2d21
commit
b5e378f406
|
@ -99,6 +99,10 @@ Enable parsing of POI blocks, provided with the mod in this repository
|
|||
Enable parsing of Travelnet boxes
|
||||
* Default: **true**
|
||||
|
||||
### colors.file
|
||||
Supply an external colors file supplementary to the builtin tables
|
||||
Should be a valid filename or empty (no external colors)
|
||||
* Default: **none***
|
||||
|
||||
# How it works
|
||||
|
||||
|
|
|
@ -13,6 +13,12 @@ public interface TileServerConfig extends Config {
|
|||
@DefaultValue("8080")
|
||||
int httPort();
|
||||
|
||||
/*
|
||||
colors from external source
|
||||
*/
|
||||
@Key("colors.file")
|
||||
String externalColorsFile();
|
||||
|
||||
/*
|
||||
Tile renderer stuff
|
||||
*/
|
||||
|
|
|
@ -1,19 +1,49 @@
|
|||
package io.rudin.minetest.tileserver.provider;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import io.rudin.minetest.tileserver.ColorTable;
|
||||
import io.rudin.minetest.tileserver.config.TileServerConfig;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
@Singleton
|
||||
public class ColorTableProvider implements Provider<ColorTable> {
|
||||
|
||||
@Inject
|
||||
public ColorTableProvider(TileServerConfig cfg){
|
||||
this.cfg = cfg;
|
||||
}
|
||||
|
||||
private final TileServerConfig cfg;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ColorTableProvider.class);
|
||||
|
||||
@Override
|
||||
@Singleton
|
||||
public ColorTable get() {
|
||||
ColorTable colorTable = new ColorTable();
|
||||
colorTable.load(ColorTableProvider.class.getResourceAsStream("/colors.txt"));
|
||||
colorTable.load(ColorTableProvider.class.getResourceAsStream("/vanessa.txt"));
|
||||
|
||||
String externalColorsFile = cfg.externalColorsFile();
|
||||
if (externalColorsFile != null){
|
||||
logger.info("Loading colors from external file: '{}'", externalColorsFile);
|
||||
try (InputStream input = new FileInputStream(externalColorsFile)){
|
||||
colorTable.load(input);
|
||||
|
||||
} catch (Exception e){
|
||||
logger.warn("external colors", e);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return colorTable;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue