This repository has been archived by the owner on May 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LFS: add V2 screenshot event API with ValueTuple instead of Tuple and…
… clearer orientation enum, bump version
- Loading branch information
Showing
8 changed files
with
125 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#nullable enable | ||
|
||
namespace LagFreeScreenshots.API | ||
{ | ||
public static class LfsApi | ||
{ | ||
/// <summary> | ||
/// Called after a creenshot is taken and written to disk | ||
/// </summary> | ||
public static event ScreenshotSavedEventV2? OnScreenshotSavedV2; | ||
|
||
public delegate void ScreenshotSavedEventV2(string filePath, int width, int height, MetadataV2? metadata); | ||
|
||
internal static void InvokeScreenshotSaved(string filePath, int width, int height, MetadataV2? metadataV2) => | ||
OnScreenshotSavedV2?.Invoke(filePath, width, height, metadataV2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using UnityEngine; | ||
using VRC; | ||
using VRC.Core; | ||
|
||
namespace LagFreeScreenshots.API | ||
{ | ||
public class MetadataV2 | ||
{ | ||
public readonly ScreenshotRotation ImageRotation; | ||
public readonly APIUser ApiUser; | ||
public readonly ApiWorldInstance WorldInstance; | ||
public Vector3 Position; | ||
public readonly List<(Player, Vector3)> PlayerList; | ||
|
||
public MetadataV2(ScreenshotRotation imageRotation, APIUser apiUser, ApiWorldInstance apiWorldInstance, Vector3 position, List<(Player, Vector3)> playerList) | ||
{ | ||
ImageRotation = imageRotation; | ||
ApiUser = apiUser; | ||
WorldInstance = apiWorldInstance; | ||
Position = position; | ||
PlayerList = playerList; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
var worldString = "null,0,Not in any world"; | ||
if (WorldInstance != null && WorldInstance.world != null) | ||
worldString = WorldInstance.world.id + "," + WorldInstance.name + "," + WorldInstance.world.name; | ||
|
||
var positionString = Position.x.ToString(CultureInfo.InvariantCulture) + "," + Position.y.ToString(CultureInfo.InvariantCulture) + "," + Position.z.ToString(CultureInfo.InvariantCulture); | ||
|
||
return "lfs|2|author:" | ||
+ ApiUser.id + "," + ApiUser.displayName | ||
+ "|world:" + worldString | ||
+ "|pos:" + positionString | ||
+ (ImageRotation != ScreenshotRotation.NoRotation ? "|rq:" + ImageRotation : "") | ||
+ "|players:" + string.Join(";", PlayerList.Select(PlayerListToString)); | ||
} | ||
|
||
private static string PlayerListToString((Player, Vector3) playerData) | ||
{ | ||
if (playerData.Item1 == null || playerData.Item1.prop_APIUser_0 == null) return "null,0,0,0,null"; | ||
return playerData.Item1.prop_APIUser_0.id + "," + | ||
playerData.Item2.x.ToString("0.00", CultureInfo.InvariantCulture) + "," + | ||
playerData.Item2.y.ToString("0.00", CultureInfo.InvariantCulture) + "," + | ||
playerData.Item2.z.ToString("0.00", CultureInfo.InvariantCulture) + "," + | ||
playerData.Item1.prop_APIUser_0.displayName; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace LagFreeScreenshots.API | ||
{ | ||
public enum ScreenshotRotation | ||
{ | ||
AutoRotationDisabled = -1, | ||
NoRotation = 0, | ||
Clockwise90 = 1, | ||
Clockwise180 = 2, | ||
CounterClockwise90 = 3 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
using System; | ||
using LagFreeScreenshots.API; | ||
|
||
namespace LagFreeScreenshots | ||
{ | ||
[Obsolete("Use LagFreeScreenshots.API.LfsApi")] | ||
public static class EventHandler | ||
{ | ||
/// <summary> | ||
/// Calls when an screenshot is saved | ||
/// </summary> | ||
public static event Action<string, int, int, Metadata> OnScreenshotSaved; | ||
|
||
internal static void InvokeScreenshotSaved(string filePath, int width, int height, Metadata metadata) => OnScreenshotSaved?.Invoke(filePath, width, height, metadata); | ||
internal static void InvokeScreenshotSaved(string filePath, int width, int height, MetadataV2 metadata) | ||
{ | ||
OnScreenshotSaved?.Invoke(filePath, width, height, new Metadata(metadata)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters