Exemplo n.º 1
0
 public void rebase(CampaignState state)
 {
     foreach (EntryAction action in this.actions)
     {
         action.rebase(state);
     }
 }
Exemplo n.º 2
0
        public override void revert(CampaignState state, Entry ent)
        {
            if (!state.events.events.ContainsKey(this.guid))
            {
                throw new ArgumentOutOfRangeException();
            }
            CalendarEvent evt = state.events.events[this.guid];

            if (this.set_timestamp)
            {
                evt.timestamp = this.from.timestamp;
            }
            if (this.set_name)
            {
                evt.name = this.from.name;
            }
            if (this.set_desc)
            {
                evt.description = this.from.description;
            }
            if (this.set_interval)
            {
                evt.interval = this.from.interval;
            }
        }
Exemplo n.º 3
0
 public override void apply(CampaignState state, Entry ent)
 {
     if (this.from is null)
     {
         // add new character
         if (this.restore)
         {
             state.characters.restore_character(this.guid);
         }
         else
         {
             state.characters.add_character(this.to.copy(), this.guid);
         }
     }
     else if (this.to is null)
     {
         // remove existing character
         state.characters.remove_character(this.guid);
     }
     else
     {
         // update existing character to new value
         state.characters.characters[this.guid] = this.to.copy();
     }
 }
Exemplo n.º 4
0
        public override void revert(CampaignState state, Entry ent)
        {
            if (!state.notes.notes.ContainsKey(this.guid))
            {
                throw new ArgumentOutOfRangeException();
            }
            Note note = state.notes.notes[this.guid];

            if (this.contents_from is not null)
            {
                note.contents = this.contents_from;
            }
            if (this.adjust_topics is not null)
            {
                foreach (Guid topic in this.adjust_topics.Keys)
                {
                    if (this.adjust_topics[topic] < 0)
                    {
                        note.topics.Add(topic, -this.adjust_topics[topic]);
                    }
                    else
                    {
                        note.topics.RemoveRef(topic);
                    }
                }
            }
        }
Exemplo n.º 5
0
        public override void revert(CampaignState state, Entry ent)
        {
            if (!state.tasks.tasks.ContainsKey(this.guid))
            {
                throw new ArgumentOutOfRangeException();
            }
            Task task = state.tasks.tasks[this.guid];

            if (this.set_name)
            {
                task.name = this.from.name;
            }
            if (this.set_desc)
            {
                task.description = this.from.description;
            }
            if (this.set_completed)
            {
                task.completed_guid = this.from.completed_guid;
            }
            if (this.set_failed)
            {
                task.failed = this.from.failed;
            }
            if (this.set_due)
            {
                task.due = this.from.due;
            }
        }
Exemplo n.º 6
0
        public override void rebase(CampaignState state)
        {
            if (!state.notes.notes.ContainsKey(this.guid))
            {
                throw new ArgumentOutOfRangeException();
            }
            Note note = state.notes.notes[this.guid];

            if (this.contents_from is not null)
            {
                this.contents_from = note.contents;
            }
            if (this.adjust_topics is not null)
            {
                foreach (Guid topic in this.adjust_topics.Keys)
                {
                    if (this.adjust_topics[topic] < 0)
                    {
                        if (note.topics.Contains(topic))
                        {
                            this.adjust_topics[topic] = -note.topics.contents[topic];
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
 public CampaignDomain()
 {
     this.state         = new CampaignState();
     this.entries       = new List <Entry>();
     this.valid_entries = 0;
     this.topics        = new Dictionary <Guid, Topic>();
     this.notes         = new Dictionary <Guid, ExternalNote>();
 }
Exemplo n.º 8
0
 public override void rebase(CampaignState state)
 {
     if (this.from is not null)
     {
         if (!state.characters.characters.ContainsKey(this.guid))
         {
             throw new ArgumentOutOfRangeException();
         }
         this.from = state.characters.characters[this.guid].copy();
     }
 }
Exemplo n.º 9
0
 public void apply(CampaignState state, int start_index = 0)
 {
     for (int i = start_index; i < this.actions.Count; i++)
     {
         try {
             this.actions[i].apply(state, this);
         }
         catch (ArgumentException e) {
             e.Data["action_index"] = i;
             throw;
         }
     }
 }
Exemplo n.º 10
0
        public CampaignState get_entry_state(int idx)
        {
            if ((idx < -1) || (idx >= this.valid_entries))
            {
                throw new ArgumentOutOfRangeException(nameof(idx));
            }
            CampaignState result = this.state.copy();

            for (int i = this.valid_entries - 1; i > idx; i--)
            {
                this.entries[i].revert(result);
            }
            return(result);
        }
Exemplo n.º 11
0
 public void revert(CampaignState state, int start_index = -1)
 {
     if (start_index < 0)
     {
         start_index = this.actions.Count - 1;
     }
     for (int i = start_index; i >= 0; i--)
     {
         try {
             this.actions[i].revert(state, this);
         }
         catch (ArgumentException e) {
             e.Data["action_index"] = i;
             throw;
         }
     }
 }
Exemplo n.º 12
0
 public override void revert(CampaignState state, Entry ent)
 {
     if (this.from is null)
     {
         // revert addition of new character
         state.characters.remove_character(this.guid);
         if (!this.restore)
         {
             // if we're not reverting a restore, purge "deleted" copy of character too
             state.characters.characters.Remove(this.guid);
         }
     }
     else if (this.to is null)
     {
         // revert removal of existing character
         state.characters.restore_character(this.guid);
     }
     else
     {
         // revert update of existing character to new value
         state.characters.characters[this.guid] = this.from.copy();
     }
 }
Exemplo n.º 13
0
        public ItemAddWindow(CampaignSave save_state, CampaignState state, Guid?guid = null, InventoryItemIdent selected = null, InventoryEntry entry = null)
        {
            this.valid               = false;
            this.need_refresh        = false;
            this.state               = save_state;
            this.entry               = entry;
            this.item                = entry?.item;
            this.inventory_rows      = new ObservableCollection <InventoryItemBaseRow>();
            this.inventory_row_index = new Dictionary <InventoryItemIdent, InventoryItemRow>();
            this.inventory_capacity  = new Dictionary <InventoryItemIdent, decimal>();
            this.populate_inventories(state, guid, selected);
            InitializeComponent();
            Visibility item_visibility = (guid is null ? Visibility.Collapsed : Visibility.Visible);

            this.item_label.Visibility         = item_visibility;
            this.item_box.Visibility           = item_visibility;
            this.item_set_but.Visibility       = item_visibility;
            this.count_label.Visibility        = item_visibility;
            this.count_box.Visibility          = item_visibility;
            this.unidentified_label.Visibility = item_visibility;
            this.unidentified_box.Visibility   = item_visibility;
            this.inventory_list.ItemsSource    = this.inventory_rows;
        }
Exemplo n.º 14
0
        private void populate_inventories(CampaignState state, Guid?guid, InventoryItemIdent selected)
        {
            this.inventory_rows.Add(new InventoryItemHeaderRow());
            List <Guid> invs;

            if (guid is null)
            {
                invs = new List <Guid>(state.inventories.inventories.Keys);
            }
            else
            {
                invs = new List <Guid>()
                {
                    guid.Value
                };
            }
            invs.Sort((x, y) => state.inventories.inventories[x].name.CompareTo(state.inventories.inventories[x].name));
            foreach (Guid inv_guid in invs)
            {
                InventoryItemIdent inv_ident = new InventoryItemIdent(inv_guid);
                InventoryItemRow   inv_row   = new InventoryItemRow(
                    null, inv_ident, state.inventories.inventories[inv_guid].name, "", "", new ObservableCollection <InventoryItemBaseRow>()
                    );
                bool found_selected = this.populate_inventory_rows(inv_row.children, inv_ident, state.inventories.inventories[inv_guid], selected);
                if (inv_ident == selected)
                {
                    inv_row._is_selected = true;
                }
                else if (found_selected)
                {
                    inv_row._is_expanded = true;
                }
                this.inventory_rows.Add(inv_row);
                this.inventory_row_index[inv_ident] = inv_row;
            }
        }
Exemplo n.º 15
0
 public virtual void rebase(CampaignState state)
 {
 }
Exemplo n.º 16
0
 public override void revert(CampaignState state, Entry ent)
 {
     state.notes.restore_note(this.guid);
 }
Exemplo n.º 17
0
 public virtual Window character_window(CampaignState state, Guid?guid = null) => new SimpleCharacterWindow(state, guid);
Exemplo n.º 18
0
        public CalendarEventWindow(CampaignState state, Calendar calendar, decimal now, Guid?entry_guid = null, Guid?guid = null)
        {
            this.valid   = false;
            this.state   = state.copy();
            this.now     = now;
            this.actions = new List <EntryAction>();
            if (guid is null)
            {
                if (entry_guid is null)
                {
                    throw new ArgumentNullException(nameof(entry_guid));
                }
                this.guid = Guid.NewGuid();
                ActionCalendarEventCreate add_action = new ActionCalendarEventCreate(this.guid, new CalendarEvent(entry_guid.Value, now, ""));
                this.actions.Add(add_action);
                this.evt = add_action.evt;
            }
            else
            {
                this.guid = guid.Value;
                this.evt  = this.state.events.events[this.guid];
            }
            InitializeComponent();
            FrameworkElement timestamp_box = calendar.timestamp_control();

            Grid.SetRow(timestamp_box, 0);
            Grid.SetColumn(timestamp_box, 1);
            this.main_grid.Children.Add(timestamp_box);
            this.timestamp_box = timestamp_box as ICalendarControl;
            if (this.timestamp_box is null)
            {
                throw new InvalidOperationException();
            }
            this.timestamp_box.calendar_value = this.evt.timestamp;
            FrameworkElement timestamp_diff_box = calendar.interval_control();

            Grid.SetRow(timestamp_diff_box, 0);
            Grid.SetColumn(timestamp_diff_box, 3);
            this.main_grid.Children.Add(timestamp_diff_box);
            this.timestamp_diff_box = timestamp_diff_box as ICalendarControl;
            if (this.timestamp_diff_box is null)
            {
                throw new InvalidOperationException();
            }
            decimal timestamp_diff = this.evt.timestamp - now;

            if (timestamp_diff < 0)
            {
                this.timestamp_diff_label.Content = "before";
                timestamp_diff = -timestamp_diff;
            }
            else
            {
                this.timestamp_diff_label.Content = "after";
            }
            this.timestamp_diff_box.calendar_value = timestamp_diff;
            this.current_timestamp_box.Text        = calendar.format_timestamp(now);
            this.timestamp_box.value_changed       = this.timestamp_changed;
            this.timestamp_diff_box.value_changed  = this.timestamp_diff_changed;
            this.repeat_box.IsChecked = (this.evt.interval is not null);
            FrameworkElement interval_box = calendar.interval_control();

            Grid.SetRow(interval_box, 0);
            Grid.SetColumn(interval_box, 9);
            this.main_grid.Children.Add(interval_box);
            this.interval_box = interval_box as ICalendarControl;
            if (this.interval_box is null)
            {
                throw new InvalidOperationException();
            }
            this.interval_box.calendar_value = (this.evt.interval ?? 0);
            this.name_box.Text        = this.evt.name;
            this.description_box.Text = this.evt.description;
        }
Exemplo n.º 19
0
 public override void apply(CampaignState state, Entry ent)
 {
     state.notes.remove_note(this.guid);
 }
Exemplo n.º 20
0
 public override void apply(CampaignState state, Entry ent)
 {
     state.events.add_event(this.evt.copy(), this.guid);
 }
Exemplo n.º 21
0
 public override void revert(CampaignState state, Entry ent)
 {
     state.tasks.restore_task(this.guid);
 }
Exemplo n.º 22
0
 public override void apply(CampaignState state, Entry ent)
 {
     state.notes.add_note(this.note.copy(), this.guid);
 }
Exemplo n.º 23
0
 public override void apply(CampaignState state, Entry ent)
 {
     state.events.remove_event(this.guid);
 }
Exemplo n.º 24
0
 public override void apply(CampaignState state, Entry ent)
 {
     state.tasks.add_task(this.task.copy(), this.guid);
 }
Exemplo n.º 25
0
        public EntryWindow(CampaignSave save_state, int entry = -1, List <EntryAction> actions = null)
        {
            this.valid      = false;
            this.save_state = save_state;
            this.entry      = entry;
            this.entries    = new List <Entry>();
            for (int i = 0; i < save_state.domain.entries.Count; i++)
            {
                if (i != entry)
                {
                    this.entries.Add(save_state.domain.entries[i]);
                }
            }
            if ((entry >= 0) && (entry < save_state.domain.valid_entries))
            {
                this.state = save_state.domain.get_entry_state(entry);
            }
            else
            {
                this.state = save_state.domain.state.copy();
            }
            Entry previous_entry = null, current_entry;

            if ((entry >= 0) && (entry < save_state.domain.entries.Count))
            {
                current_entry = save_state.domain.entries[entry];
                if (entry > 0)
                {
                    this.previous_entry_idx = entry - 1;
                    previous_entry          = this.entries[entry - 1];
                }
            }
            else
            {
                decimal timestamp;
                int     session;
                if (save_state.domain.valid_entries > 0)
                {
                    this.previous_entry_idx = save_state.domain.valid_entries - 1;
                    previous_entry          = this.entries[this.previous_entry_idx];
                    timestamp = previous_entry.timestamp + 1;
                }
                else
                {
                    timestamp = save_state.calendar.default_timestamp;
                }
                session = previous_entry?.session ?? 1;
                if ((previous_entry is not null) && ((DateTime.Now - previous_entry.created) >= SESSION_DOWNTIME_THRESHOLD))
                {
                    session += 1;
                }
                current_entry = new Entry(timestamp, DateTime.Now, "", session, actions);
                if (actions is not null)
                {
                    foreach (EntryAction action in actions)
                    {
                        action.apply(this.state, current_entry);
                    }
                }
            }
            this.actions = new List <EntryAction>();
            this.add_actions(current_entry.actions, false);
            InitializeComponent();
            this.session_box.textBox.VerticalContentAlignment = VerticalAlignment.Center;
            this.session_box.Value = current_entry.session ?? 0;
            this.created_time_box.textBox.VerticalContentAlignment = VerticalAlignment.Center;
            this.created_time_box.Pattern      = CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern;
            this.created_date_box.SelectedDate = current_entry.created.Date;
            this.created_time_box.Value        = current_entry.created.TimeOfDay.TotalSeconds;
            FrameworkElement timestamp_box = save_state.calendar.timestamp_control();

            Grid.SetRow(timestamp_box, 0);
            Grid.SetColumn(timestamp_box, 6);
            this.header_grid.Children.Add(timestamp_box);
            this.timestamp_box = timestamp_box as ICalendarControl;
            if (this.timestamp_box is null)
            {
                throw new InvalidOperationException();
            }
            this.timestamp_box.calendar_value = current_entry.timestamp;
            FrameworkElement timestamp_diff_box = save_state.calendar.interval_control();

            Grid.SetRow(timestamp_diff_box, 0);
            Grid.SetColumn(timestamp_diff_box, 8);
            this.header_grid.Children.Add(timestamp_diff_box);
            this.timestamp_diff_box = timestamp_diff_box as ICalendarControl;
            if (this.timestamp_diff_box is null)
            {
                throw new InvalidOperationException();
            }
            this.timestamp_diff_box.calendar_value = (previous_entry is null ? 0 : current_entry.timestamp - previous_entry.timestamp);
            this.timestamp_box.value_changed       = this.timestamp_changed;
            this.timestamp_diff_box.value_changed  = this.timestamp_diff_changed;
            this.previous_entry_box.Text           = (previous_entry is null ? "n/a" : save_state.calendar.format_timestamp(previous_entry.timestamp));
            this.description_box.Text    = current_entry.description;
            this.action_list.ItemsSource = this.actions;
            this.event_list = new CalendarEventListControl(this.entry_action_callback, current_entry.guid);
            this.event_list.set_calendar(this.save_state.calendar);
            this.event_list.set_state(this.state, current_entry.timestamp);
            this.event_group.Content = this.event_list;
            this.character_list      = new CharacterListControl(this.entry_action_callback);
            this.character_list.set_char_sheet(this.save_state.character_sheet);
            this.character_list.set_state(this.state);
            this.character_group.Content = this.character_list;
            this.inventory_list          = new InventoryListControl(this.entry_action_callback);
            this.inventory_list.set_state(this.save_state, this.state);
            this.inventory_group.Content = this.inventory_list;
            this.topic_list = new TopicListControl(this.entry_action_callback, current_entry.guid);
            this.topic_list.set_state(this.save_state, this.state, current_entry.timestamp);
            this.topic_group.Content = this.topic_list;
            this.task_list           = new TaskListControl(this.entry_action_callback, current_entry.guid);
            this.task_list.set_calendar(this.save_state.calendar);
            this.task_list.set_state(this.save_state, this.state, current_entry.timestamp);
            this.task_group.Content = this.task_list;
        }
Exemplo n.º 26
0
 public abstract void apply(CampaignState state, Entry ent);
Exemplo n.º 27
0
 public abstract void revert(CampaignState state, Entry ent);
Exemplo n.º 28
0
 public TaskWindow(CampaignSave save_state, CampaignState state, Calendar calendar, decimal now, Guid?entry_guid = null, Guid?guid = null)
 {
     this.valid      = false;
     this.save_state = save_state;
     this.state      = state.copy();
     this.now        = now;
     this.actions    = new List <EntryAction>();
     if (guid is null)
     {
         if (entry_guid is null)
         {
             throw new ArgumentNullException(nameof(entry_guid));
         }
         this.guid = Guid.NewGuid();
         ActionTaskCreate add_action = new ActionTaskCreate(this.guid, new Task(entry_guid.Value, ""));
         this.actions.Add(add_action);
         this.task = add_action.task;
     }
     else
     {
         this.guid = guid.Value;
         this.task = this.state.tasks.tasks[this.guid];
     }
     InitializeComponent();
     this.name_box.Text              = this.task.name;
     this.description_box.Text       = this.task.description;
     this.current_timestamp_box.Text = calendar.format_timestamp(now);
     if (this.task.completed_guid is null)
     {
         FrameworkElement due_box = calendar.timestamp_control();
         Grid.SetRow(due_box, 2);
         Grid.SetColumn(due_box, 1);
         this.main_grid.Children.Add(due_box);
         this.due_box = due_box as ICalendarControl;
         if (this.due_box is null)
         {
             throw new InvalidOperationException();
         }
         FrameworkElement due_diff_box = calendar.interval_control();
         Grid.SetRow(due_diff_box, 2);
         Grid.SetColumn(due_diff_box, 3);
         this.main_grid.Children.Add(due_diff_box);
         this.due_diff_box = due_diff_box as ICalendarControl;
         if (this.due_diff_box is null)
         {
             throw new InvalidOperationException();
         }
         if (this.task.due is null)
         {
             this.due_checkbox.IsChecked      = false;
             this.due_box.calendar_value      = now;
             this.due_box.IsReadOnly          = true;
             this.due_diff_box.calendar_value = 0;
             this.due_diff_box.IsReadOnly     = true;
         }
         else
         {
             this.due_checkbox.IsChecked = true;
             this.due_box.calendar_value = this.task.due.Value;
             this.due_box.IsReadOnly     = false;
             decimal due_diff = this.task.due.Value - now;
             if (due_diff < 0)
             {
                 this.timestamp_diff_label.Content = "before";
                 due_diff = -due_diff;
             }
             else
             {
                 this.timestamp_diff_label.Content = "after";
             }
             this.due_diff_box.calendar_value = due_diff;
             this.due_diff_box.IsReadOnly     = false;
         }
         this.due_box.value_changed      = this.due_changed;
         this.due_diff_box.value_changed = this.due_diff_changed;
     }
     else
     {
         decimal?completed_timestamp = null;
         if (task.completed_guid == entry_guid)
         {
             completed_timestamp = now;
         }
         else
         {
             foreach (Entry entry in this.save_state.domain.entries)
             {
                 if (entry.guid == task.completed_guid)
                 {
                     completed_timestamp = entry.timestamp;
                     break;
                 }
             }
         }
         if (completed_timestamp is null)
         {
             throw new InvalidOperationException();
         }
         if (this.task.failed)
         {
             this.status_label.Content = "Failed:";
         }
         else
         {
             this.status_label.Content = "Completed:";
         }
         this.status_label.Visibility  = Visibility.Visible;
         this.due_checkbox.Visibility  = Visibility.Collapsed;
         this.timestamp_box.Text       = calendar.format_timestamp(completed_timestamp.Value);
         this.timestamp_box.Visibility = Visibility.Visible;
         decimal timestamp_diff = completed_timestamp.Value - now;
         if (timestamp_diff < 0)
         {
             this.timestamp_diff_label.Content = "before";
             timestamp_diff = -timestamp_diff;
         }
         else
         {
             this.timestamp_diff_label.Content = "after";
         }
         this.timestamp_diff_box.Text       = calendar.format_interval(timestamp_diff);
         this.timestamp_diff_box.Visibility = Visibility.Visible;
     }
 }
Exemplo n.º 29
0
 public override void apply(CampaignState state, Entry ent)
 {
     state.tasks.remove_task(this.guid);
 }
Exemplo n.º 30
0
 public override void revert(CampaignState state, Entry ent)
 {
     state.events.restore_event(this.guid);
 }