cqcalendar 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cqcalendar-1.0.0/LICENSE +21 -0
- cqcalendar-1.0.0/PKG-INFO +178 -0
- cqcalendar-1.0.0/README.md +159 -0
- cqcalendar-1.0.0/cqcalendar/__init__.py +4 -0
- cqcalendar-1.0.0/cqcalendar/cqcalendar.py +349 -0
- cqcalendar-1.0.0/cqcalendar.egg-info/PKG-INFO +178 -0
- cqcalendar-1.0.0/cqcalendar.egg-info/SOURCES.txt +9 -0
- cqcalendar-1.0.0/cqcalendar.egg-info/dependency_links.txt +1 -0
- cqcalendar-1.0.0/cqcalendar.egg-info/top_level.txt +1 -0
- cqcalendar-1.0.0/pyproject.toml +28 -0
- cqcalendar-1.0.0/setup.cfg +4 -0
cqcalendar-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Brianna Ladson
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cqcalendar
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: CQCalendar is a lightweight, tick-based time and calendar system for Python games and simulations.
|
|
5
|
+
Author: Brianna Ladson
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: rpg,simulation,game-dev,time-system,calendar,tick-based,worldbuilding,sandbox
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Topic :: Games/Entertainment
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
15
|
+
Requires-Python: >=3.7
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# CQCalendar
|
|
21
|
+
CQCalendar is a lightweight, tick-based time and calendar system for Python games and simulations.
|
|
22
|
+
|
|
23
|
+
It is designed for RPGs, sandbox sims, and systemic games, where time drives world behavior rather than just displaying a UI clock.
|
|
24
|
+
|
|
25
|
+
***
|
|
26
|
+
## Features
|
|
27
|
+
* Tick-based and absolute time progression
|
|
28
|
+
* Gregorian calendar with leap year support
|
|
29
|
+
* Weekday tracking
|
|
30
|
+
* Synodic lunar cycle (moon phases & illumination)
|
|
31
|
+
* Event callbacks for hour/day/month/year changes
|
|
32
|
+
* Designed for decoupled, systemic game logic
|
|
33
|
+
* No external dependencies
|
|
34
|
+
|
|
35
|
+
***
|
|
36
|
+
|
|
37
|
+
## How to Create a Calendar for Your Game
|
|
38
|
+
```
|
|
39
|
+
import cqcalendar
|
|
40
|
+
|
|
41
|
+
calendar = cqcalendar.CQCalendar(
|
|
42
|
+
hour=9,
|
|
43
|
+
minute=0,
|
|
44
|
+
is_pm=False,
|
|
45
|
+
minutes_per_tick=1,
|
|
46
|
+
day=1,
|
|
47
|
+
month=1,
|
|
48
|
+
year=1,
|
|
49
|
+
weekday=0,
|
|
50
|
+
moon_age_days=0.0,
|
|
51
|
+
debug_callbacks=False,
|
|
52
|
+
)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
***
|
|
56
|
+
## Time
|
|
57
|
+
|
|
58
|
+
### How to Display Current Time
|
|
59
|
+
```
|
|
60
|
+
print(calendar.time_string())
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### How to Change Time
|
|
64
|
+
```
|
|
65
|
+
calendar.set_time(hour=12, minute=0, is_pm=True)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### How to Increment Time
|
|
69
|
+
```
|
|
70
|
+
calendar.update(ticks=10)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
***
|
|
74
|
+
## Date
|
|
75
|
+
|
|
76
|
+
### How to Display Current Date
|
|
77
|
+
```
|
|
78
|
+
print(calendar.date_string())
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### How to Change Date
|
|
82
|
+
```
|
|
83
|
+
calendar.set_date(day=31, month=12, year=1)
|
|
84
|
+
```
|
|
85
|
+
***
|
|
86
|
+
|
|
87
|
+
## Absolute Time Advancement
|
|
88
|
+
You can advance time directly without ticks.
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
calendar.add_minutes(30)
|
|
92
|
+
calendar.add_hours(6)
|
|
93
|
+
calendar.add_days(1)
|
|
94
|
+
calendar.add_months(1)
|
|
95
|
+
calendar.add_years(1)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Or you can do it in a single method.
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
calendar.add(days=3, hours=4)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
***
|
|
105
|
+
## Weekdays
|
|
106
|
+
Weekdays are zero-indexed (0 = Monday, 6 = Sunday).
|
|
107
|
+
|
|
108
|
+
### How to Display Weekday
|
|
109
|
+
```
|
|
110
|
+
print(calendar.weekday_name())
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### How to Change Weekday
|
|
114
|
+
```
|
|
115
|
+
calendar.set_weekday(weekday=1)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
***
|
|
119
|
+
## Lunar Cycle
|
|
120
|
+
CQCalendar includes a synodic lunar cycle (approximately 29.53 days)
|
|
121
|
+
|
|
122
|
+
### How to Display Moon Phase
|
|
123
|
+
```
|
|
124
|
+
print(calendar.moon_phase_name())
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### How to Get Moon Illumination
|
|
128
|
+
```
|
|
129
|
+
print(calendar.moon_illumination())
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Useful for:
|
|
133
|
+
* werewolf systems
|
|
134
|
+
* rituals
|
|
135
|
+
* night visibility
|
|
136
|
+
* tides or magic strength
|
|
137
|
+
|
|
138
|
+
***
|
|
139
|
+
## Callbacks (Events)
|
|
140
|
+
CQCalendar allows systems to react to time changes using callbacks.
|
|
141
|
+
|
|
142
|
+
Callbacks are triggered when time crosses a boundary (hour/day/month/year), not continuously.
|
|
143
|
+
|
|
144
|
+
### Hourly Event
|
|
145
|
+
```
|
|
146
|
+
def restock_shops(calendar):
|
|
147
|
+
if calendar.hour == 6 and not calendar.is_pm:
|
|
148
|
+
print("Shops restocked!")
|
|
149
|
+
|
|
150
|
+
calendar.on_hour(restock_shops)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Daily Event
|
|
154
|
+
```
|
|
155
|
+
def payday(calendar):
|
|
156
|
+
if calendar.day == 1:
|
|
157
|
+
print("Rent is due!")
|
|
158
|
+
|
|
159
|
+
calendar.on_day(payday)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Available callbacks:
|
|
163
|
+
* on_hour
|
|
164
|
+
* on_day
|
|
165
|
+
* on_month
|
|
166
|
+
* on_year
|
|
167
|
+
|
|
168
|
+
***
|
|
169
|
+
## Misc.
|
|
170
|
+
|
|
171
|
+
### How to Display Current Date and Time
|
|
172
|
+
```
|
|
173
|
+
print(calendar.datetime_string())
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
***
|
|
177
|
+
## Related Libraries
|
|
178
|
+
* [TerraForge](https://github.com/BriannaLadson/TerraForge): A versatile Python toolset for procedural map generation.
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# CQCalendar
|
|
2
|
+
CQCalendar is a lightweight, tick-based time and calendar system for Python games and simulations.
|
|
3
|
+
|
|
4
|
+
It is designed for RPGs, sandbox sims, and systemic games, where time drives world behavior rather than just displaying a UI clock.
|
|
5
|
+
|
|
6
|
+
***
|
|
7
|
+
## Features
|
|
8
|
+
* Tick-based and absolute time progression
|
|
9
|
+
* Gregorian calendar with leap year support
|
|
10
|
+
* Weekday tracking
|
|
11
|
+
* Synodic lunar cycle (moon phases & illumination)
|
|
12
|
+
* Event callbacks for hour/day/month/year changes
|
|
13
|
+
* Designed for decoupled, systemic game logic
|
|
14
|
+
* No external dependencies
|
|
15
|
+
|
|
16
|
+
***
|
|
17
|
+
|
|
18
|
+
## How to Create a Calendar for Your Game
|
|
19
|
+
```
|
|
20
|
+
import cqcalendar
|
|
21
|
+
|
|
22
|
+
calendar = cqcalendar.CQCalendar(
|
|
23
|
+
hour=9,
|
|
24
|
+
minute=0,
|
|
25
|
+
is_pm=False,
|
|
26
|
+
minutes_per_tick=1,
|
|
27
|
+
day=1,
|
|
28
|
+
month=1,
|
|
29
|
+
year=1,
|
|
30
|
+
weekday=0,
|
|
31
|
+
moon_age_days=0.0,
|
|
32
|
+
debug_callbacks=False,
|
|
33
|
+
)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
***
|
|
37
|
+
## Time
|
|
38
|
+
|
|
39
|
+
### How to Display Current Time
|
|
40
|
+
```
|
|
41
|
+
print(calendar.time_string())
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### How to Change Time
|
|
45
|
+
```
|
|
46
|
+
calendar.set_time(hour=12, minute=0, is_pm=True)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### How to Increment Time
|
|
50
|
+
```
|
|
51
|
+
calendar.update(ticks=10)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
***
|
|
55
|
+
## Date
|
|
56
|
+
|
|
57
|
+
### How to Display Current Date
|
|
58
|
+
```
|
|
59
|
+
print(calendar.date_string())
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### How to Change Date
|
|
63
|
+
```
|
|
64
|
+
calendar.set_date(day=31, month=12, year=1)
|
|
65
|
+
```
|
|
66
|
+
***
|
|
67
|
+
|
|
68
|
+
## Absolute Time Advancement
|
|
69
|
+
You can advance time directly without ticks.
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
calendar.add_minutes(30)
|
|
73
|
+
calendar.add_hours(6)
|
|
74
|
+
calendar.add_days(1)
|
|
75
|
+
calendar.add_months(1)
|
|
76
|
+
calendar.add_years(1)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Or you can do it in a single method.
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
calendar.add(days=3, hours=4)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
***
|
|
86
|
+
## Weekdays
|
|
87
|
+
Weekdays are zero-indexed (0 = Monday, 6 = Sunday).
|
|
88
|
+
|
|
89
|
+
### How to Display Weekday
|
|
90
|
+
```
|
|
91
|
+
print(calendar.weekday_name())
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### How to Change Weekday
|
|
95
|
+
```
|
|
96
|
+
calendar.set_weekday(weekday=1)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
***
|
|
100
|
+
## Lunar Cycle
|
|
101
|
+
CQCalendar includes a synodic lunar cycle (approximately 29.53 days)
|
|
102
|
+
|
|
103
|
+
### How to Display Moon Phase
|
|
104
|
+
```
|
|
105
|
+
print(calendar.moon_phase_name())
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### How to Get Moon Illumination
|
|
109
|
+
```
|
|
110
|
+
print(calendar.moon_illumination())
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Useful for:
|
|
114
|
+
* werewolf systems
|
|
115
|
+
* rituals
|
|
116
|
+
* night visibility
|
|
117
|
+
* tides or magic strength
|
|
118
|
+
|
|
119
|
+
***
|
|
120
|
+
## Callbacks (Events)
|
|
121
|
+
CQCalendar allows systems to react to time changes using callbacks.
|
|
122
|
+
|
|
123
|
+
Callbacks are triggered when time crosses a boundary (hour/day/month/year), not continuously.
|
|
124
|
+
|
|
125
|
+
### Hourly Event
|
|
126
|
+
```
|
|
127
|
+
def restock_shops(calendar):
|
|
128
|
+
if calendar.hour == 6 and not calendar.is_pm:
|
|
129
|
+
print("Shops restocked!")
|
|
130
|
+
|
|
131
|
+
calendar.on_hour(restock_shops)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Daily Event
|
|
135
|
+
```
|
|
136
|
+
def payday(calendar):
|
|
137
|
+
if calendar.day == 1:
|
|
138
|
+
print("Rent is due!")
|
|
139
|
+
|
|
140
|
+
calendar.on_day(payday)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Available callbacks:
|
|
144
|
+
* on_hour
|
|
145
|
+
* on_day
|
|
146
|
+
* on_month
|
|
147
|
+
* on_year
|
|
148
|
+
|
|
149
|
+
***
|
|
150
|
+
## Misc.
|
|
151
|
+
|
|
152
|
+
### How to Display Current Date and Time
|
|
153
|
+
```
|
|
154
|
+
print(calendar.datetime_string())
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
***
|
|
158
|
+
## Related Libraries
|
|
159
|
+
* [TerraForge](https://github.com/BriannaLadson/TerraForge): A versatile Python toolset for procedural map generation.
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
__version__ = "1.0.0"
|
|
2
|
+
|
|
3
|
+
class CQCalendar:
|
|
4
|
+
def __init__(self, hour=9, minute=0, is_pm=False, minutes_per_tick=1, day=1, month=1, year=1, weekday=0, moon_age_days=0.0, debug_callbacks=False):
|
|
5
|
+
self.minutes_per_tick = max(1, int(minutes_per_tick))
|
|
6
|
+
|
|
7
|
+
self.months = [
|
|
8
|
+
("January", 31),
|
|
9
|
+
("February", 28),
|
|
10
|
+
("March", 31),
|
|
11
|
+
("April", 30),
|
|
12
|
+
("May", 31),
|
|
13
|
+
("June", 30),
|
|
14
|
+
("July", 31),
|
|
15
|
+
("August", 31),
|
|
16
|
+
("September", 30),
|
|
17
|
+
("October", 31),
|
|
18
|
+
("November", 30),
|
|
19
|
+
("December", 31),
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
self.weekdays = [
|
|
23
|
+
"Monday",
|
|
24
|
+
"Tuesday",
|
|
25
|
+
"Wednesday",
|
|
26
|
+
"Thursday",
|
|
27
|
+
"Friday",
|
|
28
|
+
"Saturday",
|
|
29
|
+
"Sunday",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
self._on_hour = []
|
|
33
|
+
self._on_day = []
|
|
34
|
+
self._on_month = []
|
|
35
|
+
self._on_year = []
|
|
36
|
+
|
|
37
|
+
self.synodic_month_days = 29.530588
|
|
38
|
+
|
|
39
|
+
self.moon_age_days = float(moon_age_days) % self.synodic_month_days
|
|
40
|
+
|
|
41
|
+
self.set_time(hour=hour, minute=minute, is_pm=is_pm)
|
|
42
|
+
self.set_date(day=day, month=month, year=year)
|
|
43
|
+
self.set_weekday(weekday)
|
|
44
|
+
|
|
45
|
+
self.debug_callbacks = bool(debug_callbacks)
|
|
46
|
+
|
|
47
|
+
def __repr__(self):
|
|
48
|
+
return f"<CQCalendar {self.date_string()} {self.time_string()}>"
|
|
49
|
+
|
|
50
|
+
def on_hour(self, callback):
|
|
51
|
+
self._on_hour.append(callback)
|
|
52
|
+
|
|
53
|
+
return callback
|
|
54
|
+
|
|
55
|
+
def on_day(self, callback):
|
|
56
|
+
self._on_day.append(callback)
|
|
57
|
+
|
|
58
|
+
return callback
|
|
59
|
+
|
|
60
|
+
def on_month(self, callback):
|
|
61
|
+
self._on_month.append(callback)
|
|
62
|
+
|
|
63
|
+
return callback
|
|
64
|
+
|
|
65
|
+
def on_year(self, callback):
|
|
66
|
+
self._on_year.append(callback)
|
|
67
|
+
|
|
68
|
+
return callback
|
|
69
|
+
|
|
70
|
+
def off_hour(self, callback):
|
|
71
|
+
if callback in self._on_hour:
|
|
72
|
+
self._on_hour.remove(callback)
|
|
73
|
+
|
|
74
|
+
def off_day(self, callback):
|
|
75
|
+
if callback in self._on_day:
|
|
76
|
+
self._on_day.remove(callback)
|
|
77
|
+
|
|
78
|
+
def off_month(self, callback):
|
|
79
|
+
if callback in self._on_month:
|
|
80
|
+
self._on_month.remove(callback)
|
|
81
|
+
|
|
82
|
+
def off_year(self, callback):
|
|
83
|
+
if callback in self._on_year:
|
|
84
|
+
self._on_year.remove(callback)
|
|
85
|
+
|
|
86
|
+
def _emit(self, callbacks):
|
|
87
|
+
for cb in list(callbacks):
|
|
88
|
+
try:
|
|
89
|
+
cb(self)
|
|
90
|
+
|
|
91
|
+
except Exception as e:
|
|
92
|
+
if self.debug_callbacks:
|
|
93
|
+
raise
|
|
94
|
+
|
|
95
|
+
def set_time(self, hour=9, minute=0, is_pm=False):
|
|
96
|
+
hour = int(hour)
|
|
97
|
+
minute = int(minute)
|
|
98
|
+
|
|
99
|
+
if hour < 1: hour = 1
|
|
100
|
+
if hour > 12: hour = 12
|
|
101
|
+
|
|
102
|
+
if minute < 0: minute = 0
|
|
103
|
+
if minute > 59: minute = 59
|
|
104
|
+
|
|
105
|
+
self.hour = hour
|
|
106
|
+
self.minute = minute
|
|
107
|
+
self.is_pm = bool(is_pm)
|
|
108
|
+
|
|
109
|
+
def set_date(self, day=1, month=1, year=1):
|
|
110
|
+
month = int(month)
|
|
111
|
+
day = int(day)
|
|
112
|
+
year = int(year)
|
|
113
|
+
|
|
114
|
+
month = max(1, min(month, len(self.months)))
|
|
115
|
+
year = max(1, year)
|
|
116
|
+
|
|
117
|
+
days_in_month = self.days_in_month(month, year)
|
|
118
|
+
day = max(1, min(day, days_in_month))
|
|
119
|
+
|
|
120
|
+
self.day = day
|
|
121
|
+
self.month = month
|
|
122
|
+
self.year = year
|
|
123
|
+
|
|
124
|
+
def update(self, ticks=1):
|
|
125
|
+
self.add_minutes(int(ticks) * self.minutes_per_tick)
|
|
126
|
+
|
|
127
|
+
def add_minutes(self, minutes: int):
|
|
128
|
+
minutes = int(minutes)
|
|
129
|
+
|
|
130
|
+
if minutes == 0:
|
|
131
|
+
return
|
|
132
|
+
|
|
133
|
+
if minutes < 0:
|
|
134
|
+
raise ValueError("add_minutes does not support negative values.")
|
|
135
|
+
|
|
136
|
+
self.advance_moon_by_minutes(minutes)
|
|
137
|
+
|
|
138
|
+
self.minute += minutes
|
|
139
|
+
|
|
140
|
+
while self.minute >= 60:
|
|
141
|
+
self.minute -= 60
|
|
142
|
+
self.advance_hour()
|
|
143
|
+
|
|
144
|
+
def add_hours(self, hours: int):
|
|
145
|
+
hours = int(hours)
|
|
146
|
+
|
|
147
|
+
if hours == 0:
|
|
148
|
+
return
|
|
149
|
+
|
|
150
|
+
if hours < 0:
|
|
151
|
+
raise ValueError("add_hours does not support negative values.")
|
|
152
|
+
|
|
153
|
+
self.add_minutes(hours * 60)
|
|
154
|
+
|
|
155
|
+
def add_days(self, days: int):
|
|
156
|
+
days = int(days)
|
|
157
|
+
|
|
158
|
+
if days == 0:
|
|
159
|
+
return
|
|
160
|
+
|
|
161
|
+
if days < 0:
|
|
162
|
+
raise ValueError("add_days does not support negative values.")
|
|
163
|
+
|
|
164
|
+
for _ in range(days):
|
|
165
|
+
self.advance_day()
|
|
166
|
+
|
|
167
|
+
def add_months(self, months: int):
|
|
168
|
+
months = int(months)
|
|
169
|
+
|
|
170
|
+
if months == 0:
|
|
171
|
+
return
|
|
172
|
+
|
|
173
|
+
if months < 0:
|
|
174
|
+
raise ValueError("add_months does not support negative values.")
|
|
175
|
+
|
|
176
|
+
for _ in range(months):
|
|
177
|
+
self.advance_month()
|
|
178
|
+
|
|
179
|
+
self.clamp_day_to_month()
|
|
180
|
+
|
|
181
|
+
def add_years(self, years: int):
|
|
182
|
+
years = int(years)
|
|
183
|
+
|
|
184
|
+
if years == 0:
|
|
185
|
+
return
|
|
186
|
+
|
|
187
|
+
if years < 0:
|
|
188
|
+
raise ValueError("add_years does not support negative values.")
|
|
189
|
+
|
|
190
|
+
self.year += years
|
|
191
|
+
|
|
192
|
+
self.clamp_day_to_month()
|
|
193
|
+
|
|
194
|
+
def add(self, minutes=0, hours=0, days=0, months=0, years=0):
|
|
195
|
+
if years: self.add_years(years)
|
|
196
|
+
if months: self.add_months(months)
|
|
197
|
+
if days: self.add_days(days)
|
|
198
|
+
if hours: self.add_hours(hours)
|
|
199
|
+
if minutes: self.add_minutes(minutes)
|
|
200
|
+
|
|
201
|
+
def advance_hour(self):
|
|
202
|
+
if self.hour == 11:
|
|
203
|
+
self.hour = 12
|
|
204
|
+
|
|
205
|
+
self.is_pm = not self.is_pm
|
|
206
|
+
|
|
207
|
+
if not self.is_pm:
|
|
208
|
+
self.advance_day()
|
|
209
|
+
|
|
210
|
+
elif self.hour == 12:
|
|
211
|
+
self.hour = 1
|
|
212
|
+
|
|
213
|
+
else:
|
|
214
|
+
self.hour += 1
|
|
215
|
+
|
|
216
|
+
self._emit(self._on_hour)
|
|
217
|
+
|
|
218
|
+
def advance_day(self):
|
|
219
|
+
days_in_month = self.days_in_month(self.month, self.year)
|
|
220
|
+
|
|
221
|
+
self.day += 1
|
|
222
|
+
|
|
223
|
+
self.moon_age_days = (self.moon_age_days + 1.0) % self.synodic_month_days
|
|
224
|
+
|
|
225
|
+
if self.day > days_in_month:
|
|
226
|
+
self.day = 1
|
|
227
|
+
self.advance_month()
|
|
228
|
+
|
|
229
|
+
self.weekday = (self.weekday + 1) % 7
|
|
230
|
+
|
|
231
|
+
self._emit(self._on_day)
|
|
232
|
+
|
|
233
|
+
def advance_month(self):
|
|
234
|
+
self.month += 1
|
|
235
|
+
|
|
236
|
+
if self.month > len(self.months):
|
|
237
|
+
self.month = 1
|
|
238
|
+
self.advance_year()
|
|
239
|
+
|
|
240
|
+
self.clamp_day_to_month()
|
|
241
|
+
|
|
242
|
+
self._emit(self._on_month)
|
|
243
|
+
|
|
244
|
+
def advance_year(self):
|
|
245
|
+
self.year += 1
|
|
246
|
+
|
|
247
|
+
self._emit(self._on_year)
|
|
248
|
+
|
|
249
|
+
def advance_moon_by_minutes(self, minutes: int):
|
|
250
|
+
days = minutes / (60.0 * 24.0)
|
|
251
|
+
|
|
252
|
+
self.moon_age_days = (self.moon_age_days + days) % self.synodic_month_days
|
|
253
|
+
|
|
254
|
+
def is_leap_year(self, year=None) -> bool:
|
|
255
|
+
if year is None:
|
|
256
|
+
year = self.year
|
|
257
|
+
|
|
258
|
+
year = int(year)
|
|
259
|
+
|
|
260
|
+
if year % 400 == 0:
|
|
261
|
+
return True
|
|
262
|
+
|
|
263
|
+
if year % 100 == 0:
|
|
264
|
+
return False
|
|
265
|
+
|
|
266
|
+
return year % 4 == 0
|
|
267
|
+
|
|
268
|
+
def days_in_month(self, month=None, year=None) -> int:
|
|
269
|
+
if month is None:
|
|
270
|
+
month = self.month
|
|
271
|
+
|
|
272
|
+
if year is None:
|
|
273
|
+
year = self.year
|
|
274
|
+
|
|
275
|
+
month = int(month)
|
|
276
|
+
year = int(year)
|
|
277
|
+
|
|
278
|
+
if month == 2:
|
|
279
|
+
return 29 if self.is_leap_year(year) else 28
|
|
280
|
+
|
|
281
|
+
_, base_days = self.months[month - 1]
|
|
282
|
+
|
|
283
|
+
return base_days
|
|
284
|
+
|
|
285
|
+
def clamp_day_to_month(self):
|
|
286
|
+
dim = self.days_in_month(self.month, self.year)
|
|
287
|
+
|
|
288
|
+
if self.day > dim:
|
|
289
|
+
self.day = dim
|
|
290
|
+
|
|
291
|
+
def set_weekday(self, weekday=0):
|
|
292
|
+
if weekday is None:
|
|
293
|
+
weekday = 0
|
|
294
|
+
|
|
295
|
+
self.weekday = int(weekday) % 7
|
|
296
|
+
|
|
297
|
+
def weekday_name(self):
|
|
298
|
+
return self.weekdays[self.weekday]
|
|
299
|
+
|
|
300
|
+
def moon_phase_name(self):
|
|
301
|
+
phase = self.moon_age_days / self.synodic_month_days
|
|
302
|
+
|
|
303
|
+
index = int((phase * 8) + 0.5) % 8
|
|
304
|
+
|
|
305
|
+
return [
|
|
306
|
+
"New Moon",
|
|
307
|
+
"Waxing Crescent",
|
|
308
|
+
"First Quarter",
|
|
309
|
+
"Waxing Gibbous",
|
|
310
|
+
"Full Moon",
|
|
311
|
+
"Waning Gibbous",
|
|
312
|
+
"Last Quarter",
|
|
313
|
+
"Waning Crescent",
|
|
314
|
+
][index]
|
|
315
|
+
|
|
316
|
+
def moon_illumination(self):
|
|
317
|
+
import math
|
|
318
|
+
|
|
319
|
+
phase_angle = (self.moon_age_days / self.synodic_month_days) * 2.0 * math.pi
|
|
320
|
+
|
|
321
|
+
return 0.5 * (1.0 - math.cos(phase_angle))
|
|
322
|
+
|
|
323
|
+
def time_string(self):
|
|
324
|
+
return f"{self.hour}:{self.minute:02d} {'PM' if self.is_pm else 'AM'}"
|
|
325
|
+
|
|
326
|
+
def date_string(self):
|
|
327
|
+
month_name, _ = self.months[self.month - 1]
|
|
328
|
+
return f"{self.weekday_name()}, {month_name} {self.day}, Year {self.year}"
|
|
329
|
+
|
|
330
|
+
def datetime_string(self):
|
|
331
|
+
return f"{self.date_string()} at {self.time_string()}"
|
|
332
|
+
|
|
333
|
+
if __name__ == "__main__":
|
|
334
|
+
calendar = CQCalendar(day=31, month=1, year=2024, weekday=0, moon_age_days=0.0)
|
|
335
|
+
|
|
336
|
+
def restock_shops(calendar):
|
|
337
|
+
if calendar.hour == 6 and not calendar.is_pm:
|
|
338
|
+
print("[EVENT] Shops restocked!")
|
|
339
|
+
|
|
340
|
+
def payday(calendar):
|
|
341
|
+
if calendar.day == 1:
|
|
342
|
+
print("[EVENT] Rent due!")
|
|
343
|
+
|
|
344
|
+
calendar.on_hour(restock_shops)
|
|
345
|
+
calendar.on_day(payday)
|
|
346
|
+
|
|
347
|
+
for i in range(48):
|
|
348
|
+
print(calendar.datetime_string(), calendar.moon_phase_name(), round(calendar.moon_illumination(), 2))
|
|
349
|
+
calendar.add_hours(1)
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cqcalendar
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: CQCalendar is a lightweight, tick-based time and calendar system for Python games and simulations.
|
|
5
|
+
Author: Brianna Ladson
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: rpg,simulation,game-dev,time-system,calendar,tick-based,worldbuilding,sandbox
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Topic :: Games/Entertainment
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
15
|
+
Requires-Python: >=3.7
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# CQCalendar
|
|
21
|
+
CQCalendar is a lightweight, tick-based time and calendar system for Python games and simulations.
|
|
22
|
+
|
|
23
|
+
It is designed for RPGs, sandbox sims, and systemic games, where time drives world behavior rather than just displaying a UI clock.
|
|
24
|
+
|
|
25
|
+
***
|
|
26
|
+
## Features
|
|
27
|
+
* Tick-based and absolute time progression
|
|
28
|
+
* Gregorian calendar with leap year support
|
|
29
|
+
* Weekday tracking
|
|
30
|
+
* Synodic lunar cycle (moon phases & illumination)
|
|
31
|
+
* Event callbacks for hour/day/month/year changes
|
|
32
|
+
* Designed for decoupled, systemic game logic
|
|
33
|
+
* No external dependencies
|
|
34
|
+
|
|
35
|
+
***
|
|
36
|
+
|
|
37
|
+
## How to Create a Calendar for Your Game
|
|
38
|
+
```
|
|
39
|
+
import cqcalendar
|
|
40
|
+
|
|
41
|
+
calendar = cqcalendar.CQCalendar(
|
|
42
|
+
hour=9,
|
|
43
|
+
minute=0,
|
|
44
|
+
is_pm=False,
|
|
45
|
+
minutes_per_tick=1,
|
|
46
|
+
day=1,
|
|
47
|
+
month=1,
|
|
48
|
+
year=1,
|
|
49
|
+
weekday=0,
|
|
50
|
+
moon_age_days=0.0,
|
|
51
|
+
debug_callbacks=False,
|
|
52
|
+
)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
***
|
|
56
|
+
## Time
|
|
57
|
+
|
|
58
|
+
### How to Display Current Time
|
|
59
|
+
```
|
|
60
|
+
print(calendar.time_string())
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### How to Change Time
|
|
64
|
+
```
|
|
65
|
+
calendar.set_time(hour=12, minute=0, is_pm=True)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### How to Increment Time
|
|
69
|
+
```
|
|
70
|
+
calendar.update(ticks=10)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
***
|
|
74
|
+
## Date
|
|
75
|
+
|
|
76
|
+
### How to Display Current Date
|
|
77
|
+
```
|
|
78
|
+
print(calendar.date_string())
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### How to Change Date
|
|
82
|
+
```
|
|
83
|
+
calendar.set_date(day=31, month=12, year=1)
|
|
84
|
+
```
|
|
85
|
+
***
|
|
86
|
+
|
|
87
|
+
## Absolute Time Advancement
|
|
88
|
+
You can advance time directly without ticks.
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
calendar.add_minutes(30)
|
|
92
|
+
calendar.add_hours(6)
|
|
93
|
+
calendar.add_days(1)
|
|
94
|
+
calendar.add_months(1)
|
|
95
|
+
calendar.add_years(1)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Or you can do it in a single method.
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
calendar.add(days=3, hours=4)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
***
|
|
105
|
+
## Weekdays
|
|
106
|
+
Weekdays are zero-indexed (0 = Monday, 6 = Sunday).
|
|
107
|
+
|
|
108
|
+
### How to Display Weekday
|
|
109
|
+
```
|
|
110
|
+
print(calendar.weekday_name())
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### How to Change Weekday
|
|
114
|
+
```
|
|
115
|
+
calendar.set_weekday(weekday=1)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
***
|
|
119
|
+
## Lunar Cycle
|
|
120
|
+
CQCalendar includes a synodic lunar cycle (approximately 29.53 days)
|
|
121
|
+
|
|
122
|
+
### How to Display Moon Phase
|
|
123
|
+
```
|
|
124
|
+
print(calendar.moon_phase_name())
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### How to Get Moon Illumination
|
|
128
|
+
```
|
|
129
|
+
print(calendar.moon_illumination())
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Useful for:
|
|
133
|
+
* werewolf systems
|
|
134
|
+
* rituals
|
|
135
|
+
* night visibility
|
|
136
|
+
* tides or magic strength
|
|
137
|
+
|
|
138
|
+
***
|
|
139
|
+
## Callbacks (Events)
|
|
140
|
+
CQCalendar allows systems to react to time changes using callbacks.
|
|
141
|
+
|
|
142
|
+
Callbacks are triggered when time crosses a boundary (hour/day/month/year), not continuously.
|
|
143
|
+
|
|
144
|
+
### Hourly Event
|
|
145
|
+
```
|
|
146
|
+
def restock_shops(calendar):
|
|
147
|
+
if calendar.hour == 6 and not calendar.is_pm:
|
|
148
|
+
print("Shops restocked!")
|
|
149
|
+
|
|
150
|
+
calendar.on_hour(restock_shops)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Daily Event
|
|
154
|
+
```
|
|
155
|
+
def payday(calendar):
|
|
156
|
+
if calendar.day == 1:
|
|
157
|
+
print("Rent is due!")
|
|
158
|
+
|
|
159
|
+
calendar.on_day(payday)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Available callbacks:
|
|
163
|
+
* on_hour
|
|
164
|
+
* on_day
|
|
165
|
+
* on_month
|
|
166
|
+
* on_year
|
|
167
|
+
|
|
168
|
+
***
|
|
169
|
+
## Misc.
|
|
170
|
+
|
|
171
|
+
### How to Display Current Date and Time
|
|
172
|
+
```
|
|
173
|
+
print(calendar.datetime_string())
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
***
|
|
177
|
+
## Related Libraries
|
|
178
|
+
* [TerraForge](https://github.com/BriannaLadson/TerraForge): A versatile Python toolset for procedural map generation.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cqcalendar
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "cqcalendar"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
description = "CQCalendar is a lightweight, tick-based time and calendar system for Python games and simulations."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.7"
|
|
7
|
+
license = {text = "MIT"}
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Brianna Ladson" }
|
|
10
|
+
]
|
|
11
|
+
keywords = [
|
|
12
|
+
"rpg", "simulation", "game-dev", "time-system", "calendar",
|
|
13
|
+
"tick-based", "worldbuilding", "sandbox"
|
|
14
|
+
]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Topic :: Games/Entertainment",
|
|
22
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
23
|
+
]
|
|
24
|
+
dependencies = []
|
|
25
|
+
|
|
26
|
+
[build-system]
|
|
27
|
+
requires = ["setuptools", "wheel"]
|
|
28
|
+
build-backend = "setuptools.build_meta"
|