Skip to content

Commit

Permalink
Every weekday can now be marked as impossible for each task.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brotcrunsher committed Dec 4, 2023
1 parent 490370d commit 48d0e6a
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 14 deletions.
6 changes: 6 additions & 0 deletions BrotBoxEngine/BBE/BrotTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ namespace bbe

// Both hours are inclusive! So 23/4 is from 23:00 until 4:59.
bool isNight(int64_t fromHour = 23, int64_t toHour = 4) const;
bool isMonday() const;
bool isTuesday() const;
bool isWednesday() const;
bool isThursday() const;
bool isFriday() const;
bool isSaturday() const;
bool isSunday() const;
bool isToday() const;

Expand Down
41 changes: 38 additions & 3 deletions BrotBoxEngine/BrotTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,46 @@ bool bbe::TimePoint::isNight(int64_t fromHour, int64_t toHour) const
}
}

bool bbe::TimePoint::isSunday() const
static int getWDay(const std::chrono::system_clock::time_point& tp)
{
std::time_t t = std::chrono::system_clock::to_time_t(m_time);
std::time_t t = std::chrono::system_clock::to_time_t(tp);
::tm timeinfo = *localtime(&t);
return timeinfo.tm_wday == 0;
return timeinfo.tm_wday;
}

bool bbe::TimePoint::isMonday() const
{
return getWDay(m_time) == 1;
}

bool bbe::TimePoint::isTuesday() const
{
return getWDay(m_time) == 2;
}

bool bbe::TimePoint::isWednesday() const
{
return getWDay(m_time) == 3;
}

bool bbe::TimePoint::isThursday() const
{
return getWDay(m_time) == 4;
}

bool bbe::TimePoint::isFriday() const
{
return getWDay(m_time) == 5;
}

bool bbe::TimePoint::isSaturday() const
{
return getWDay(m_time) == 6;
}

bool bbe::TimePoint::isSunday() const
{
return getWDay(m_time) == 0;
}

bool bbe::TimePoint::isToday() const
Expand Down
52 changes: 41 additions & 11 deletions Examples/ExampleMother/ExampleMother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//TODO: Add "fixed date" tasks. "Every month/year at this and that date". Useful e.g. for Taxes.
//TODO: Butchered looks on non 4k
//TODO: Implement proper date picker
//TODO: Add tooltips to stuff that explains what everything is
//TODO: Somehow mark error if all weekdays are marked as impossible

#define WM_SYSICON (WM_USER + 1)
#define ID_EXIT 1002
Expand Down Expand Up @@ -57,7 +57,7 @@ struct Task
private:
bbe::TimePoint nextExecution; // Call nextPossibleExecution from the outside!
public:
bool canBeSundays = true;
bool canBeSu = true;
int32_t followUp = 0; // In minutes. When clicking follow up, the task will be rescheduled the same day.
int32_t internalValue = 0;
int32_t internalValueIncrease = 0;
Expand All @@ -67,6 +67,12 @@ struct Task
bool advanceable = false;
bool oneShot = false;
bool preparation = false;
bool canBeMo = true;
bool canBeTu = true;
bool canBeWe = true;
bool canBeTh = true;
bool canBeFr = true;
bool canBeSa = true;

// Non-Persisted Helper Data below.
const char* inputTypeStr = inputTypeItems[0];
Expand Down Expand Up @@ -94,11 +100,7 @@ struct Task
{
internalValue += internalValueIncrease;
previousExecution = bbe::TimePoint();
nextExecution = previousExecution.nextMorning().plusDays(repeatDays - 1);
if (!canBeSundays && nextExecution.isSunday())
{
nextExecution = nextExecution.plusDays(1);
}
nextExecution = toPossibleTimePoint(previousExecution.nextMorning().plusDays(repeatDays - 1));
}
void execFollowUp()
{
Expand Down Expand Up @@ -138,7 +140,7 @@ struct Task
buffer.write(repeatDays);
previousExecution.serialize(buffer);
nextExecution.serialize(buffer);
buffer.write(canBeSundays);
buffer.write(canBeSu);
buffer.write(followUp);
buffer.write(internalValue);
buffer.write(internalValueIncrease);
Expand All @@ -148,6 +150,12 @@ struct Task
buffer.write(advanceable);
buffer.write(oneShot);
buffer.write(preparation);
buffer.write(canBeMo);
buffer.write(canBeTu);
buffer.write(canBeWe);
buffer.write(canBeTh);
buffer.write(canBeFr);
buffer.write(canBeSa);
}
static Task deserialize(bbe::ByteBufferSpan& buffer)
{
Expand All @@ -157,7 +165,7 @@ struct Task
buffer.read(retVal.repeatDays);
retVal.previousExecution = bbe::TimePoint::deserialize(buffer);
retVal.nextExecution = bbe::TimePoint::deserialize(buffer);
buffer.read(retVal.canBeSundays, true);
buffer.read(retVal.canBeSu, true);
buffer.read(retVal.followUp);
buffer.read(retVal.internalValue);
buffer.read(retVal.internalValueIncrease);
Expand All @@ -170,6 +178,12 @@ struct Task
buffer.read(retVal.advanceable);
buffer.read(retVal.oneShot);
buffer.read(retVal.preparation);
buffer.read(retVal.canBeMo, true);
buffer.read(retVal.canBeTu, true);
buffer.read(retVal.canBeWe, true);
buffer.read(retVal.canBeTh, true);
buffer.read(retVal.canBeFr, true);
buffer.read(retVal.canBeSa, true);

return retVal;
}
Expand All @@ -183,7 +197,16 @@ struct Task
bbe::TimePoint toPossibleTimePoint(const bbe::TimePoint& tp) const
{
bbe::TimePoint retVal = tp;
if (!canBeSundays && retVal.isSunday()) retVal = retVal.nextMorning();
for (int32_t i = 0; i < 2; i++)
{
if (!canBeMo && retVal.isMonday()) retVal = retVal.nextMorning();
if (!canBeTu && retVal.isTuesday()) retVal = retVal.nextMorning();
if (!canBeWe && retVal.isWednesday()) retVal = retVal.nextMorning();
if (!canBeTh && retVal.isThursday()) retVal = retVal.nextMorning();
if (!canBeFr && retVal.isFriday()) retVal = retVal.nextMorning();
if (!canBeSa && retVal.isSaturday()) retVal = retVal.nextMorning();
if (!canBeSu && retVal.isSunday()) retVal = retVal.nextMorning();
}
return retVal;
}

Expand Down Expand Up @@ -761,7 +784,14 @@ class MyGame : public bbe::Game
bool taskChanged = false;
taskChanged |= ImGui::InputText("Title", t.title, sizeof(t.title));
taskChanged |= ImGui::InputInt("Repeat Days", &t.repeatDays);
taskChanged |= ImGui::Checkbox("Can be Sundays", &t.canBeSundays);
taskChanged |= ImGui::Checkbox("Monday", &t.canBeMo);
ImGui::SameLine(); taskChanged |= ImGui::Checkbox("Tuesday", &t.canBeTu);
ImGui::SameLine(); taskChanged |= ImGui::Checkbox("Wednesday", &t.canBeWe);
ImGui::SameLine(); taskChanged |= ImGui::Checkbox("Thursday", &t.canBeTh);
ImGui::SameLine(); taskChanged |= ImGui::Checkbox("Friday", &t.canBeFr);
ImGui::SameLine(); taskChanged |= ImGui::Checkbox("Saturday", &t.canBeSa);
ImGui::SameLine(); taskChanged |= ImGui::Checkbox("Sunday", &t.canBeSu);

taskChanged |= ImGui::Checkbox("Advanceable", &t.advanceable);
tooltip("Can \"done\" even if it's not planned for today.");
if (t.advanceable)
Expand Down

0 comments on commit 48d0e6a

Please sign in to comment.