Example #1
0
 /// <summary>
 /// Revert this change from the specified state.
 /// </summary>
 /// <param name="state">The state from which to revert the change</param>
 /// <exception cref="InvalidState">The change cannot be reverted from the state</exception>
 public void revertFromState(State state)
 {
     // first revert all the removals
     foreach (KeyValuePair <string, Dictionary <Guid, StateAspectRemove> > changeDict in this.removals)
     {
         StateAspectStore store = state.getStore(changeDict.Key);
         foreach (KeyValuePair <Guid, StateAspectRemove> stateChange in changeDict.Value)
         {
             stateChange.Value.revertFromStore(store);
         }
     }
     // then revert all the updates
     foreach (KeyValuePair <string, Dictionary <Guid, StateAspectUpdate> > changeDict in this.updates)
     {
         StateAspectStore store = state.getStore(changeDict.Key);
         foreach (KeyValuePair <Guid, StateAspectUpdate> stateChange in changeDict.Value)
         {
             stateChange.Value.revertFromStore(store);
         }
     }
     // then revert all the additions
     foreach (KeyValuePair <string, Dictionary <Guid, StateAspectAdd> > changeDict in this.additions)
     {
         StateAspectStore store = state.getStore(changeDict.Key);
         foreach (KeyValuePair <Guid, StateAspectAdd> stateChange in changeDict.Value)
         {
             stateChange.Value.revertFromStore(store);
         }
     }
     // finally do any necessary cross-store validation
 }
Example #2
0
 public override void applyToStore(StateAspectStore store)
 {
     if ((store.aspects.ContainsKey(this.aspect_id)) || (store.removed_aspects.ContainsKey(this.aspect_id)))
     {
         throw new InvalidState("Cannot add aspect that already exists.");
     }
     store.aspects[this.aspect_id] = this.aspect.copy();
     foreach (string tag in aspect.tags)
     {
         if (!store.tag_index.ContainsKey(tag))
         {
             store.tag_index[tag] = new HashSet <Guid>();
         }
         store.tag_index[tag].Add(this.aspect_id);
     }
 }
Example #3
0
 public override void revertFromStore(StateAspectStore store)
 {
     if ((store.aspects.ContainsKey(this.aspect_id)) || (!store.removed_aspects.ContainsKey(this.aspect_id)))
     {
         throw new InvalidState("Cannot revert removing aspect that hasn't been removed.");
     }
     store.aspects[this.aspect_id] = store.removed_aspects[this.aspect_id];
     store.removed_aspects.Remove(this.aspect_id);
     foreach (string tag in store.aspects[this.aspect_id].tags)
     {
         if (!store.tag_index.ContainsKey(tag))
         {
             store.tag_index[tag] = new HashSet <Guid>();
         }
         store.tag_index[tag].Add(this.aspect_id);
     }
 }
Example #4
0
        public StateAspectStore copy()
        {
            StateAspectStore store = new StateAspectStore();

            foreach (KeyValuePair <Guid, StateAspect> aspect in this.aspects)
            {
                store.aspects[aspect.Key] = aspect.Value.copy();
            }
            foreach (KeyValuePair <string, HashSet <Guid> > tag in this.tag_index)
            {
                store.tag_index[tag.Key] = new HashSet <Guid>(tag.Value);
            }
            foreach (KeyValuePair <Guid, StateAspect> aspect in this.removed_aspects)
            {
                store.removed_aspects[aspect.Key] = aspect.Value.copy();
            }
            return(store);
        }
Example #5
0
 public override void revertFromStore(StateAspectStore store)
 {
     if (!store.aspects.ContainsKey(this.aspect_id))
     {
         throw new InvalidState("Cannot revert adding aspect that doesn't exist.");
     }
     foreach (string tag in store.aspects[this.aspect_id].tags)
     {
         if ((!store.tag_index.ContainsKey(tag)) || (!store.tag_index[tag].Contains(this.aspect_id)))
         {
             // we shouldn't get here, but a missing tag shouldn't prevent a revert
             continue;
         }
         store.tag_index[tag].Remove(this.aspect_id);
         if (store.tag_index[tag].Count <= 0)
         {
             store.tag_index.Remove(tag);
         }
     }
     store.aspects.Remove(this.aspect_id);
 }
Example #6
0
        //quests
        //characters
        //inventory

        public State()
        {
            this.notes = new StateAspectStore();
        }
Example #7
0
 /// <summary>
 /// Revert this change from the specified store.
 /// </summary>
 /// <param name="store">The store from which to revert the change</param>
 /// <exception cref="InvalidState">The change cannot be reverted from the store</exception>
 public abstract void revertFromStore(StateAspectStore store);
Example #8
0
 /// <summary>
 /// Apply this change to the specified store.
 /// </summary>
 /// <param name="store">The store to which to apply the change</param>
 /// <exception cref="InvalidState">The change cannot be applied to the store</exception>
 public abstract void applyToStore(StateAspectStore store);
Example #9
0
 public override void revertFromStore(StateAspectStore store)
 {
     //TODO
 }
Example #10
0
 public override void applyToStore(StateAspectStore store)
 {
     //TODO
 }