mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-23 00:03:07 +00:00
improve Door
integer coercion, remove PreviewDoor.editable
This commit is contained in:
parent
3a4d2c1598
commit
560beb0a44
2 changed files with 12 additions and 15 deletions
|
@ -26,16 +26,11 @@ import SVGRect from "../rects/SVGRect.vue";
|
|||
},
|
||||
props: {
|
||||
door: Door,
|
||||
editable: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
},
|
||||
emits: ["update:door"],
|
||||
})
|
||||
export default class extends Vue {
|
||||
public door!: Door;
|
||||
private editable!: boolean;
|
||||
|
||||
public day_str = "";
|
||||
public editing = false;
|
||||
|
@ -74,14 +69,9 @@ export default class extends Vue {
|
|||
return result;
|
||||
}
|
||||
|
||||
private get day_num(): number {
|
||||
const result = Number(this.day_str);
|
||||
return isNaN(result) ? -1 : result;
|
||||
}
|
||||
|
||||
private toggle_editing() {
|
||||
this.day_str = String(this.door.day);
|
||||
this.editing = this.editable && !this.editing;
|
||||
this.editing = !this.editing;
|
||||
}
|
||||
|
||||
public on_click(event: MouseEvent) {
|
||||
|
@ -100,7 +90,7 @@ export default class extends Vue {
|
|||
};
|
||||
day_input_focus();
|
||||
} else {
|
||||
this.door.day = this.day_num;
|
||||
this.door.day = this.day_str;
|
||||
}
|
||||
|
||||
this.toggle_editing();
|
||||
|
@ -112,7 +102,7 @@ export default class extends Vue {
|
|||
}
|
||||
|
||||
if (event.key === "Enter") {
|
||||
this.door.day = this.day_num;
|
||||
this.door.day = this.day_str;
|
||||
this.toggle_editing();
|
||||
} else if (event.key === "Delete") {
|
||||
this.door.day = -1;
|
||||
|
|
|
@ -13,7 +13,14 @@ export class Door {
|
|||
return this._day
|
||||
}
|
||||
|
||||
public set day(day: number) {
|
||||
this._day = Math.max(Math.floor(day), -1);
|
||||
public set day(day: unknown) {
|
||||
// integer coercion
|
||||
const result = Number(day);
|
||||
|
||||
if (isNaN(result)) {
|
||||
this._day = -1;
|
||||
} else {
|
||||
this._day = Math.max(Math.floor(result), -1);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue