Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyGalbreath committed Apr 27, 2024
1 parent 30c9479 commit 0f5a3f7
Show file tree
Hide file tree
Showing 52 changed files with 978 additions and 656 deletions.
16 changes: 16 additions & 0 deletions Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"profiles": {
"Client": {
"commandName": "Executable",
"executablePath": "dotnet",
"commandLineArgs": "\"$(VINTAGE_STORY)/Vintagestory.dll\" --dataPath \"$(VINTAGE_STORY_DATA)\" --addModPath \"$(ProjectDir)/bin/mods\" \"$(VINTAGE_STORY_DATA)/Mods\"",
"workingDirectory": "$(VINTAGE_STORY)"
},
"Server": {
"commandName": "Executable",
"executablePath": "dotnet",
"commandLineArgs": "\"$(VINTAGE_STORY)/VintagestoryServer.dll\" --dataPath \"$(VINTAGE_STORY_DATA)\" --addModPath \"$(ProjectDir)/bin/mods\" \"$(VINTAGE_STORY_DATA)/Mods\"",
"workingDirectory": "$(VINTAGE_STORY)"
}
}
}
10 changes: 9 additions & 1 deletion livemap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<DebugSymbols>true</DebugSymbols>
<ExcludeGeneratedDebugSymbol>false</ExcludeGeneratedDebugSymbol>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<OutputPath>bin\mods\mod</OutputPath>
</PropertyGroup>

<ItemGroup>
Expand All @@ -45,13 +46,19 @@
<Reference Include="Newtonsoft.Json" HintPath="$(VINTAGE_STORY)/Lib/Newtonsoft.Json.dll" Private="false" />
<Reference Include="protobuf-net" HintPath="$(VINTAGE_STORY)/Lib/protobuf-net.dll" Private="false" />
<Reference Include="SkiaSharp" HintPath="$(VINTAGE_STORY)/Lib/SkiaSharp.dll" Private="false" />
<Reference Include="ConfigLib" HintPath="../libs/configlib-1.3.9.dll" Private="false" />
<PackageReference Include="VSImGui" Version="0.0.6" IncludeAssets="compile" PrivateAssets="all" />
<PackageReference Include="ImGui.NET" Version="1.89.9.2" IncludeAssets="compile" PrivateAssets="all" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" IncludeAssets="compile" PrivateAssets="all" />
<PackageReference Include="NuGet.Build.Tasks.Pack" Version="6.7.0" IncludeAssets="compile" PrivateAssets="all" />
<PackageReference Include="MimeTypeMapOfficial" Version="1.0.17" IncludeAssets="compile;runtime" PrivateAssets="all" />
<PackageReference Include="YamlDotNet" Version="13.7.1" IncludeAssets="compile;runtime" PrivateAssets="all" />
<None Include="LICENSE;README.md;resources/**" CopyToOutputDirectory="PreserveNewest" Pack="true" PackagePath="" Link="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<Target Name="_ResolveCopyLocalNuGetPkgXmls" AfterTargets="ResolveReferences">
<ReferenceCopyLocalPaths Include="@(ReferenceCopyLocalPaths->'%(RootDir)%(Directory)%(Filename).xml')" Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)'!='' and Exists('%(RootDir)%(Directory)%(Filename).xml')" />
</Target>

<Target Name="InstallAndRunNpm" AfterTargets="PostBuildEvent">
<Exec Command="npm install" WorkingDirectory="web" />
<Exec Command="npm run build" WorkingDirectory="web" />
Expand All @@ -76,6 +83,7 @@
</Target>

<Target Name="PackZip" AfterTargets="FilterModInfo">
<MakeDir Directories="bin\mods\mod" />
<ZipDirectory DestinationFile="bin/livemap-$(Version).zip" SourceDirectory="$(TargetDir)" Overwrite="true" />
</Target>

Expand Down
38 changes: 29 additions & 9 deletions resources/assets/livemap/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,33 @@

"command.reload.finished": "LiveMap config and services were successfully reloaded.",

"logger.info.server-loaded-colormap": "&dColormap loaded from disk.",
"logger.info.server-received-colormap": "&dColormap packet was received from &n{0}",

"logger.info.webserver-started": "&aInternal webserver starting on port &e{0}",
"logger.info.webserver-stopped": "&cInternal webserver has stopped",
"logger.error.webserver-start-failed": "&cInternal webserver has failed to start",

"logger.warning.packet-from-non-admin": "Ignoring colormap packet from non-privileged user {0}",
"logger.warning.received-null-colormap": "Received null colormap from {0}"
"livemap:no-data-to-display": "\nNo data to display.\n\nIs the mod disabled?",
"livemap:access-denied": "Sorry. Access Denied.",

"livemap:stop": "Stop",
"livemap:start": "Start",
"livemap:cancel": "Cancel",
"livemap:close": "Close",

"livemap:colormap-settings": "Colormap Settings",
"livemap:colormap-settings.hint": "Settings about block colors that the\nclient knows but the server doesn't.",
"livemap:colormap-generate": "Generate",
"livemap:colormap-generate.text": "Generate a new Colormap",
"livemap:colormap-generate.hint": "Generates a new Colormap of all the\nblocks in the game (including modded\nones) and then sends it to the server.\n\nUse this first if this is a fresh install\nor when you change your mod list.",

"livemap:httpd-settings": "Web Server Settings",
"livemap:httpd-settings.hint": "Settings regarding the built-in httpd web server.\nThis is just a basic httpd web server, if you need/want\nsomething better just disable this and run your own.",
"livemap:httpd-enabled": "Enabled",
"livemap:httpd-enabled.hint": "Enable the built-in http web server.\nDisable this if you want to manually use a\nstandalone web server such as apache or nginx.",
"livemap:httpd-port": "Port",
"livemap:httpd-port.hint": "The port the built-in web server listens to. Make\nsure the port is allocated if using a game web panel.",

"livemap:zoom-settings": "Zoom Settings",
"livemap:zoom-settings.hint": "Settings regarding the zoom aspect of the map.\nThe more zoom levels you have the more tile sets to\ncreate which uses more drive space. So be cautious.",
"livemap:zoom.max-in": "Max In",
"livemap:zoom.max-in.hint": "Extra zoom in layers will stretch the original\ntile images so you can zoom in further without\nthe extra cost of rendering more tiles.",
"livemap:zoom.max-out": "Max Out",
"livemap:zoom.max-out.hint": "The maximum zoom out you can do on the map.\nEach additional level requires a new set of tiles\nto be rendered, so don't go too wild here.",
"livemap:zoom.default": "Default",
"livemap:zoom.default.hint": "The default zoom when loading the map in browser.\nNormal sized tiles (1 pixel = 1 block) are always\nat zoom level 0, making it a good default value."
}
37 changes: 29 additions & 8 deletions src/client/LiveMapClient.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,52 @@
using livemap.client.command;
using System.Reflection;
using HarmonyLib;
using livemap.client.gui;
using livemap.client.network;
using livemap.client.patches;
using livemap.client.util;
using livemap.common;
using livemap.common.configuration;
using livemap.common.network;
using livemap.common.util;
using Vintagestory.API.Client;
using Vintagestory.Common;

namespace livemap.client;

public sealed class LiveMapClient : LiveMapCore {
public override ICoreClientAPI Api { get; }

private readonly ClientHarmonyPatches _patches;
private readonly Harmony _harmony;
private readonly ConfigGui? _gui;

protected override ClientCommandHandler CommandHandler { get; }
public override ClientNetworkHandler NetworkHandler { get; }

public Config? Config { get; private set; }

public LiveMapClient(ICoreClientAPI api) : base(api, new ClientLoggerImpl()) {
Api = api;

_patches = new ClientHarmonyPatches();
_patches.Init();
_harmony = new Harmony(LiveMapMod.Id);
_harmony.Patch(typeof(GameCalendar).GetProperty("YearRel", BindingFlags.Instance | BindingFlags.Public)!.GetGetMethod(),
prefix: typeof(ColormapGenerator).GetMethod("PreYearRel"));

if (Api.ModLoader.IsModEnabled("configlib")) {
Logger.Info("Found ConfigLib. Registering gui for settings.");
_gui = new ConfigGui(this);
}

CommandHandler = new ClientCommandHandler(this);
NetworkHandler = new ClientNetworkHandler(this);
}

public void ReceiveConfig(ConfigPacket packet) {
Logger.Debug("Received config packet from server");
Config = packet.Config!;

Logger.Debug($"TileType: {Config.Web.TileType}");
}

public override void Dispose() {
_patches.Dispose();
_harmony.UnpatchAll(LiveMapMod.Id);

_gui?.Dispose();
}
}
13 changes: 0 additions & 13 deletions src/client/command/ClientCommand.cs

This file was deleted.

15 changes: 0 additions & 15 deletions src/client/command/ClientCommandHandler.cs

This file was deleted.

58 changes: 0 additions & 58 deletions src/client/command/ColorMapCommand.cs

This file was deleted.

93 changes: 93 additions & 0 deletions src/client/gui/ConfigGui.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using ConfigLib;
using livemap.client.gui.settings;
using livemap.common.network;
using livemap.common.util;
using Vintagestory.API.Server;

namespace livemap.client.gui;

public class ConfigGui : Gui {
private readonly LiveMapClient _client;

private readonly List<Gui> _guis = new();

private bool _alreadyRequestedConfig;

public ConfigGui(LiveMapClient client) {
_client = client;

ConfigLibModSystem? configlib = _client.Api.ModLoader.GetModSystem<ConfigLibModSystem>();
configlib.ConfigWindowClosed += OnClose;
configlib.RegisterCustomConfig(LiveMapMod.Id, (_, controlButtons) => {
try {
return Draw(controlButtons);
} catch (Exception e) {
Logger.Error(e.ToString());
return new ControlButtons(false);
}
});

_guis.Add(new ColormapSettings(client));
_guis.Add(new HttpdSettings(client));
_guis.Add(new ZoomSettings(client));
}

private ControlButtons Draw(ControlButtons controlButtons) {
if (!_client.Api.World.Player.HasPrivilege(Privilege.root)) {
Text($"\n{Lang.Get("access-denied.")}", true, 0xFFFF4040);
return new ControlButtons(false);
}

if (_client.Config == null) {
Text($"{Lang.Get("no-data-to-display")}", true, 0xFFFF4040);
// ReSharper disable once InvertIf
if (!_alreadyRequestedConfig) {
_client.NetworkHandler.SendPacket(new ConfigPacket());
_alreadyRequestedConfig = true;
}
return new ControlButtons(false);
}

if (controlButtons.Save) {
// saves changes to config
// todo send values back to server
Console.WriteLine("SAVE");
}

if (controlButtons.Restore) {
// retrieves values from config
// todo request new values from server
Console.WriteLine("RESTORE");
}

if (controlButtons.Reload) {
// applies settings changes
// todo not needed
Console.WriteLine("RELOAD");
}

if (controlButtons.Defaults) {
// sets settings to default values
// todo do we want original defaults or current defaults?
Console.WriteLine("DEFAULTS");
}

Draw();

return new ControlButtons(true) { Reload = false };
}

public override void Draw() {
_guis.ForEach(gui => gui.Draw());
}

public override void OnClose() {
_guis.ForEach(gui => gui.OnClose());
}

public void Dispose() {
_guis.Clear();
}
}
Loading

0 comments on commit 0f5a3f7

Please sign in to comment.