Skip to content

Commit

Permalink
Merge pull request #234 from misternebula/dev
Browse files Browse the repository at this point in the history
0.7.1
  • Loading branch information
misternebula authored Dec 21, 2020
2 parents b3ac505 + dc6232b commit 5b25035
Show file tree
Hide file tree
Showing 65 changed files with 775 additions and 1,334 deletions.
2 changes: 1 addition & 1 deletion QSB/Animation/AnimControllerPatch.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using OWML.ModHelper.Events;
using OWML.Utils;
using UnityEngine;

namespace QSB.Animation
Expand Down
6 changes: 3 additions & 3 deletions QSB/Animation/AnimationSync.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using OWML.Common;
using OWML.ModHelper.Events;
using OWML.Utils;
using QSB.Events;
using QSB.Player;
using QSB.Utility;
Expand Down Expand Up @@ -184,11 +184,11 @@ public void SetAnimationType(AnimationType type)
CurrentType = type;
if (_unsuitedAnimController == null)
{
DebugLog.DebugWrite($"Error - Unsuited controller is null. ({PlayerId})", MessageType.Error);
DebugLog.ToConsole($"Error - Unsuited controller is null. ({PlayerId})", MessageType.Error);
}
if (_suitedAnimController == null)
{
DebugLog.DebugWrite($"Error - Suited controller is null. ({PlayerId})", MessageType.Error);
DebugLog.ToConsole($"Error - Suited controller is null. ({PlayerId})", MessageType.Error);
}
RuntimeAnimatorController controller = default;
switch (type)
Expand Down
4 changes: 2 additions & 2 deletions QSB/Animation/AnimatorMirror.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public void Init(Animator from, Animator to)
_to = to;
if (_from.runtimeAnimatorController == null)
{
DebugLog.DebugWrite($"Warning - \"From\" ({from.name}) controller is null.", MessageType.Warning);
DebugLog.ToConsole($"Warning - \"From\" ({from.name}) controller is null.", MessageType.Warning);
_from.runtimeAnimatorController = _to.runtimeAnimatorController;
}
else if (_to.runtimeAnimatorController == null)
{
DebugLog.DebugWrite($"Warning - \"To\" ({to.name}) controller is null.", MessageType.Warning);
DebugLog.ToConsole($"Warning - \"To\" ({to.name}) controller is null.", MessageType.Warning);
_to.runtimeAnimatorController = _from.runtimeAnimatorController;
}
foreach (var param in _from.parameters.Where(p => p.type == AnimatorControllerParameterType.Float))
Expand Down
2 changes: 1 addition & 1 deletion QSB/ConversationSync/ConversationManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using OWML.Common;
using OWML.ModHelper.Events;
using OWML.Utils;
using QSB.Events;
using QSB.Player;
using QSB.Utility;
Expand Down
2 changes: 1 addition & 1 deletion QSB/ConversationSync/ConversationPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static bool EndConversation(CharacterDialogueTree __instance)
if (QSBPlayerManager.LocalPlayer.CurrentDialogueID == -1)
{
DebugLog.ToConsole($"Warning - Ending conversation with CurrentDialogueId of -1! Called from {__instance.name}", MessageType.Warning);
return false;
return true;
}
ConversationManager.Instance.SendConvState(QSBPlayerManager.LocalPlayer.CurrentDialogueID, false);
ConversationManager.Instance.CloseBoxCharacter(QSBPlayerManager.LocalPlayer.CurrentDialogueID);
Expand Down
2 changes: 1 addition & 1 deletion QSB/ConversationSync/Events/ConversationStartEndEvent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using OWML.Common;
using OWML.ModHelper.Events;
using OWML.Utils;
using QSB.Events;
using QSB.Player;
using QSB.Utility;
Expand Down
5 changes: 5 additions & 0 deletions QSB/DeathSync/DeathPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public class DeathPatches : QSBPatch

public static bool PreFinishDeathSequence(DeathType deathType)
{
if (RespawnOnDeath.Instance == null)
{
return true;
}

if (RespawnOnDeath.Instance.AllowedDeathTypes.Contains(deathType))
{
// Allow real death
Expand Down
2 changes: 1 addition & 1 deletion QSB/DeathSync/PreventShipDestruction.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Harmony;
using OWML.ModHelper.Events;
using OWML.Utils;
using System.Collections.Generic;
using System.Reflection.Emit;
using UnityEngine;
Expand Down
35 changes: 14 additions & 21 deletions QSB/DeathSync/RespawnOnDeath.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using OWML.Common;
using OWML.ModHelper.Events;
using OWML.Utils;
using QSB.Events;
using QSB.Utility;
using System.Linq;
Expand Down Expand Up @@ -28,21 +28,7 @@ public class RespawnOnDeath : MonoBehaviour
private ShipCockpitController _cockpitController;
private PlayerSpacesuit _spaceSuit;

public void Awake()
{
Instance = this;

QSBCore.Helper.Events.Subscribe<PlayerResources>(OWML.Common.Events.AfterStart);
QSBCore.Helper.Events.Event += OnEvent;
}

private void OnEvent(MonoBehaviour behaviour, OWML.Common.Events ev)
{
if (behaviour is PlayerResources && ev == OWML.Common.Events.AfterStart)
{
Init();
}
}
public void Awake() => Instance = this;

public void Init()
{
Expand Down Expand Up @@ -71,17 +57,18 @@ public void Init()

public void ResetShip()
{
if (_shipBody == null)
if (_shipSpawnPoint == null)
{
return;
DebugLog.ToConsole("Warning - _shipSpawnPoint is null!", MessageType.Warning);
Init();
}

// Reset ship position.
if (_shipSpawnPoint == null)
if (_shipBody == null)
{
DebugLog.ToConsole("_shipSpawnPoint is null!", MessageType.Warning);
return;
}

// Reset ship position.
_shipBody.SetVelocity(_shipSpawnPoint.GetPointVelocity());
_shipBody.WarpToPositionRotation(_shipSpawnPoint.transform.position, _shipSpawnPoint.transform.rotation);

Expand All @@ -108,6 +95,12 @@ private void ExitShip()

public void ResetPlayer()
{
if (_shipSpawnPoint == null)
{
DebugLog.ToConsole("Warning - _playerSpawnPoint is null!", MessageType.Warning);
Init();
}

// Reset player position.
var playerBody = Locator.GetPlayerBody();
playerBody.WarpToPositionRotation(_playerSpawnPoint.transform.position, _playerSpawnPoint.transform.rotation);
Expand Down
2 changes: 1 addition & 1 deletion QSB/ElevatorSync/ElevatorPatches.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using OWML.ModHelper.Events;
using OWML.Utils;
using QSB.Events;
using QSB.Patches;

Expand Down
2 changes: 1 addition & 1 deletion QSB/ElevatorSync/QSBElevator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using OWML.ModHelper.Events;
using OWML.Utils;
using QSB.WorldSync;
using UnityEngine;

Expand Down
3 changes: 1 addition & 2 deletions QSB/Instruments/InstrumentsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void StartInstrument(AnimationType type)
{
if (!IsLocalPlayer)
{
DebugLog.DebugWrite("Error - Tried to start instrument on non-local player!", MessageType.Error);
DebugLog.ToConsole("Error - Tried to start instrument on non-local player!", MessageType.Error);
return;
}
if (Player.PlayingInstrument || !Locator.GetPlayerController().IsGrounded())
Expand All @@ -115,7 +115,6 @@ public void ReturnToPlayer()

public void SwitchToType(AnimationType type)
{
DebugLog.DebugWrite($"switch to type {type} player {PlayerId}");
GlobalMessenger<uint, AnimationType>.FireEvent(EventNames.QSBChangeAnimType, QSBPlayerManager.LocalPlayerId, type);
QSBPlayerManager.LocalPlayer.AnimationSync.SetAnimationType(type);
CheckInstrumentProps(type);
Expand Down
9 changes: 7 additions & 2 deletions QSB/OrbSync/Events/OrbUserEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private static void HandleServer(WorldObjectMessage message)
}
if (fromPlayer == null)
{
DebugLog.DebugWrite("Error - FromPlayer is null!", MessageType.Error);
DebugLog.ToConsole("Error - FromPlayer is null!", MessageType.Error);
}
var orbSync = QSBWorldSync.OrbSyncList
.First(x => x.AttachedOrb == QSBWorldSync.OldOrbList[message.ObjectId]);
Expand All @@ -85,11 +85,16 @@ private static void HandleClient(WorldObjectMessage message)
{
if (QSBWorldSync.OrbSyncList.Count < message.ObjectId)
{
DebugLog.DebugWrite(
DebugLog.ToConsole(
$"Error - Orb id {message.ObjectId} out of range of orb sync list {QSBWorldSync.OrbSyncList.Count}.",
MessageType.Error);
return;
}
if (!QSBWorldSync.OrbSyncList.Any(x => x.AttachedOrb == QSBWorldSync.OldOrbList[message.ObjectId]))
{
DebugLog.ToConsole($"Error - No NomaiOrbTransformSync has AttachedOrb with objectId {message.ObjectId}!");
return;
}
var orb = QSBWorldSync.OrbSyncList
.First(x => x.AttachedOrb == QSBWorldSync.OldOrbList[message.ObjectId]);
orb.enabled = true;
Expand Down
2 changes: 1 addition & 1 deletion QSB/OrbSync/QSBOrbSlot.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using OWML.ModHelper.Events;
using OWML.Utils;
using QSB.Events;
using QSB.WorldSync;

Expand Down
2 changes: 1 addition & 1 deletion QSB/Player/Events/PlayerJoinEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override void OnReceiveRemote(bool server, PlayerJoinMessage message)
{
var player = QSBPlayerManager.GetPlayer(message.AboutId);
player.Name = message.PlayerName;
DebugLog.ToHud($"{player.Name} joined!");
DebugLog.ToAll($"{player.Name} joined!", MessageType.Info);
DebugLog.DebugWrite($"{player.Name} joined as id {player.PlayerId}", MessageType.Info);
}

Expand Down
70 changes: 70 additions & 0 deletions QSB/Player/PlayerMapMarker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using UnityEngine;

namespace QSB.Player
{
public class PlayerMapMarker : MonoBehaviour
{
public string PlayerName;
private Transform _playerTransform;
private CanvasMapMarker _canvasMarker;
private bool _canvasMarkerInitialized;

public void Awake()
{
GlobalMessenger.AddListener("EnterMapView", new Callback(OnEnterMapView));
GlobalMessenger.AddListener("ExitMapView", new Callback(OnExitMapView));
}

public void Start()
{
enabled = false;
_playerTransform = Locator.GetPlayerTransform();
}

public void OnDestroy()
{
GlobalMessenger.RemoveListener("EnterMapView", new Callback(OnEnterMapView));
GlobalMessenger.RemoveListener("ExitMapView", new Callback(OnExitMapView));
}

public void InitMarker()
{
var obj = GameObject.FindWithTag("MapCamera");
var markerManager = obj.GetRequiredComponent<MapController>().GetMarkerManager();
_canvasMarker = markerManager.InstantiateNewMarker(true);
var component = GetComponent<OWRigidbody>();
if (component != null)
{
markerManager.RegisterMarker(_canvasMarker, component);
}
else
{
markerManager.RegisterMarker(_canvasMarker, transform);
}
_canvasMarker.SetLabel(PlayerName.ToUpper());
_canvasMarker.SetColor(Color.white);
_canvasMarker.SetVisibility(false);
_canvasMarkerInitialized = true;
}

private void OnEnterMapView() => enabled = true;
private void OnExitMapView() => enabled = false;

public void LateUpdate()
{
if (!_canvasMarkerInitialized)
{
InitMarker();
}
var a = Locator.GetActiveCamera().WorldToScreenPoint(transform.position);
var b = Locator.GetActiveCamera().WorldToScreenPoint(_playerTransform.position);
var vector = a - b;
vector.z = 0f;
var flag = a.z > 0f;
if (_canvasMarker.IsVisible() != flag)
{
_canvasMarker.SetVisibility(flag);
}
}
}
}
12 changes: 2 additions & 10 deletions QSB/Player/QSBPlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,9 @@ public static IEnumerable<T> GetSyncObjects<T>() where T : PlayerSyncObject =>
public static T GetSyncObject<T>(uint id) where T : PlayerSyncObject =>
GetSyncObjects<T>().FirstOrDefault(x => x != null && x.AttachedNetId == id);

public static void AddSyncObject(PlayerSyncObject obj)
{
DebugLog.DebugWrite($"SyncObject Add : type<{obj.GetType().Name}>, netid<{obj.NetId}>");
PlayerSyncObjects.Add(obj);
}
public static void AddSyncObject(PlayerSyncObject obj) => PlayerSyncObjects.Add(obj);

public static void RemoveSyncObject(PlayerSyncObject obj)
{
DebugLog.DebugWrite($"SyncObject Remove : type<{obj.GetType().Name}>, netid<{obj.NetId}>");
PlayerSyncObjects.Remove(obj);
}
public static void RemoveSyncObject(PlayerSyncObject obj) => PlayerSyncObjects.Remove(obj);

public static bool IsBelongingToLocalPlayer(uint id)
{
Expand Down
Loading

0 comments on commit 5b25035

Please sign in to comment.