mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Merge branch 'development' of https://github.com/SpoinkyNL/Artemis.git
This commit is contained in:
commit
52d30353de
@ -379,6 +379,7 @@
|
||||
<DependentUpon>GtaVView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Modules\Games\GtaV\GtaVViewModel.cs" />
|
||||
<Compile Include="Modules\Games\LightFx\Data\LightFxState.cs" />
|
||||
<Compile Include="Modules\Games\LightFx\LightFxDataModel.cs" />
|
||||
<Compile Include="Modules\Games\LightFx\LightFxModel.cs" />
|
||||
<Compile Include="Modules\Games\LightFx\LightFxSettings.cs" />
|
||||
|
||||
40
Artemis/Artemis/Modules/Games/LightFx/Data/LightFxState.cs
Normal file
40
Artemis/Artemis/Modules/Games/LightFx/Data/LightFxState.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using MoonSharp.Interpreter;
|
||||
|
||||
namespace Artemis.Modules.Games.LightFx.Data
|
||||
{
|
||||
[MoonSharpUserData]
|
||||
public class LightFxState
|
||||
{
|
||||
public Device[] devices { get; set; }
|
||||
public string game { get; set; }
|
||||
public Mask mask { get; set; }
|
||||
}
|
||||
|
||||
[MoonSharpUserData]
|
||||
public class Device
|
||||
{
|
||||
public Light[] lights { get; set; }
|
||||
}
|
||||
|
||||
[MoonSharpUserData]
|
||||
public class Mask
|
||||
{
|
||||
public Light light { get; set; }
|
||||
public int location { get; set; }
|
||||
}
|
||||
|
||||
[MoonSharpUserData]
|
||||
public class Light
|
||||
{
|
||||
public Color color { get; set; }
|
||||
}
|
||||
|
||||
[MoonSharpUserData]
|
||||
public class Color
|
||||
{
|
||||
public int brightness { get; set; }
|
||||
public int red { get; set; }
|
||||
public int green { get; set; }
|
||||
public int blue { get; set; }
|
||||
}
|
||||
}
|
||||
@ -1,15 +1,19 @@
|
||||
using Artemis.Models.Interfaces;
|
||||
using Artemis.Modules.Games.LightFx.Data;
|
||||
using MoonSharp.Interpreter;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.Modules.Games.LightFx
|
||||
{
|
||||
[MoonSharpUserData]
|
||||
public class LightFxDataModel : IDataModel
|
||||
{
|
||||
[JsonProperty(PropertyName = "lightFxState")]
|
||||
public LightFxState LightFxState { get; set; }
|
||||
|
||||
public LightFxDataModel()
|
||||
{
|
||||
|
||||
LightFxState = new LightFxState();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,16 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Artemis.DAL;
|
||||
using Artemis.Managers;
|
||||
using Artemis.Models;
|
||||
using Artemis.Profiles.Layers.Models;
|
||||
using Artemis.Utilities.DataReaders;
|
||||
using Artemis.Utilities.GameState;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.Modules.Games.LightFx
|
||||
{
|
||||
public class LightFxModel : GameModel
|
||||
{
|
||||
public LightFxModel(DeviceManager deviceManager, GameStateWebServer gameStateWebServer)
|
||||
public LightFxModel(DeviceManager deviceManager, PipeServer pipeServer)
|
||||
: base(deviceManager, SettingsProvider.Load<LightFxSettings>(), new LightFxDataModel())
|
||||
{
|
||||
Name = "LightFX";
|
||||
@ -20,20 +23,28 @@ namespace Artemis.Modules.Games.LightFx
|
||||
Initialized = false;
|
||||
|
||||
// This model can enable itself by changing its process name to the currently running Light FX game.
|
||||
gameStateWebServer.GameDataReceived += GameStateWebServerOnGameDataReceived;
|
||||
pipeServer.PipeMessage += PipeServerOnPipeMessage;
|
||||
}
|
||||
|
||||
private void GameStateWebServerOnGameDataReceived(object sender, GameDataReceivedEventArgs e)
|
||||
private void PipeServerOnPipeMessage(string msg)
|
||||
{
|
||||
var jsonString = e.Json.ToString();
|
||||
// Ensure it's Light FX JSON
|
||||
if (!jsonString.Contains("lightFxState"))
|
||||
if (!msg.Contains("lightFxState"))
|
||||
return;
|
||||
|
||||
// Deserialize and data
|
||||
try
|
||||
{
|
||||
JsonConvert.PopulateObject(msg, DataModel);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger?.Error(ex, "Failed to deserialize LightFX JSON");
|
||||
throw;
|
||||
}
|
||||
|
||||
// Setup process name
|
||||
|
||||
ProcessName = Path.GetFileNameWithoutExtension(((LightFxDataModel)DataModel).LightFxState.game);
|
||||
}
|
||||
|
||||
public int Scale { get; set; }
|
||||
|
||||
@ -20,14 +20,11 @@ LightFxState::~LightFxState()
|
||||
|
||||
json LightFxState::GetJson()
|
||||
{
|
||||
json root;
|
||||
json j;
|
||||
root["lightFxState"] = { j };
|
||||
|
||||
j["game"] = Game;
|
||||
j["mask"] = {
|
||||
{ "location", LocationMask },
|
||||
{ "light", LocationMaskLight->GetJson() }
|
||||
{"location", LocationMask},
|
||||
{"light", LocationMaskLight->GetJson()}
|
||||
};
|
||||
j["devices"] = {};
|
||||
for (LightFxDevice* device : Devices)
|
||||
@ -35,5 +32,5 @@ json LightFxState::GetJson()
|
||||
j["devices"].push_back(device->GetJson());
|
||||
}
|
||||
|
||||
return j;
|
||||
return json{{"lightFxState", j}};
|
||||
}
|
||||
|
||||
@ -80,8 +80,8 @@ FN_DECLSPEC LFX_RESULT STDCALL LFX_Update()
|
||||
Transmit(j.dump().c_str());
|
||||
|
||||
// Only bother dumping it indented if actually debugging
|
||||
if (FILELog::ReportingLevel() == logDEBUG1)
|
||||
FILE_LOG(logDEBUG1) << "JSON: " << j.dump(4);
|
||||
if (FILELog::ReportingLevel() == logDEBUG1)
|
||||
FILE_LOG(logDEBUG1) << "JSON: " << j.dump(4);
|
||||
|
||||
return LFX_SUCCESS;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user