瀏覽代碼

Actions for modifying a deck

crobi 9 年之前
父節點
當前提交
da04fd2fbd
共有 3 個文件被更改,包括 47 次插入2 次删除
  1. 16
    0
      client/src/actions/actions.ts
  2. 21
    2
      client/src/app.ts
  3. 10
    0
      client/src/stores/store.ts

+ 16
- 0
client/src/actions/actions.ts 查看文件

@@ -10,6 +10,16 @@ module rpgcards {
10 10
     export class ActionNewDeck implements Action {
11 11
         constructor() {}
12 12
     }
13
+    export class ActionSetDeckName implements Action {
14
+        constructor(private _id: string, private _name:string) {}
15
+        get id(): string {return this._id}
16
+        get name(): string {return this._name}
17
+    }
18
+    export class ActionSetDeckDescription implements Action {
19
+        constructor(private _id: string, private _desc:string) {}
20
+        get id(): string {return this._id}
21
+        get desc(): string {return this._desc}
22
+    }
13 23
     export class ActionDeleteDeck implements Action {
14 24
         constructor(private _id: string) {}
15 25
         get id(): string {return this._id}
@@ -48,6 +58,12 @@ module rpgcards {
48 58
         public newDeck(): void {
49 59
             this._dispatcher.dispatch(new ActionNewDeck());
50 60
         }
61
+        public setDeckName(id:string, name:string): void {
62
+            this._dispatcher.dispatch(new ActionSetDeckName(id, name));
63
+        }
64
+        public setDeckDesc(id:string, desc:string): void {
65
+            this._dispatcher.dispatch(new ActionSetDeckDescription(id, desc));
66
+        }
51 67
         public deleteDeck(id: string): void {
52 68
             this._dispatcher.dispatch(new ActionDeleteDeck(id));
53 69
         }

+ 21
- 2
client/src/app.ts 查看文件

@@ -53,13 +53,32 @@ module rpgcards {
53 53
             + " and then triggers a series of hardcoded user actions,"
54 54
             + " in order to set up some application state that can be used"
55 55
             + " for testing");
56
+        var withDeckId = (i: number, fn: (deckId: string)=>void) => {
57
+            appStore.getDeckList().lift(ids => fn(ids[i]));
58
+        }
56 59
         appActions.reset();
60
+
61
+        // Deck 1
57 62
         appActions.newDeck();
58
-        appStore.getDeckList().lift(deckIds => appActions.newCard(deckIds[0]));
59
-        appStore.getDeckList().lift(deckIds => appActions.newCard(deckIds[0]));
63
+        withDeckId(0, id=>appActions.setDeckName(id, "Spells"));
64
+        withDeckId(0, id=>appActions.setDeckDesc(id, "This deck contains"
65
+            + " basic spells."));
66
+        withDeckId(0, id=>appActions.newCard(id));
67
+        withDeckId(0, id=>appActions.newCard(id));
68
+        withDeckId(0, id=>appActions.newCard(id));
69
+
70
+        // Deck 2
60 71
         appActions.newDeck();
72
+        withDeckId(1, id=>appActions.setDeckName(id, "Items"));
73
+        withDeckId(1, id=>appActions.setDeckDesc(id, "This deck contains"
74
+            + " mundane and magic items."));
61 75
         appStore.getDeckList().lift(deckIds => appActions.newCard(deckIds[1]));
76
+
77
+        // Deck 3
62 78
         appActions.newDeck();
79
+        withDeckId(2, id=>appActions.setDeckName(id, "Creatures"));
80
+        withDeckId(2, id=>appActions.setDeckDesc(id, "This deck contains"
81
+            + " creatures."));
63 82
     }
64 83
 
65 84
 }

+ 10
- 0
client/src/stores/store.ts 查看文件

@@ -36,6 +36,12 @@ module rpgcards {
36 36
                     this._newDeck()
37 37
                 } else if (action instanceof ActionDeleteDeck) {
38 38
                     this._deleteDeck(action.id);
39
+                } else if (action instanceof ActionSetDeckName) {
40
+                    this._modifyDeck(action.id, (deck)=>{
41
+                        deck.name = action.name});
42
+                } else if (action instanceof ActionSetDeckDescription) {
43
+                    this._modifyDeck(action.id, (deck)=>{
44
+                        deck.description = action.desc});
39 45
                 } else if (action instanceof ActionSelectDeck) {
40 46
                     this._selectDeck(action.id);
41 47
                 } else if (action instanceof ActionNewCard) {
@@ -106,6 +112,10 @@ module rpgcards {
106 112
             this._selectedDeck = id;
107 113
         }
108 114
 
115
+        private _modifyDeck(id: string, fn: (deck: Deck)=>void): void {
116
+            this.getDeck(id).lift(deck => fn(deck));
117
+        }
118
+
109 119
         private _newCard(deckId: string): void {
110 120
             this.getDeck(deckId)
111 121
                 .lift(deck => {

Loading…
取消
儲存