diff --git a/message.go b/message.go index 8cb9ef1..3eefb2c 100644 --- a/message.go +++ b/message.go @@ -218,6 +218,58 @@ func HandleMessages(_ *astilectron.Window, m bootstrap.MessageIn) (payload inter unitData.UnitFunc = unitFuncMap[unitId] unitData.SLKUnit = baseUnitMap[unitId] + missileartSplit := strings.Split(unitData.UnitFunc.Missileart.String, ",") + missilearcSplit := strings.Split(unitData.UnitFunc.Missilearc.String, ",") + missilespeedSplit := strings.Split(unitData.UnitFunc.Missilespeed.String, ",") + missilehomingSplit := strings.Split(unitData.UnitFunc.Missilehoming.String, ",") + if !unitData.UnitFunc.Missileart1.Valid { + if len(missileartSplit) > 0 && len(missileartSplit[0]) > 0 { + unitData.UnitFunc.Missileart1.SetValid(missileartSplit[0]) + } + } + + if !unitData.UnitFunc.Missileart2.Valid { + if len(missileartSplit) > 1 && len(missileartSplit[1]) > 0 { + unitData.UnitFunc.Missileart2.SetValid(missileartSplit[1]) + } + } + + if !unitData.UnitFunc.Missilearc1.Valid { + if len(missilearcSplit) > 0 && len(missilearcSplit[0]) > 0 { + unitData.UnitFunc.Missilearc1.SetValid(missilearcSplit[0]) + } + } + + if !unitData.UnitFunc.Missilearc2.Valid { + if len(missilearcSplit) > 1 && len(missilearcSplit[1]) > 0 { + unitData.UnitFunc.Missilearc2.SetValid(missilearcSplit[1]) + } + } + + if !unitData.UnitFunc.Missilespeed1.Valid { + if len(missilespeedSplit) > 0 && len(missilespeedSplit[0]) > 0 { + unitData.UnitFunc.Missilespeed1.SetValid(missilespeedSplit[0]) + } + } + + if !unitData.UnitFunc.Missilespeed2.Valid { + if len(missilespeedSplit) > 1 && len(missilespeedSplit[1]) > 0 { + unitData.UnitFunc.Missilespeed2.SetValid(missilespeedSplit[1]) + } + } + + if !unitData.UnitFunc.Missilehoming1.Valid { + if len(missilehomingSplit) > 0 && len(missilehomingSplit[0]) > 0 { + unitData.UnitFunc.Missilehoming1.SetValid(missilehomingSplit[0]) + } + } + + if !unitData.UnitFunc.Missilehoming2.Valid { + if len(missilehomingSplit) > 1 && len(missilehomingSplit[1]) > 0 { + unitData.UnitFunc.Missilehoming2.SetValid(missilehomingSplit[1]) + } + } + payload = unitData } else { payload = fmt.Errorf("invalid input") diff --git a/resources/app/static/js/index.js b/resources/app/static/js/index.js index 1e3d47b..7120a65 100644 --- a/resources/app/static/js/index.js +++ b/resources/app/static/js/index.js @@ -149,42 +149,6 @@ const index = { }) }); - if (message.payload.UnitFunc.Missileart) { - const split = message.payload.UnitFunc.Missileart.split(","); - if (split.length > 0) { - message.payload.UnitFunc.Missileart1 = split[0]; - } - if (split.length > 1) { - message.payload.UnitFunc.Missileart2 = split[1]; - } - } - if (message.payload.UnitFunc.Missilearc) { - const split = message.payload.UnitFunc.Missilearc.split(","); - if (split.length > 0) { - message.payload.UnitFunc.Missilearc1 = split[0]; - } - if (split.length > 1) { - message.payload.UnitFunc.Missilearc2 = split[1]; - } - } - if (message.payload.UnitFunc.Missilespeed) { - const split = message.payload.UnitFunc.Missilespeed.split(","); - if (split.length > 0) { - message.payload.UnitFunc.Missilespeed1 = split[0]; - } - if (split.length > 1) { - message.payload.UnitFunc.Missilespeed2 = split[1]; - } - } - if (message.payload.UnitFunc.Missilehoming) { - const split = message.payload.UnitFunc.Missilehoming.split(","); - if (split.length > 0) { - message.payload.UnitFunc.Missilehoming1 = split[0]; - } - if (split.length > 1) { - message.payload.UnitFunc.Missilehoming2 = split[1]; - } - } if (message.payload.UnitFunc.Ubertip) { const rawValue = message.payload.UnitFunc.Ubertip; const trimmedRight = rawValue.endsWith("\"") ? rawValue.substr(0, rawValue.length - 1) : rawValue; @@ -279,12 +243,15 @@ const index = { } else { const type = input.type; Field = input.id; + fieldSplit = Field.split("-"); if (type === "text" || type === "textarea" || type === "select-one") { const containsNumberRegex = new RegExp("^(?:(?:\\d*)|(?:\\d+\\.\\d+))$"); Value = input.value.replace(new RegExp("\n", "g"), "|n"); - if (!Value.match(containsNumberRegex)) { - Value = "\"" + Value + "\""; + if (fieldSplit[0] === "SLKUnit" || Field === "UnitFunc-Ubertip") { + if (!Value.match(containsNumberRegex)) { + Value = "\"" + Value + "\""; + } } } else if (type === "checkbox") { Value = input.checked ? "1" : "0";