From 06a269f277a3b949cda7d7b5c33fb8ee89ea08b5 Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Thu, 17 Aug 2023 10:28:30 -0400 Subject: [PATCH] rewrite constructor of VmcExtVrm --- VmcMessages/VmcExtVrm.cs | 61 ++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/VmcMessages/VmcExtVrm.cs b/VmcMessages/VmcExtVrm.cs index 60a2100..850c59f 100644 --- a/VmcMessages/VmcExtVrm.cs +++ b/VmcMessages/VmcExtVrm.cs @@ -29,33 +29,44 @@ namespace godotVmcSharp public VmcExtVrm(godotOscSharp.OscMessage m) : base(m.Address) { - if (m.Data.Count < 2 || m.Data.Count > 3) + switch (m.Data.Count) { - GD.Print($"Invalid number of arguments for {addr} message. Expected 2 or 3 but received {m.Data.Count}"); - return; + case 2: + if (m.Data[0].Type != 's') + { + GD.Print(InvalidArgumentType.GetErrorString(addr, "path", 's', m.Data[0].Type)); + return; + } + if (m.Data[1].Type != 's') + { + GD.Print(InvalidArgumentType.GetErrorString(addr, "title", 's', m.Data[1].Type)); + return; + } + path = (string)m.Data[0].Value; + title = (string)m.Data[1].Value; + case 3: + if (m.Data[0].Type != 's') + { + GD.Print(InvalidArgumentType.GetErrorString(addr, "path", 's', m.Data[0].Type)); + return; + } + if (m.Data[1].Type != 's') + { + GD.Print(InvalidArgumentType.GetErrorString(addr, "title", 's', m.Data[1].Type)); + return; + } + if (m.Data[2].Type != 's') + { + GD.Print(InvalidArgumentType.GetErrorString(addr, "hash", 's', m.Data[1].Type)); + return; + } + path = (string)m.Data[0].Value; + title = (string)m.Data[1].Value; + hash = (string)m.Data[2].Value; + default: + GD.Print($"Invalid number of arguments for {addr} message. Expected 2 or 3 but received {m.Data.Count}"); + return; } - if (m.Data[0].Type != 's') - { - GD.Print(InvalidArgumentType.GetErrorString(addr, "path", 's', m.Data[0].Type)); - return; - } - if (m.Data[1].Type != 's') - { - GD.Print(InvalidArgumentType.GetErrorString(addr, "title", 's', m.Data[1].Type)); - return; - } - path = (string)m.Data[0].Value; - title = (string)m.Data[1].Value; - if (m.Data.Count != 3) - { - return; - } - if (m.Data[2].Type != 's') - { - GD.Print(InvalidArgumentType.GetErrorString(addr, "hash", 's', m.Data[1].Type)); - return; - } - hash = (string)m.Data[2].Value; } } } \ No newline at end of file