Skip to content

Commit

Permalink
etc
Browse files Browse the repository at this point in the history
  • Loading branch information
aedenthorn committed Mar 26, 2021
1 parent 04c0c56 commit d0a2345
Show file tree
Hide file tree
Showing 23 changed files with 2,462 additions and 15 deletions.
11 changes: 11 additions & 0 deletions AutoFuel/AedenthornUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,15 @@ public static bool CheckKeyDown(string value)
return false;
}
}
public static bool CheckKeyHeld(string value, bool req = true)
{
try
{
return Input.GetKey(value.ToLower());
}
catch
{
return !req;
}
}
}
11 changes: 11 additions & 0 deletions AutoStore/AedenthornUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,15 @@ public static bool CheckKeyDown(string value)
return false;
}
}
public static bool CheckKeyHeld(string value, bool req = true)
{
try
{
return Input.GetKey(value.ToLower());
}
catch
{
return !req;
}
}
}
11 changes: 11 additions & 0 deletions BuildingDemolish/AedenthornUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,15 @@ public static bool CheckKeyDown(string value)
return false;
}
}
public static bool CheckKeyHeld(string value, bool req = true)
{
try
{
return Input.GetKey(value.ToLower());
}
catch
{
return !req;
}
}
}
11 changes: 11 additions & 0 deletions ClockMod/AedenthornUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,15 @@ public static bool CheckKeyDown(string value)
return false;
}
}
public static bool CheckKeyHeld(string value, bool req = true)
{
try
{
return Input.GetKey(value.ToLower());
}
catch
{
return !req;
}
}
}
76 changes: 76 additions & 0 deletions ConfigurationManager/ConfigSettingEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Based on code made by MarC0 / ManlyMarco
// Copyright 2018 GNU General Public License v3.0

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using BepInEx;
using BepInEx.Configuration;

namespace ConfigurationManager
{
internal sealed class ConfigSettingEntry : SettingEntryBase
{
public ConfigEntryBase Entry { get; }

public ConfigSettingEntry(ConfigEntryBase entry, BaseUnityPlugin owner)
{
Entry = entry;

DispName = entry.Definition.Key;
Category = entry.Definition.Section;
Description = entry.Description?.Description;

var converter = TomlTypeConverter.GetConverter(entry.SettingType);
if (converter != null)
{
ObjToStr = o => converter.ConvertToString(o, entry.SettingType);
StrToObj = s => converter.ConvertToObject(s, entry.SettingType);
}

var values = entry.Description?.AcceptableValues;
if (values != null)
GetAcceptableValues(values);

DefaultValue = entry.DefaultValue;

SetFromAttributes(entry.Description?.Tags, owner);
}

private void GetAcceptableValues(AcceptableValueBase values)
{
var t = values.GetType();
var listProp = t.GetProperty(nameof(AcceptableValueList<bool>.AcceptableValues), BindingFlags.Instance | BindingFlags.Public);
if (listProp != null)
{
AcceptableValues = ((IEnumerable)listProp.GetValue(values, null)).Cast<object>().ToArray();
}
else
{
var minProp = t.GetProperty(nameof(AcceptableValueRange<bool>.MinValue), BindingFlags.Instance | BindingFlags.Public);
if (minProp != null)
{
var maxProp = t.GetProperty(nameof(AcceptableValueRange<bool>.MaxValue), BindingFlags.Instance | BindingFlags.Public);
if (maxProp == null) throw new ArgumentNullException(nameof(maxProp));
AcceptableValueRange = new KeyValuePair<object, object>(minProp.GetValue(values, null), maxProp.GetValue(values, null));
ShowRangeAsPercent = (AcceptableValueRange.Key.Equals(0) || AcceptableValueRange.Key.Equals(1)) && AcceptableValueRange.Value.Equals(100) ||
AcceptableValueRange.Key.Equals(0f) && AcceptableValueRange.Value.Equals(1f);
}
}
}

public override Type SettingType => Entry.SettingType;

public override object Get()
{
return Entry.BoxedValue;
}

protected override void SetValue(object newVal)
{
Entry.BoxedValue = newVal;
}
}
}
Loading

0 comments on commit d0a2345

Please sign in to comment.