Skip to content

Commit

Permalink
"keeping up" the "appearance" of "work"
Browse files Browse the repository at this point in the history
  • Loading branch information
Govorunb committed Dec 2, 2023
1 parent 726b151 commit 3687576
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 84 deletions.
4 changes: 2 additions & 2 deletions SCHIZO/Creatures/Ermfish/ErmStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ ErmStack FindNearest_TechType()
{
return PhysicsHelpers.ObjectsInRange(gameObject.transform.position, 20f)
.OfTechType(selfTechType)
.OrderByDistanceTo(gameObject.transform.position)
.SelectComponentInParent<ErmStack>()
.OrderByDistanceTo(gameObject.transform.position)
.FirstOrDefault(s => !s.nextSocket && s != this);
}
}
Expand Down Expand Up @@ -140,7 +140,7 @@ public static void Disconnect(ErmStack node, bool plugSide = true)
public bool Connect(ErmStack node, bool nodeIsPlug) => nodeIsPlug ? Connect(node, this) : Connect(this, node);
public void Disconnect(bool plugSide = true) => Disconnect(this, plugSide);

public bool ShouldAttach(Carryable plug, CarryCreature socket)
public bool ShouldAttach(Carryable _, CarryCreature socket)
{
ErmStack socketStack = socket.GetComponent<ErmStack>();
if (!socketStack) return true;
Expand Down
10 changes: 4 additions & 6 deletions SCHIZO/Events/Ermcon/Ermcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public partial class Ermcon
private void Start()
{
instance = this;
conMembers = new List<ErmconAttendee>();
targets = new HashSet<ErmconPanelist>();
conMembers = [];
targets = [];
// let's not wait the whole cooldown on load
_eventEndTime = -cooldown / 2;

Expand Down Expand Up @@ -123,7 +123,7 @@ public override void StartEvent()
return;
}
LOGGER.LogMessage($"The upcoming Ermcon will be visited by {totalAttendance} afficionados");
conMembers.AddRange(erms.Take(totalAttendance));
conMembers = erms.Take(totalAttendance).ToList();
conMembers.ForEach(erm => erm.enabled = true);

_eventEndTime = Time.time + maxDuration;
Expand All @@ -136,12 +136,10 @@ public override void EndEvent()
targets.Clear();
foreach (ErmconAttendee ermEnthusiast in conMembers)
{
if (!ermEnthusiast) continue;
ermEnthusiast.enabled = false;
if (ermEnthusiast) ermEnthusiast.enabled = false;
}
conMembers.Clear();


_eventEndTime = Time.time;
_isOccurring = false;
base.EndEvent();
Expand Down
8 changes: 4 additions & 4 deletions SCHIZO/Events/Ermcon/ErmconAttendee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public partial class ErmconAttendee : IHandTarget
new Keyframe(90f, 20f),
new Keyframe(120f, 1000f)
);
private List<(HandTarget target, bool wasEnabled)> _otherHandTargets;
private List<HandTarget> _disabledHandTargets;

/// <summary>
/// A value that increases the longer the creature is focused on one target.<br/>
Expand Down Expand Up @@ -68,8 +68,8 @@ public override void OnEnable()
LogSelf($"enabled\npatience: {patience}");
creature.actions.Clear();
creature.actions.Add(this);
_otherHandTargets = GetComponents<HandTarget>().Select(ht => (ht, ht.enabled)).ToList();
_otherHandTargets.ForEach(pair => pair.target.enabled = false);
_disabledHandTargets = GetComponents<HandTarget>().Where(ht => ht.enabled).ToList();
_disabledHandTargets.ForEach(ht => ht.enabled = false);
}

public void OnDisable()
Expand All @@ -79,7 +79,7 @@ public void OnDisable()
_visited.Clear();
creature.ScanCreatureActions();
creature.GetComponent<SwimBehaviour>().LookForward();
_otherHandTargets.ForEach(pair => pair.target.enabled = pair.wasEnabled);
_disabledHandTargets.ForEach(ht => ht.enabled = true);
}

public void OnTargetRemoved(GameObject removedBy)
Expand Down
2 changes: 1 addition & 1 deletion SCHIZO/Events/Ermcon/ErmconPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace SCHIZO.Events.Ermcon;
[HarmonyPatch]
public static class ErmconPatches
{
private static readonly MethodInfo GetComponentOfIHandTarget = AccessTools.Method(typeof(GameObject), nameof(GameObject.GetComponent), null, new[] { typeof(IHandTarget) });
private static readonly MethodInfo GetComponentOfIHandTarget = AccessTools.Method(typeof(GameObject), nameof(GameObject.GetComponent), null, [typeof(IHandTarget)]);

[HarmonyPatch(typeof(GUIHand), nameof(GUIHand.Send))]
[HarmonyTranspiler]
Expand Down
30 changes: 18 additions & 12 deletions SCHIZO/Events/GameEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
namespace SCHIZO.Events;
public partial class GameEvent : IStoryGoalListener
{
public record StoryGoals(GameEvent evt)
public readonly record struct StoryGoals(GameEvent evt)
{
public string Unlock => $"{evt.Name}.UnlockedAutoStart";
public string FirstTime => $"{evt.Name}.FirstTime";
public readonly string Unlock => $"{evt.EventName}.UnlockedAutoStart";
public readonly string FirstTime => $"{evt.EventName}.FirstTime";
}
public abstract bool IsOccurring { get; }
public bool IsFirstTime { get; private set; } = true;
Expand All @@ -16,28 +16,34 @@ public record StoryGoals(GameEvent evt)
protected string RequiredStoryGoal => RetargetHelpers.Pick(requiredStoryGoal_SN, requiredStoryGoal_BZ);
protected bool IsUnlocked { get; private set; }
public StoryGoals Goals { get; private set; }
public string Name => GetType().Name;
public string EventName => GetType().Name;

protected void Awake()
{
Goals = new StoryGoals(this);
player = Player.main;

StoryGoalManager.main.AddListener(this);
if (StoryGoalHelpers.IsCompleted(Goals.FirstTime)) IsFirstTime = false;
}

#region Unlock goals
// TODO: can/should this be improved?
public void NotifyGoalComplete(string goal)
{
if (string.Equals(goal, RequiredStoryGoal, System.StringComparison.OrdinalIgnoreCase))
Unlock();
}

public void NotifyGoalReset(string key) => Lock();
public void NotifyGoalReset(string goal)
{
if (string.Equals(goal, RequiredStoryGoal, System.StringComparison.OrdinalIgnoreCase))
Lock();
}

public void NotifyGoalsDeserialized() { }
public void NotifyGoalsDeserialized()
{
if (StoryGoalHelpers.IsCompleted(Goals.FirstTime)) IsFirstTime = false;
if (StoryGoalHelpers.IsCompleted(Goals.Unlock)) IsUnlocked = true;
}

public void Unlock()
{
Expand All @@ -59,19 +65,19 @@ private void OnDestroy()

public virtual void StartEvent()
{
string firstTimeMsg = "";
string msg = $"{EventName} started";
IsFirstTime = !StoryGoalHelpers.IsCompleted(Goals.FirstTime);
if (IsFirstTime)
{
StoryGoalHelpers.Trigger(Goals.FirstTime);
firstTimeMsg = " (first time)";
msg += " (first time)";
}
LOGGER.LogMessage($"{Name} started{firstTimeMsg}");
LOGGER.LogMessage(msg);
}

public virtual void EndEvent()
{
LOGGER.LogMessage($"{Name} ended");
LOGGER.LogMessage($"{EventName} ended");
}

/// <summary>
Expand Down
18 changes: 10 additions & 8 deletions SCHIZO/Events/GameEventsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,26 @@ private void Awake()
{
if (Instance) Destroy(Instance);
Instance = this;
}
private void Start()
{
gameObject.GetComponents(Events);
}

[ConsoleCommand("autoevents"), UsedImplicitly]
public static void OnConsoleCommand_autoevents(bool? action = null)
public static string OnConsoleCommand_autoevents(bool? arg = null)
{
if (action == null)
if (arg is not { } value)
{
MessageHelpers.WriteCommandOutput($"Events are currently {FormatAutoStart(AutoStart)}");
return;
return $"Events are currently {FormatAutoStart(AutoStart)}";
}

AutoStart = action.Value;
AutoStart = value;

MessageHelpers.WriteCommandOutput($"Events are now {FormatAutoStart(action.Value)}");
return MessageHelpers.GetCommandOutput($"Events are now {FormatAutoStart(arg.Value)}");
}

#if DEBUG
#if DEBUG_ERMCON
public void Update()
{
if (!Input.GetKeyDown(KeyCode.LeftControl)) return;
Expand All @@ -58,7 +60,7 @@ public void Update()
[ConsoleCommand("event"), UsedImplicitly]
public static string OnConsoleCommand_event(string eventName, bool start)
{
GameEvent @event = Events.FirstOrDefault(e => e.Name.Equals(eventName, System.StringComparison.OrdinalIgnoreCase));
GameEvent @event = Events.FirstOrDefault(e => e.EventName.Equals(eventName, System.StringComparison.OrdinalIgnoreCase));
if (!@event) return MessageHelpers.GetCommandOutput($"No event named '{eventName}'");

if (start) @event.StartEvent();
Expand Down
2 changes: 1 addition & 1 deletion SCHIZO/Helpers/StaticHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private static bool TryGetCached<T>(string name, out T value)
private static void Cache(string fieldOrPropertyColonName)
{
string[] splits = fieldOrPropertyColonName.Split(':');
Type type = AccessTools.TypeByName(splits[0]);
Type type = ReflectionCache.GetType(splits[0]);

FieldInfo f = type.GetField(splits[1], BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

Expand Down
4 changes: 2 additions & 2 deletions SCHIZO/HullPlates/HullPlatePrefab.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
using Nautilus.Assets;
using Nautilus.Assets.Gadgets;
Expand All @@ -24,7 +24,7 @@ public HullPlatePrefab(HullPlate hullPlate, HullPlateLoader loader) : base(hullP

if (!_hullPlate.deprecated)
{
Texture2D overrideIcon = hullPlate.overrideIcon ! ?? hullPlate.texture;
Texture2D overrideIcon = hullPlate.overrideIcon !?? hullPlate.texture;
overrideIcon = overrideIcon.Scale(177, 176).Translate(-21, -38).Crop(loader.hiddenIcon.width, loader.hiddenIcon.height);
Texture2D newIcon = hullPlate.hidden ? loader.hiddenIcon : TextureHelpers.BlendAlpha(loader.hiddenIcon, overrideIcon);
Info.WithIcon(ImageUtils.LoadSpriteFromTexture(newIcon));
Expand Down
1 change: 1 addition & 0 deletions SCHIZO/Jukebox/CustomJukeboxTrackPatches.BelowZero.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static CustomJukeboxTrackPatches()
{
CoroutineHost.StartCoroutine(GetJukeboxDiskPrefab());
CoroutineHost.StartCoroutine(InitJukebox());
SaveUtils.RegisterOnQuitEvent(() => CoroutineHost.StartCoroutine(InitJukebox()));
}
private static IEnumerator GetJukeboxDiskPrefab()
{
Expand Down
10 changes: 5 additions & 5 deletions SCHIZO/Registering/ComponentAdder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Reflection;
using HarmonyLib;
using SCHIZO.Helpers;
using UnityEngine;

namespace SCHIZO.Registering;
Expand All @@ -24,8 +25,8 @@ protected override void Register()
return;
}

Type targetType = AccessTools.TypeByName(typeName);
Type actualTargetType = _isBaseType ? AccessTools.TypeByName(targetTypeName) : targetType;
Type targetType = ReflectionCache.GetType(typeName);
Type actualTargetType = _isBaseType ? ReflectionCache.GetType(targetTypeName) : targetType;
if (scanForExisting)
{
foreach (Component o in FindObjectsOfType(actualTargetType).Cast<Component>())
Expand All @@ -34,9 +35,8 @@ protected override void Register()
}
}

MethodInfo targetMethod = AccessTools.Method(targetType, methodName);
if (targetMethod == null) throw new MissingMethodException(typeName, methodName);

MethodInfo targetMethod = AccessTools.Method(targetType, methodName)
?? throw new MissingMethodException(typeName, methodName);
Target target = CreateTarget(targetMethod, mode);
Entry entry = new(actualTargetType, prefab);

Expand Down
9 changes: 6 additions & 3 deletions SCHIZO/Twitch/TwitchIntegration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Nautilus.Commands;
Expand All @@ -22,9 +23,11 @@ partial class TwitchIntegration

private TwitchClient _client;
private readonly ConcurrentQueue<string> _msgQueue = new();
private HashSet<string> _allowedUsersSet;

private void Awake()
{
_allowedUsersSet = new(whitelistedUsers, StringComparer.OrdinalIgnoreCase);
ClientOptions clientOptions = new()
{
MessagesAllowedInPeriod = 750,
Expand Down Expand Up @@ -69,7 +72,7 @@ private void Client_OnMessageReceived(object _, OnMessageReceivedArgs evt)

private bool IsUserWhitelisted(string username)
{
return whitelistedUsers.Any(user => user.Equals(username, StringComparison.InvariantCultureIgnoreCase));
return _allowedUsersSet.Contains(username);
}

private bool CheckPrefix(string message)
Expand All @@ -79,7 +82,7 @@ private bool CheckPrefix(string message)

private void FixedUpdate()
{
if (_msgQueue.Count > 0 && _msgQueue.TryDequeue(out string message)) HandleMessage(message);
if (_msgQueue.TryDequeue(out string message)) HandleMessage(message);
}

private static void HandleMessage(string message)
Expand Down
19 changes: 0 additions & 19 deletions SCHIZO/_old/Creatures/Ermfish/ErmfishLoader.cs

This file was deleted.

1 change: 1 addition & 0 deletions Unity/Assets/Mod/Anneel/Databank/Databank.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
someone please fill this in before vedal plays the mod i'm begging you
2 changes: 1 addition & 1 deletion Unity/Assets/Mod/Erm Bed/Erm Bed.asset
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ MonoBehaviour:
id: 0
classId: ermbed
displayName: Erm Bed
tooltip: '[PH] What if..we hold hands..under the Erm blanket tonight? :flushed:
tooltip: 'What if..we hold hands..under the Erm blanket tonight? :flushed:
Haha
just kidding... unless..? :pleading_face: :point_right::point_left:'
Expand Down
4 changes: 1 addition & 3 deletions Unity/Assets/Mod/Events/Event Manager.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 78315918d0514014d864600fb981a894, type: 3}
m_Name:
m_EditorClassIdentifier:
autoStartEvents: 1
overridePlayerPrefs: 0
--- !u!114 &2221432346329158674
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -60,7 +58,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
canAutoStart: 1
requiredStoryGoal_SN:
requiredStoryGoal_BZ:
requiredStoryGoal_BZ: SanctuaryCompleted
ticketsSold: {x: 10, y: 50}
attendeeSearchRadius: 250
panelistSearchRadius: 30
Expand Down
4 changes: 3 additions & 1 deletion Unity/Assets/Mod/Green Screen/Green Screens.asset
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c08c4776b89c430d985e9557dc60112d, type: 3}
m_Name: Green Screens
m_EditorClassIdentifier:
registryItems: []
registryItems:
- {fileID: 11400000, guid: ac6932989e512cc43a944ca4fc5924f0, type: 2}
- {fileID: 11400000, guid: 6710c9cdea33a7f4ab8ba37ee479c8e8, type: 2}
Loading

0 comments on commit 3687576

Please sign in to comment.