NAP
calendarcomponent.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // Local includes
8 #include "calendar.h"
9 #include "calendarevent.h"
10 
11 // External Includes
12 #include <component.h>
13 #include <nap/timer.h>
14 #include <map>
15 #include <nap/signalslot.h>
16 
17 namespace nap
18 {
19  class CalendarComponentInstance;
20 
25  class NAPAPI CalendarComponent : public Component
26  {
27  RTTI_ENABLE(Component)
29  public:
30  float mFrequency = 1.0f;
31  nap::ResourcePtr<ICalendar> mCalendar = nullptr;
32  };
33 
34 
45  {
46  RTTI_ENABLE(ComponentInstance)
47  public:
49  ComponentInstance(entity, resource) { }
50 
56  virtual bool init(utility::ErrorState& errorState) override;
57 
63  virtual void update(double deltaTime) override;
64 
69  void setDirty() { mDirty = true; }
70 
74  const nap::ICalendar& getCalendar() const { assert(mCalendar != nullptr); return *mCalendar; }
75 
79  nap::ICalendar& getCalendar() { assert(mCalendar != nullptr); return *mCalendar; }
80 
98  bool active(const std::string& itemID) const;
99 
102 
103  private:
104  nap::ICalendar* mCalendar = nullptr;
105  float mInterval = 1.0f;
106  double mTime = 0.0;
107  std::unordered_set<std::string> mActive;
108  OwnedCalendarItemList mDeletedItems;
109  bool mDirty = true;
110 
115  void onItemAdded(const CalendarItem& item) { mDirty = true; }
116  nap::Slot<const CalendarItem&> mItemAdded = { this, &CalendarComponentInstance::onItemAdded };
117 
122  void onItemRemoved(const CalendarItem& item);
123  nap::Slot<const CalendarItem&> mItemRemoved = { this, &CalendarComponentInstance::onItemRemoved };
124  };
125 }
nap::CalendarComponentInstance::eventEnded
nap::Signal< const CalendarEvent & > eventEnded
Triggered when a calendar event ends, always on the main thread on update()
Definition: calendarcomponent.h:101
nap::OwnedCalendarItemList
std::vector< std::unique_ptr< CalendarItem > > OwnedCalendarItemList
Definition: calendar.h:107
nap::Slot
Slot.
Definition: signalslot.h:21
nap::rtti::ObjectPtr
Definition: objectptr.h:154
nap::CalendarComponentInstance::setDirty
void setDirty()
Definition: calendarcomponent.h:69
nap::utility::ErrorState
Definition: errorstate.h:19
nap::CalendarComponentInstance::eventStarted
nap::Signal< const CalendarEvent & > eventStarted
Triggered when a calendar event starts, always on the main thread on update()
Definition: calendarcomponent.h:100
nap::CalendarComponentInstance
Definition: calendarcomponent.h:44
nap::ICalendar
Definition: calendar.h:30
nap::Signal
Definition: signalslot.h:28
nap::CalendarComponentInstance::getCalendar
nap::ICalendar & getCalendar()
Definition: calendarcomponent.h:79
nap::EntityInstance
Definition: entity.h:34
nap::CalendarItem
Definition: calendaritem.h:22
nap::ComponentInstance
Definition: component.h:43
nap::Component
Definition: component.h:151
nap::CalendarComponent
Definition: calendarcomponent.h:25
nap
Definition: templateapp.h:17
nap::CalendarComponentInstance::getCalendar
const nap::ICalendar & getCalendar() const
Definition: calendarcomponent.h:74
nap::CalendarComponentInstance::CalendarComponentInstance
CalendarComponentInstance(EntityInstance &entity, Component &resource)
Definition: calendarcomponent.h:48