refactor: Macro

This commit is contained in:
Farkas József
2016-09-25 13:56:03 +02:00
parent 2aed594dd1
commit 140709e31f
4 changed files with 18 additions and 14 deletions

View File

@@ -1,8 +1,8 @@
<macro-header [macro]="macro"></macro-header>
<div class="row list-container">
<div class="col-xs-10 col-xs-offset-1 list-group">
<div class="macro-actions-container" [dragula]="'macroActions'" [dragulaModel]="macro.macroActions.elements">
<macro-item *ngFor="let macroAction of macro.macroActions.elements; let macroActionIndex = index"
<div class="macro-actions-container" [dragula]="'macroActions'" [dragulaModel]="macro.macroActions">
<macro-item *ngFor="let macroAction of macro.macroActions; let macroActionIndex = index"
[macroAction]="macroAction"
[editable]="true"
[deletable]="true"

View File

@@ -58,8 +58,8 @@ export class MacroComponent implements OnInit, OnDestroy {
}
addAction() {
this.hideOtherActionEditors(this.macro.macroActions.elements.length);
this.macro.macroActions.elements.push(undefined);
this.hideOtherActionEditors(this.macro.macroActions.length);
this.macro.macroActions.push(undefined);
}
discardChanges() {
@@ -83,12 +83,12 @@ export class MacroComponent implements OnInit, OnDestroy {
onSaveAction(macroAction: MacroAction, index: number) {
this.hasChanges = true;
this.macro.macroActions.elements[index] = macroAction;
this.macro.macroActions[index] = macroAction;
}
onDeleteAction(index: number) {
// @ todo show confirm action dialog
this.macro.macroActions.elements.splice(index, 1);
this.macro.macroActions.splice(index, 1);
this.hasChanges = true;
}

View File

@@ -5,7 +5,7 @@
<div class="macro-action-container" [class.inactive]="selectedMacroIndex === -1">
<template [ngIf]="selectedMacroIndex >= 0">
<div class="list-group">
<macro-item *ngFor="let macroAction of macros[selectedMacroIndex].macroActions.elements"
<macro-item *ngFor="let macroAction of macros[selectedMacroIndex].macroActions"
[macroAction]="macroAction">
</macro-item>
</div>

View File

@@ -1,7 +1,7 @@
import { assertUInt8 } from '../assert';
import { Serializable } from '../Serializable';
import { UhkBuffer } from '../UhkBuffer';
import { MacroActions } from './macro-action';
import { Helper as MacroActionHelper, MacroAction } from './macro-action';
export class Macro extends Serializable<Macro> {
@@ -14,7 +14,7 @@ export class Macro extends Serializable<Macro> {
name: string;
macroActions: MacroActions;
macroActions: MacroAction[];
constructor(other?: Macro) {
super();
@@ -25,7 +25,7 @@ export class Macro extends Serializable<Macro> {
this.isLooped = other.isLooped;
this.isPrivate = other.isPrivate;
this.name = other.name;
this.macroActions = new MacroActions(other.macroActions);
this.macroActions = other.macroActions.map(macroAction => MacroActionHelper.createMacroAction(macroAction));
}
_fromJsObject(jsObject: any): Macro {
@@ -33,7 +33,7 @@ export class Macro extends Serializable<Macro> {
this.isLooped = jsObject.isLooped;
this.isPrivate = jsObject.isPrivate;
this.name = jsObject.name;
this.macroActions = new MacroActions().fromJsObject(jsObject.macroActions);
this.macroActions = jsObject.macroActions.map((macroAction: any) => MacroActionHelper.createMacroAction(macroAction));
return this;
}
@@ -42,7 +42,11 @@ export class Macro extends Serializable<Macro> {
this.isLooped = buffer.readBoolean();
this.isPrivate = buffer.readBoolean();
this.name = buffer.readString();
this.macroActions = new MacroActions().fromBinary(buffer);
let macroActionsLength: number = buffer.readCompactLength();
this.macroActions = [];
for (let i = 0; i < macroActionsLength; ++i) {
this.macroActions.push(MacroActionHelper.createMacroAction(buffer));
}
return this;
}
@@ -52,7 +56,7 @@ export class Macro extends Serializable<Macro> {
isLooped: this.isLooped,
isPrivate: this.isPrivate,
name: this.name,
macroActions: this.macroActions.toJsObject()
macroActions: this.macroActions.map(macroAction => macroAction.toJsObject())
};
}
@@ -61,7 +65,7 @@ export class Macro extends Serializable<Macro> {
buffer.writeBoolean(this.isLooped);
buffer.writeBoolean(this.isPrivate);
buffer.writeString(this.name);
this.macroActions.toBinary(buffer);
buffer.writeArray(this.macroActions);
}
toString(): string {