-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing support for showing images through primitive objects & hi…
…nts.
- Loading branch information
Showing
36 changed files
with
1,144 additions
and
777 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using LabExtended.API.Hints; | ||
using LabExtended.API.Hints.Elements.Personal; | ||
|
||
using LabExtended.Commands; | ||
using LabExtended.Commands.Arguments; | ||
using LabExtended.Commands.Interfaces; | ||
|
||
namespace LabExtended.API.CustomCommands.Hints.Loop; | ||
|
||
public class LoopCommand : CustomCommand | ||
{ | ||
public override string Command { get; } = "loop"; | ||
public override string Description { get; } = "Toggles looping."; | ||
|
||
public override void OnCommand(ExPlayer sender, ICommandContext ctx, ArgumentCollection args) | ||
{ | ||
base.OnCommand(sender, ctx, args); | ||
|
||
if (!sender.TryGetHintElement<PersonalImageElement>(out var personalImageElement)) | ||
{ | ||
ctx.RespondFail($"No personal image element found."); | ||
return; | ||
} | ||
|
||
personalImageElement.IsLooping = !personalImageElement.IsLooping; | ||
|
||
if (personalImageElement.IsLooping) | ||
ctx.RespondOk($"Enabled looping."); | ||
else | ||
ctx.RespondOk($"Disabled looping."); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
LabExtended/API/CustomCommands/Hints/Pause/PauseCommand.cs
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,32 @@ | ||
using LabExtended.API.Hints; | ||
using LabExtended.API.Hints.Elements.Personal; | ||
|
||
using LabExtended.Commands; | ||
using LabExtended.Commands.Arguments; | ||
using LabExtended.Commands.Interfaces; | ||
|
||
namespace LabExtended.API.CustomCommands.Hints.Pause; | ||
|
||
public class PauseCommand : CustomCommand | ||
{ | ||
public override string Command { get; } = "pause"; | ||
public override string Description { get; } = "Toggles image pause."; | ||
|
||
public override void OnCommand(ExPlayer sender, ICommandContext ctx, ArgumentCollection args) | ||
{ | ||
base.OnCommand(sender, ctx, args); | ||
|
||
if (!sender.TryGetHintElement<PersonalImageElement>(out var personalImageElement)) | ||
{ | ||
ctx.RespondFail($"No personal image element found."); | ||
return; | ||
} | ||
|
||
personalImageElement.IsPaused = !personalImageElement.IsPaused; | ||
|
||
if (personalImageElement.IsPaused) | ||
ctx.RespondOk($"Paused image."); | ||
else | ||
ctx.RespondOk($"Unpaused image."); | ||
} | ||
} |
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,29 @@ | ||
using LabExtended.API.Hints; | ||
using LabExtended.API.Hints.Elements.Personal; | ||
|
||
using LabExtended.Commands; | ||
using LabExtended.Commands.Arguments; | ||
using LabExtended.Commands.Interfaces; | ||
|
||
namespace LabExtended.API.CustomCommands.Hints.Stop; | ||
|
||
public class StopCommand : CustomCommand | ||
{ | ||
public override string Command { get; } = "stop"; | ||
public override string Description { get; } = "Stops image playback."; | ||
|
||
public override void OnCommand(ExPlayer sender, ICommandContext ctx, ArgumentCollection args) | ||
{ | ||
base.OnCommand(sender, ctx, args); | ||
|
||
if (!sender.TryGetHintElement<PersonalImageElement>(out var personalImageElement)) | ||
{ | ||
ctx.RespondFail($"No personal image element found."); | ||
return; | ||
} | ||
|
||
personalImageElement.Reset(); | ||
|
||
ctx.RespondOk($"Playback stopped."); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
LabExtended/API/CustomCommands/Image/Destroy/DestroyCommand.cs
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,34 @@ | ||
using LabExtended.Commands; | ||
using LabExtended.Commands.Arguments; | ||
using LabExtended.Commands.Interfaces; | ||
|
||
namespace LabExtended.API.CustomCommands.Image.Destroy; | ||
|
||
public class DestroyCommand : CustomCommand | ||
{ | ||
public override string Command { get; } = "destroy"; | ||
public override string Description { get; } = "Destroys an active primitive image."; | ||
|
||
public override ArgumentDefinition[] BuildArgs() | ||
{ | ||
return GetArg<int>("ID", "ID of the image."); | ||
} | ||
|
||
public override void OnCommand(ExPlayer sender, ICommandContext ctx, ArgumentCollection args) | ||
{ | ||
base.OnCommand(sender, ctx, args); | ||
|
||
var id = args.Get<int>("ID"); | ||
|
||
if (!ImageCommand.SpawnedImages.TryGetValue(id, out var image)) | ||
{ | ||
ctx.RespondFail($"No image with ID {id}"); | ||
return; | ||
} | ||
|
||
image.Dispose(); | ||
ImageCommand.SpawnedImages.Remove(id); | ||
|
||
ctx.RespondOk($"Image with ID {id} has been destroyed."); | ||
} | ||
} |
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,61 @@ | ||
using CommandSystem; | ||
|
||
using LabExtended.API.CustomCommands.Image.Destroy; | ||
using LabExtended.API.CustomCommands.Image.Loop; | ||
using LabExtended.API.CustomCommands.Image.Pause; | ||
using LabExtended.API.CustomCommands.Image.Play; | ||
using LabExtended.API.CustomCommands.Image.Spawn; | ||
using LabExtended.API.CustomCommands.Image.Stop; | ||
|
||
using LabExtended.API.Toys.Primitives; | ||
|
||
using LabExtended.Attributes; | ||
using LabExtended.Commands; | ||
using LabExtended.Events; | ||
|
||
using Utils.NonAllocLINQ; | ||
|
||
namespace LabExtended.API.CustomCommands.Image; | ||
|
||
[CommandHandler(typeof(RemoteAdminCommandHandler))] | ||
[CommandHandler(typeof(GameConsoleCommandHandler))] | ||
public class ImageCommand : VanillaParentCommandBase | ||
{ | ||
#region Static Methods | ||
private static int idClock = 0; | ||
|
||
public static int NewId => idClock++; | ||
|
||
public static Dictionary<int, PrimitiveDynamicImage> SpawnedImages { get; } = | ||
new Dictionary<int, PrimitiveDynamicImage>(); | ||
|
||
private static void OnRoundRestart() | ||
{ | ||
SpawnedImages.ForEachValue(x => x.Dispose()); | ||
SpawnedImages.Clear(); | ||
|
||
idClock = 0; | ||
} | ||
|
||
[LoaderInitialize(1)] | ||
private static void OnInit() | ||
=> RoundEvents.OnRoundRestarted += OnRoundRestart; | ||
#endregion | ||
|
||
public override string Command { get; } = "image"; | ||
public override string Description { get; } = "Commands for spawning images via primitive objects."; | ||
|
||
public override void LoadGeneratedCommands() | ||
{ | ||
base.LoadGeneratedCommands(); | ||
|
||
RegisterCommand(new DestroyCommand()); | ||
RegisterCommand(new LoopCommand()); | ||
RegisterCommand(new PauseCommand()); | ||
RegisterCommand(new PlayCommand()); | ||
RegisterCommand(new SpawnCommand()); | ||
RegisterCommand(new StopCommand()); | ||
|
||
RegisterCommand(new Parent.ParentCommand()); | ||
} | ||
} |
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,36 @@ | ||
using LabExtended.Commands; | ||
using LabExtended.Commands.Arguments; | ||
using LabExtended.Commands.Interfaces; | ||
|
||
namespace LabExtended.API.CustomCommands.Image.Loop; | ||
|
||
public class LoopCommand : CustomCommand | ||
{ | ||
public override string Command { get; } = "loop"; | ||
public override string Description { get; } = "Toggles image looping."; | ||
|
||
public override ArgumentDefinition[] BuildArgs() | ||
{ | ||
return GetArg<int>("ID", "ID of the image to loop"); | ||
} | ||
|
||
public override void OnCommand(ExPlayer sender, ICommandContext ctx, ArgumentCollection args) | ||
{ | ||
base.OnCommand(sender, ctx, args); | ||
|
||
var id = args.Get<int>("ID"); | ||
|
||
if (!ImageCommand.SpawnedImages.TryGetValue(id, out var image)) | ||
{ | ||
ctx.RespondFail($"No image with ID {id}"); | ||
return; | ||
} | ||
|
||
image.IsLooping = !image.IsLooping; | ||
|
||
if (image.IsLooping) | ||
ctx.RespondOk($"Looping enabled."); | ||
else | ||
ctx.RespondOk($"Looping disabled."); | ||
} | ||
} |
Oops, something went wrong.