Skip to content

Commit

Permalink
A few extra convenience conversions when switch apl value type
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyt857 committed Aug 20, 2023
1 parent c8d23b1 commit c4f198f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ui/core/components/individual_sim_ui/apl_values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,28 @@ export class APLValuePicker extends Input<Player<any>, APLValue | undefined> {
} else {
(newSourceValue.value as APLValueImplStruct<'or'>).or.vals = [this.makeAPLValue(oldKind, this.valuePicker.getInputValue())];
}
} else if (newKind == 'min') {
if (sourceValue.value.oneofKind == 'max') {
(newSourceValue.value as APLValueImplStruct<'min'>).min.vals = sourceValue.value.max.vals;
} else {
(newSourceValue.value as APLValueImplStruct<'min'>).min.vals = [this.makeAPLValue(oldKind, this.valuePicker.getInputValue())];
}
} else if (newKind == 'max') {
if (sourceValue.value.oneofKind == 'min') {
(newSourceValue.value as APLValueImplStruct<'max'>).max.vals = sourceValue.value.min.vals;
} else {
(newSourceValue.value as APLValueImplStruct<'max'>).max.vals = [this.makeAPLValue(oldKind, this.valuePicker.getInputValue())];
}
} else if (sourceValue.value.oneofKind == 'and' && sourceValue.value.and.vals?.[0]?.value.oneofKind == newKind) {
newSourceValue = sourceValue.value.and.vals[0];
} else if (sourceValue.value.oneofKind == 'or' && sourceValue.value.or.vals?.[0]?.value.oneofKind == newKind) {
newSourceValue = sourceValue.value.or.vals[0];
} else if (sourceValue.value.oneofKind == 'min' && sourceValue.value.min.vals?.[0]?.value.oneofKind == newKind) {
newSourceValue = sourceValue.value.min.vals[0];
} else if (sourceValue.value.oneofKind == 'max' && sourceValue.value.max.vals?.[0]?.value.oneofKind == newKind) {
newSourceValue = sourceValue.value.max.vals[0];
} else if (newKind == 'cmp') {
(newSourceValue.value as APLValueImplStruct<'cmp'>).cmp.lhs = this.makeAPLValue(oldKind, this.valuePicker.getInputValue());
}
}
}
Expand Down

0 comments on commit c4f198f

Please sign in to comment.