Skip to content

Commit

Permalink
Fixed a bug where unit Ubertip was completely broken
Browse files Browse the repository at this point in the history
  • Loading branch information
Runar Serigstad committed Apr 28, 2019
1 parent 77fd956 commit 37a554f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 38 deletions.
52 changes: 52 additions & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
43 changes: 5 additions & 38 deletions resources/app/static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 37a554f

Please sign in to comment.