Skip to content

Commit

Permalink
Rename PunPun to Log and refactor SaveSystem & TileSystem (#1229)
Browse files Browse the repository at this point in the history
* Rename PunPun to Log and refactor SaveSystem & TileSystem

* Remove unused stuff

* Add missing metas and script fixes

* Fix missing log changes

* Fix missing changes

* Add map saves

* Fix how folder checks are made

* Add log when the saved map is null

* Add warning and pragma explanation

* Fix issue with client's build menu
  • Loading branch information
joaoburatto authored Sep 29, 2023
1 parent b3a90a1 commit d6d8204
Show file tree
Hide file tree
Showing 72 changed files with 1,040 additions and 902 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,16 @@ void CallDiscord()
activityManager.SendInvite(485905734618447895, ActivityActionType.Join, "", (inviteUserResult) =>
{
Console.WriteLine("Invite User {0}", inviteUserResult);
Punpun.Information(nameof(DiscordManager), "How is This Working >???", Logs.External);
Log.Information(nameof(DiscordManager), "How is This Working >???", Logs.External);
});

if(res == Result.Ok)
{
Punpun.Information(this, "Discord Status Is On!", Logs.External);
Log.Information(this, "Discord Status Is On!", Logs.External);
}
else
{
Punpun.Error(nameof(DiscordManager), "Discord Status Failed!", Logs.External);
Log.Error(nameof(DiscordManager), "Discord Status Failed!", Logs.External);
}
});
}
Expand All @@ -230,7 +230,7 @@ void CallDiscord()

void OnDisable()
{
Punpun.Warning(nameof(DiscordManager), "Discord Shutdown after 10 seconds", Logs.External);
Log.Warning(nameof(DiscordManager), "Discord Shutdown after 10 seconds", Logs.External);

Shutdown();
discord?.Dispose();
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scripts/External/FishNet.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Scripts/External/FishNet/CodeGenerating.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Scripts/External/FishNet/Runtime.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Scripts/External/FishNet/Runtime/Transporting.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions Assets/Scripts/SS3D/Core/ApplicationInitializerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using SS3D.Core.Utils;
using SS3D.Data;
using SS3D.Data.Enums;
using SS3D.Data.Management;
using SS3D.Logging;
using SS3D.SceneManagement;
using UDiscord;
Expand Down Expand Up @@ -35,18 +36,23 @@ private void InitializeLauncher()
sceneToLoad = Scenes.Launcher;
}

// This call is async and not awaited. Hence the pragma disable.
#pragma warning disable CS4014
Scene.LoadAsync(sceneToLoad);
#pragma warning restore CS4014
}

/// <summary>
/// Initializes all required systems for the application.
/// </summary>
public void InitializeApplication()
{
Punpun.Information(this, "Initializing application", Logs.Important);
Log.Information(this, "Initializing application", Logs.Important);

DOTween.Init();

SaveSystem.Initialize();

InitializeDiscordIntegration();
InitializeAssetData();

Expand Down Expand Up @@ -103,7 +109,7 @@ private void InitializeDiscordIntegration()
/// </summary>
private void InitializeNetworkSession()
{
Punpun.Information(this, "Initializing network session", Logs.Important);
Log.Information(this, "Initializing network session", Logs.Important);

SessionNetworkSystem sessionNetworkSystem = Subsystems.Get<SessionNetworkSystem>();
sessionNetworkSystem.InitializeNetworkSession();
Expand Down
26 changes: 12 additions & 14 deletions Assets/Scripts/SS3D/Core/LogManager.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using Serilog;
using Serilog.Sinks.Unity3D;
using Serilog.Core;
using Serilog.Events;
using Serilog.Formatting.Compact;
using UnityEngine;
using FishNet;
using System;
using System.Linq;
using System.Collections.Generic;
using SS3D.Logging.LogSettings;
using SS3D.Logging;
using SS3D.Data;
using Log = Serilog.Log;


namespace SS3D.Core
Expand All @@ -23,28 +21,28 @@ namespace SS3D.Core
/// </summary>
public static class LogManager
{
private static readonly string defaultUnityLogTemplate;
private static readonly string DefaultUnityLogTemplate;
private static readonly string LogFolderPath;
private static bool _isInitialized;
private static bool IsInitialized;

private static LogSetting settings;
private static readonly LogSettings Settings;

static LogManager()
{
defaultUnityLogTemplate = "{SourceContext} {Message}{NewLine}{Exception}";
DefaultUnityLogTemplate = "{SourceContext} {Message}{NewLine}{Exception}";
LogFolderPath = Application.dataPath + "/../Logs/";

if (Application.isPlaying)
{
settings = Assets.Get<LogSetting>(Data.Enums.AssetDatabases.Settings, (int)Data.Enums.SettingsId.LogSettings);
Settings = Assets.Get<LogSettings>(Data.Enums.AssetDatabases.Settings, (int)Data.Enums.SettingsId.LogSettings);
}

}

public static void Initialize()
{
if (_isInitialized) return;
_isInitialized = true;
if (IsInitialized) return;
IsInitialized = true;

var configuration = new LoggerConfiguration();

Expand All @@ -54,7 +52,7 @@ public static void Initialize()
}

// Configure writing to Unity's console, using our custom text formatter.
configuration = configuration.WriteTo.Unity3D(formatter: new SS3DUnityTextFormatter(outputTemplate: defaultUnityLogTemplate));
configuration = configuration.WriteTo.Unity3D(formatter: new SS3DUnityTextFormatter(outputTemplate: DefaultUnityLogTemplate));



Expand All @@ -77,9 +75,9 @@ private static LoggerConfiguration ConfigureForPlayMode(LoggerConfiguration conf

// Apply some override on the minimum logging level for some namespaces using the log settings.
// Does not apply override if the logging level corresponds to the global minimum level.
foreach (var levelForNameSpace in settings.SS3DNameSpaces)
foreach (var levelForNameSpace in Settings.SS3DNameSpaces)
{
if (levelForNameSpace.Level == settings.defaultLogLevel) continue;
if (levelForNameSpace.Level == Settings.defaultLogLevel) continue;

configuration = configuration.MinimumLevel.Override(levelForNameSpace.Name, levelForNameSpace.Level);
}
Expand Down Expand Up @@ -110,7 +108,7 @@ private static LoggerConfiguration ConfigureForPlayMode(LoggerConfiguration conf
/// </summary>
private static LoggerConfiguration ConfigureMinimumLevel(LoggerConfiguration loggerConfiguration)
{
switch (settings.defaultLogLevel)
switch (Settings.defaultLogLevel)
{
case LogEventLevel.Verbose: return loggerConfiguration.MinimumLevel.Verbose();
case LogEventLevel.Debug: return loggerConfiguration.MinimumLevel.Debug();
Expand Down
10 changes: 5 additions & 5 deletions Assets/Scripts/SS3D/Core/SessionNetworkSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public void InitializeNetworkSession()
switch (networkType)
{
case NetworkType.DedicatedServer:
Punpun.Information(this, "Hosting a new headless server on port {port}", Logs.Important, port);
Log.Information(this, "Hosting a new headless server on port {port}", Logs.Important, port);
networkManager.ServerManager.StartConnection(port);
break;
case NetworkType.Client:
Punpun.Information(this, "Joining server {serverAddress}:{port} as {ckey}", Logs.Important, serverAddress, port, ckey);
Log.Information(this, "Joining server {serverAddress}:{port} as {ckey}", Logs.Important, serverAddress, port, ckey);
networkManager.ClientManager.StartConnection(serverAddress, port);
break;
case NetworkType.Host:
Punpun.Information(this, "Hosting a new server on port {port}", Logs.Important, port);
Log.Information(this, "Hosting a new server on port {port}", Logs.Important, port);
networkManager.ServerManager.StartConnection(port);
networkManager.ClientManager.StartConnection();
break;
Expand All @@ -69,11 +69,11 @@ public void CloseNetworkSession()
NetworkManager networkManager = InstanceFinder.NetworkManager;
if (networkManager == null)
{
Punpun.Warning(this, "No NetworkManager found", Logs.Important);
Log.Warning(this, "No NetworkManager found", Logs.Important);
return;
}

Punpun.Information(this, "Closing network session", Logs.Important);
Log.Information(this, "Closing network session", Logs.Important);
networkManager.TransportManager.Transport.Shutdown();
}
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/SS3D/Core/Settings/NetworkSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static void ResetOnBuiltApplication()
{
NetworkSettings networkSettings = GetOrFind<NetworkSettings>();

Punpun.Information(nameof(NetworkSettings), $"Network settings reset on the built executable");
Log.Information(nameof(NetworkSettings), $"Network settings reset on the built executable");

networkSettings.NetworkType = NetworkType.Client;
networkSettings.ServerAddress = string.Empty;
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/SS3D/Core/Subsystems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static T Get<T>() where T : MonoBehaviour
string message = $"Couldn't find subsystem of {typeof(T).Name} in the scene";

// ReSharper disable once Unity.PerformanceCriticalCodeInvocation
Punpun.Error(typeof(Subsystems), message, Logs.Important);
Log.Error(typeof(Subsystems), message, Logs.Important);

return null;
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/SS3D/Core/Utils/CommandLineArgsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private void LoadCommandLineArgs()
}
catch (Exception e)
{
Punpun.Information(this,e,$"Failed to load command line arguments");
Log.Information(this,e,$"Failed to load command line arguments");
throw;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/SS3D/Core/ViewLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static List<T> Get<T>() where T : MonoBehaviour

string message = $"No views of type {typeof(T).Name} found.";
// ReSharper disable once Unity.PerformanceCriticalCodeInvocation
Punpun.Error(typeof(Subsystems), "No views of type {typeName} found", Logs.Important, typeof(T).Name);
Log.Error(typeof(Subsystems), "No views of type {typeName} found", Logs.Important, typeof(T).Name);

return null;
}
Expand Down
6 changes: 3 additions & 3 deletions Assets/Scripts/SS3D/Data/Assets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static void LoadAssetDatabases()
Databases.Add(index, database);
}

Punpun.Information(typeof(Assets), "{assetDatabasesCount} Asset Databases initialized", Logs.Important, assetDatabases.Count);
Log.Information(typeof(Assets), "{assetDatabasesCount} Asset Databases initialized", Logs.Important, assetDatabases.Count);
}

/// <summary>
Expand All @@ -103,7 +103,7 @@ public static AssetDatabase GetDatabase(int key)

if (!databaseExists)
{
Punpun.Warning(typeof(Assets), "Database of type {key} not found", Logs.Important, key);
Log.Warning(typeof(Assets), "Database of type {key} not found", Logs.Important, key);
}

return database;
Expand All @@ -120,7 +120,7 @@ public static AssetDatabase GetDatabase(Enums.AssetDatabases key)

if (!databaseExists)
{
Punpun.Warning(typeof(Assets), "Database of type {key} not found", Logs.Important, key);
Log.Warning(typeof(Assets), "Database of type {key} not found", Logs.Important, key);
}

return database;
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/SS3D/Data/GamePaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public enum GamePaths
{
Root,
Config,
Data,
}
}
3 changes: 3 additions & 0 deletions Assets/Scripts/SS3D/Data/Management.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d6d8204

Please sign in to comment.