Skip to content

Commit

Permalink
Playing sounds when night time or almost night time.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brotcrunsher committed Nov 22, 2023
1 parent 213a728 commit 005f126
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
Binary file added Examples/ExampleMother/Assets/AlmostNightTime.mp3
Binary file not shown.
Binary file added Examples/ExampleMother/Assets/NightTime.mp3
Binary file not shown.
31 changes: 27 additions & 4 deletions Examples/ExampleMother/ExampleMother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include <Windows.h>
#include "AssetStore.h"

//TODO: GATW: play sound when night time
//TODO: GATW: play sound 5 minutes before night time
//TODO: GATW: kill (?) Time Wasters Processes during working hours and while still tasks are open.
//TODO: Add "fixed date" tasks. "Every month/year at this and that date". Useful e.g. for Taxes.
//TODO: Make .dll unnecessary for OpenAL when deploying .exe
Expand Down Expand Up @@ -366,7 +364,7 @@ class MyGame : public bbe::Game
Shell_NotifyIcon(firstCall ? NIM_ADD : NIM_MODIFY, &notifyIconData);
}

bool isNightTime()
bbe::TimePoint getNightStart()
{
// TODO: This is something highly personalized for my own current usage. It probably needs to be removed some day.
// It takes away one minute for every passed day since 2023/11/22. Slowly approaching a more healthy sleep
Expand All @@ -376,8 +374,28 @@ class MyGame : public bbe::Game
int32_t daysSinceQualifyingDate = timeSinceQualifyingDate.toDays();
if (daysSinceQualifyingDate > 60) daysSinceQualifyingDate = 60;

return bbe::TimePoint::todayAt(23, 59 - daysSinceQualifyingDate);
}

bool isNightTime()
{
bbe::TimePoint now;
return bbe::TimePoint::todayAt(5, 00) > now || now > bbe::TimePoint::todayAt(23, 59 - daysSinceQualifyingDate);
return bbe::TimePoint::todayAt(5, 00) > now || now > getNightStart();
}

bool shouldPlayAlmostNightWarning()
{
static bool playedBefore = false;
if (!playedBefore)
{
bbe::TimePoint now;
if (now > getNightStart().plusMinutes(-5))
{
playedBefore = true;
return true;
}
}
return false;
}

virtual void update(float timeSinceLastFrame) override
Expand Down Expand Up @@ -411,8 +429,13 @@ class MyGame : public bbe::Game
HWND hwnd = FindWindow("Shell_TrayWnd", NULL);
LRESULT res = SendMessage(hwnd, WM_COMMAND, (WPARAM)419, 0);
showWindow();
assetStore::NightTime()->play();
}
}
if (shouldPlayAlmostNightWarning())
{
assetStore::AlmostNightTime()->play();
}
}

int32_t drawTable(const char* title, const std::function<bool(Task&)>& predicate, bool& contentsChanged, bool showMoveToNow, bool showCountdown, bool showDone, bool showFollowUp, bool highlightRareTasks)
Expand Down

0 comments on commit 005f126

Please sign in to comment.