godotVmcSharp/VmcMessages/VmcExtCon.cs

82 lines
3.1 KiB
C#
Raw Normal View History

/*
godotVmcSharp
Copyright (C) 2023 Cassandra de la Cruz-Munoz
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using Godot;
using godotOscSharp;
namespace godotVmcSharp
{
public class VmcExtCon : VmcMessage
{
2023-09-24 19:06:26 +02:00
public readonly int Active;
public readonly string Name;
public readonly int IsLeft;
public readonly int IsTouch;
public readonly int IsAxis;
public readonly Vector3 Axis;
public static VmcExtCon CreateFromMessage(OscMessage m)
{
if (m.Data.Count < 8)
{
throw new MissingArgumentsException(m.Address, "8", m.Data.Count);
}
var active = m.Data[0].GetAsInt32();
if (active < 0 || active > 2)
{
throw new DataOutOfRangeException(m.Address, 0, "active", "{0, 1, 2}", active);
}
return new VmcExtCon(active, m.Data[1].GetAsString(), m.Data[2].GetAsInt32(), m.Data[3].GetAsInt32(), m.Data[4].GetAsInt32(), new Vector3(m.Data[5].GetAsFloat(), m.Data[6].GetAsFloat(), m.Data[7].GetAsFloat()));
}
2023-08-17 01:24:53 +02:00
public static VmcExtCon CreateFromParams(int active, string name, int isLeft, int isTouch, int isAxis, Vector3 axis)
2023-08-17 01:24:53 +02:00
{
if (active < 0 || active > 2)
2023-08-17 01:24:53 +02:00
{
throw new DataOutOfRangeException("/VMC/Ext/Con", 0, "active", "{0, 1, 2}", active);
2023-08-17 01:24:53 +02:00
}
return new VmcExtCon(active, name, isLeft, isTouch, isAxis, axis);
}
private VmcExtCon(int active, string name, int isLeft, int isTouch, int isAxis, Vector3 axis) : base(new OscAddress("/VMC/Ext/Con"))
{
Active = active;
Name = name;
IsLeft = isLeft;
IsTouch = isTouch;
IsAxis = isAxis;
Axis = axis;
}
public new OscMessage ToMessage()
{
2023-08-18 00:22:27 +02:00
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{
OscArgument.CreateFromParams(Active, 'i')!,
OscArgument.CreateFromParams(Name, 's')!,
OscArgument.CreateFromParams(IsLeft, 'i')!,
OscArgument.CreateFromParams(IsTouch, 'i')!,
OscArgument.CreateFromParams(IsAxis, 'i')!,
OscArgument.CreateFromParams(Axis.X, 'i')!,
OscArgument.CreateFromParams(Axis.Y, 'i')!,
OscArgument.CreateFromParams(Axis.Z, 'i')!,
});
2023-08-17 01:24:53 +02:00
}
}
}