Skip to content

Commit

Permalink
Added hotkeys for commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Mydayyy committed May 13, 2021
1 parent cadb095 commit d38128f
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 2 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ Currently there are three available chat commands:
- **/convertpins ignorelocaldupes**: Uploads all pins which are currently clientside to the server. Pins which have a pin on the server near them are **not** uploaded. Default radius 15.0, can be adjusted in the config.
- **/deletealllocalpins**: **DELETES** all local pins. Those will not be recoverable, use it when you are absolutely sure you want to do that.

#### **Hotkeys:**
You can enable hotkeys for the convertpins and 'convertpins ignorelocaldupes'.
To enable, adjust the Hotkeys section in the config accordingly. A list of
valid strings can be found here: [https://docs.unity3d.com/ScriptReference/KeyCode.html](https://docs.unity3d.com/ScriptReference/KeyCode.html).
Leave empty for no hotkey (default)
Example:
```
[Hotkeys]
## Hotkey to run /convertpins
# Setting type: String
# Default value:
KeyConvertAll = F10
## Hotkey to run /convertpins ignorelocaldupes
# Setting type: String
# Default value:
KeyConvertIgnoreDupes = F11
```

## Bug Reports
Please use [Github](https://github.com/Mydayyy/Valheim-ServerSideMap/issues) for bug reports and feedback.

Expand All @@ -59,6 +79,7 @@ You need to copy the following dlls into the Libs folder:
- UnityEngine.dll
- UnityEngine.ImageConversionModule.dll
- UnityEngine.UI.dll
- UnityEngine.InputLegacyModule.dll

## KoFi
My kofi can be found [here](https://ko-fi.com/mydayyy)
29 changes: 29 additions & 0 deletions ServerSideMap/Hotkeys.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using HarmonyLib;
using UnityEngine;

namespace ServerSideMap
{
public static class Hotkeys
{
[HarmonyPatch(typeof (Player), "Update")]
private class PlayerInputPatch
{
// ReSharper disable once InconsistentNaming
private static void Postfix(Player __instance)
{
if (Store.HasKeyConvertAll() && Input.GetKeyDown(Store.GetKeyConvertAll()))
{
Utility.Log("Hotkey: GetKeyConvertAll");
UtilityPin.UploadAllPins(false);
}

if (Store.HasKeyConvertIgnoreDupes() && Input.GetKeyDown(Store.GetKeyConvertIgnoreDupes()))
{
Utility.Log("Hotkey: GetKeyConvertIgnoreDupes");
UtilityPin.UploadAllPins(true);
}
}
}
}
}
9 changes: 8 additions & 1 deletion ServerSideMap/ServerSideMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace ServerSideMap
{
[BepInPlugin("eu.mydayyy.plugins.serversidemap", "ServerSideMap", "1.3.2.0")]
[BepInPlugin("eu.mydayyy.plugins.serversidemap", "ServerSideMap", "1.3.3.0")]
public class ServerSideMap : BaseUnityPlugin
{
void Awake()
Expand All @@ -19,6 +19,13 @@ void Awake()
Store.EnableMapShare = Config.Bind("General", "EnableMapShare", true, "Client: Whether or not to participate in sharing the map. Server: Whether or not to allow map sharing");
Store.EnablePinShare = Config.Bind("General", "EnableMarkerShare", false, "Client: Whether or not to participate in sharing markers. Server: Whether or not to allow marker sharing");
Store.DuplicatePinRadius = Config.Bind("PinShare", "DuplicatePinRadius", 15.0f, "A local pin will not be uploaded if a pin exists in the given radius on the server (when using /convertpins ignorelocaldupes)");
Store.sKeyConvertAll = Config.Bind("Hotkeys", "KeyConvertAll", "", "Hotkey to run /convertpins");
Store.sKeyConvertIgnoreDupes = Config.Bind("Hotkeys", "KeyConvertIgnoreDupes", "", "Hotkey to run /convertpins ignorelocaldupes");

Store.InitHotkeys();
Utility.Log("Store1: " + Store.HasKeyConvertAll());
Utility.Log("Store2: " + Store.HasKeyConvertIgnoreDupes());

}

[HarmonyPatch(typeof (ZNet), "OnNewConnection")]
Expand Down
4 changes: 4 additions & 0 deletions ServerSideMap/ServerSideMap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,16 @@
<Reference Include="UnityEngine.ImageConversionModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\Libs\UnityEngine.ImageConversionModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.InputLegacyModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\Libs\UnityEngine.InputLegacyModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\Libs\UnityEngine.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CommandsPinUpsync.cs" />
<Compile Include="Hotkeys.cs" />
<Compile Include="Store.cs" />
<Compile Include="ExplorationDatabase.cs" />
<Compile Include="ExplorationMapSync.cs" />
Expand Down
2 changes: 2 additions & 0 deletions ServerSideMap/ServerSideMap.csproj.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp70</s:String></wpf:ResourceDictionary>
35 changes: 34 additions & 1 deletion ServerSideMap/Store.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using BepInEx.Configuration;
using UnityEngine;

namespace ServerSideMap
{
Expand All @@ -7,7 +9,15 @@ public static class Store
public static ConfigEntry<bool> EnableMapShare;
public static ConfigEntry<bool> EnablePinShare;
public static ConfigEntry<float> DuplicatePinRadius;


public static ConfigEntry<String> sKeyConvertAll;
private static bool hasKeyConvertAll;
private static KeyCode KeyConvertAll;

public static ConfigEntry<String> sKeyConvertIgnoreDupes;
private static bool hasKeyConvertIgnoreDupes;
private static KeyCode KeyConvertIgnoreDupes;

public static bool ServerPinShare = false;

public static bool IsSharingMap()
Expand All @@ -24,5 +34,28 @@ public static float GetDuplicatePinRadius()
{
return DuplicatePinRadius.Value;
}

public static void InitHotkeys()
{
hasKeyConvertAll = Enum.TryParse(sKeyConvertAll.Value, out KeyConvertAll);
hasKeyConvertIgnoreDupes = Enum.TryParse(sKeyConvertIgnoreDupes.Value, out KeyConvertIgnoreDupes);
}
public static bool HasKeyConvertAll()
{
return hasKeyConvertAll;
}
public static KeyCode GetKeyConvertAll()
{
return KeyConvertAll;
}

public static bool HasKeyConvertIgnoreDupes()
{
return hasKeyConvertIgnoreDupes;
}
public static KeyCode GetKeyConvertIgnoreDupes()
{
return KeyConvertIgnoreDupes;
}
}
}

0 comments on commit d38128f

Please sign in to comment.