-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstantMap.cs
More file actions
112 lines (97 loc) · 3.1 KB
/
InstantMap.cs
File metadata and controls
112 lines (97 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using UnityEngine;
// ReSharper disable once CheckNamespace
[UsedImplicitly]
public class InstantMap : Mod
{
private const string ModName = "InstantMap";
private const string CommandName = "instantmap";
private const string CommandDocumentation = "Unlocks the map.";
private const string CommandParameterSimple = "simple";
private const string CommandParameterFull = "full";
[UsedImplicitly]
public void Start()
{
Debug.Log(string.Format("Mod {0} has been loaded!", ModName));
}
[UsedImplicitly]
[ConsoleCommand(CommandName, CommandDocumentation)]
public static void Command(string[] args)
{
if (!ValidateArguments(args))
{
Debug.Log("Please use either \n" +
"- \"instantmap simple\" - Unlock the map only\n" +
"- \"instantmap full\" - Unlock the map including all places of interest");
return;
}
var argument = args[0].ToLower();
switch (argument)
{
case CommandParameterSimple:
{
ActivateMap();
break;
}
case CommandParameterFull:
{
ActivateMap();
UnlockPois();
break;
}
default:
{
throw new ArgumentOutOfRangeException("args");
}
}
}
private static bool ValidateArguments(IReadOnlyList<string> args)
{
return args != null &&
args.Count > 0 &&
(CommandParameterSimple.Equals(args[0], StringComparison.OrdinalIgnoreCase) ||
CommandParameterFull.Equals(args[0], StringComparison.OrdinalIgnoreCase));
}
private static void ActivateMap()
{
var mapTab = MapTab.Get();
if (mapTab == null || mapTab.m_MapDatas.Count == 0)
{
Debug.Log(string.Format("{0}: Map could not be unlocked.", ModName));
return;
}
foreach (var map in mapTab.m_MapDatas)
{
if (map.Value.m_Unlocked)
{
continue;
}
mapTab.UnlockPage(map.Key);
}
Debug.Log(string.Format("{0}: Map unlocked.", ModName));
}
private static void UnlockPois()
{
var mapTab = MapTab.Get();
if (mapTab == null)
{
Debug.Log(string.Format("{0}: Places of interest could not be unlocked.", ModName));
return;
}
foreach (var map in mapTab.m_MapDatas)
{
foreach (var mapElement in map.Value.m_Elemets)
{
mapTab.UnlockElement(mapElement.name);
}
}
Debug.Log(string.Format("{0}: Places of interest unlocked.", ModName));
}
[UsedImplicitly]
public void OnModUnload()
{
Debug.Log(string.Format("Mod {0} has been unloaded!", ModName));
}
}