Skip to content

Commit

Permalink
Send world name to client. Show in title.
Browse files Browse the repository at this point in the history
  • Loading branch information
kylepaulsen committed Apr 17, 2021
1 parent 45abc5c commit 310aef9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
19 changes: 19 additions & 0 deletions WebMap/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ static class WebMapConfig {
public static double PLAYER_UPDATE_INTERVAL = 0.5;
public static bool CACHE_SERVER_FILES = false;

public static string WORLD_NAME = "";

public static TValue GetValueOrDefault<TKey, TValue>(
this IDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue) {

Expand Down Expand Up @@ -97,11 +99,28 @@ public static void readConfigFile(string configFile) {
}
}

public static string getWorldName() {
if (WORLD_NAME != "") {
return WORLD_NAME;
}
string[] arguments = Environment.GetCommandLineArgs();
var worldName = "";
for (var t = 0; t < arguments.Length; t++) {
if (arguments[t] == "-world") {
worldName = arguments[t + 1];
break;
}
}
WORLD_NAME = worldName;
return worldName;
}

public static string makeClientConfigJSON() {
var sb = new StringBuilder();
sb.Length = 0;

sb.Append("{");
sb.Append($"\"world_name\":\"{getWorldName()}\",");
sb.Append($"\"texture_size\":{TEXTURE_SIZE},");
sb.Append($"\"pixel_size\":{PIXEL_SIZE},");
sb.Append($"\"update_interval\":{PLAYER_UPDATE_INTERVAL},");
Expand Down
11 changes: 1 addition & 10 deletions WebMap/WebMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,9 @@ public void Awake() {
var pluginPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
WebMapConfig.readConfigFile(Path.Combine(pluginPath, "config.json"));

string[] arguments = Environment.GetCommandLineArgs();
var worldName = "";
for (var t = 0; t < arguments.Length; t++) {
if (arguments[t] == "-world") {
worldName = arguments[t + 1];
break;
}
}

var mapDataPath = Path.Combine(pluginPath, "map_data");
Directory.CreateDirectory(mapDataPath);
worldDataPath = Path.Combine(mapDataPath, worldName);
worldDataPath = Path.Combine(mapDataPath, WebMapConfig.getWorldName());
Directory.CreateDirectory(worldDataPath);

mapDataServer = new MapDataServer();
Expand Down
2 changes: 2 additions & 0 deletions WebMap/web-src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const fetchConfig = fetch('/config').then(res => res.json()).then(config => {
constants.PIXEL_SIZE = config.pixel_size || 12;
constants.EXPLORE_RADIUS = config.explore_radius || 100;
constants.UPDATE_INTERVAL = config.update_interval || 0.5;
constants.WORLD_NAME = config.world_name;
document.title = `Valheim WebMap - ${constants.WORLD_NAME}`;
createStyleSheet(`.mapIcon.player {
transition: top ${constants.UPDATE_INTERVAL}s linear, left ${constants.UPDATE_INTERVAL}s linear;
}`);
Expand Down

0 comments on commit 310aef9

Please sign in to comment.