Oki, one thing at a time
Code: Select all
class Calendar(object):
'''Provides time-related information.
Cheers to Rudi for mooncalendar calculations.
'''
def __init__(self, day=1, month=1, year=1, leapyear=False):
"""
Expects day/month/year as they are numbered in normal calender.
If you wish to add leapyear, specify a number of the first Leap year to come.
"""
self.day = day
self._month = month - 1
self.year = year
if not leapyear:
self.leapyear = self.year + 4
else:
self.leapyear = leapyear
self.daycount_from_gamestart = 0
self.days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
self.month_names = ['January', 'February', 'March', 'April', 'May', 'June', 'July',
'August', 'September', 'October', 'November', 'December']
self.days_count = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
self.mooncycle = 29
self.newmoonday = 1
@property
def game_day(self):
"""
Returns amount of days player has spent in game.
Counts first day as day 1.
"""
return self.daycount_from_gamestart + 1
@property
def game_week(self):
'''Returns the number of weeks, starting at 1 for the first week.
'''
weekidx = self.daycount_from_gamestart / len(self.days)
return weekidx + 1
@property
def weekday(self):
'''Returns the name of the current day according to daycount.'''
daylistidx = self.daycount_from_gamestart % len(self.days)
return self.days[daylistidx]
@property
def month_number(self):
return self._month + 1
@property
def month(self):
return self.month_names[self._month]
@property
def lunarprogress(self):
'''Returns the progress in the lunar cycle since new moon as percentage.
'''
newmoonidx = self.newmoonday - 1
dayidx = self.daycount_from_gamestart - newmoonidx
moonidx = dayidx % self.mooncycle
moondays = moonidx + 1
percentage = moondays * 100.0 / self.mooncycle
return int(round(percentage))
@property
def moonphase(self):
'''Returns the lunar phase according to daycount.
Phases:
new moon -> waxing crescent -> first quater -> waxing moon ->
full moon -> waning moon -> last quarter -> waning crescent -> ...
'''
# calculate days into the cycle
newmoonidx = self.newmoonday - 1
dayidx = self.daycount_from_gamestart - newmoonidx
moonidx = dayidx % self.mooncycle
moondays = moonidx + 1
# substract the number of named days
unnamed_days = self.mooncycle - 4
# calculate the days per quarter
quarter = unnamed_days / 4.0
# determine phase
if moonidx<1:
phase = "new moon"
elif moonidx<(quarter+1):
phase = "waxing crescent"
elif moonidx<(quarter+2):
phase = "first quarter"
elif moonidx<(2*quarter+2):
phase = "waxing moon"
elif moonidx<(2*quarter+3):
phase = "full moon"
elif moonidx<(3*quarter+3):
phase = "waning moon"
elif moonidx<(3*quarter+4):
phase = "last quarter"
else:
phase = "waning crescent"
return phase
@property
def last_day_of_the_month(self):
if self.leapyear == self.year and self._month == 1:
return self.day == self.days_count[self._month] + 1
else:
return self.day == self.days_count[self._month]
@property
def string(self):
return "(%s) - %s %d %d"%(self.weekday, self.month, self.day, self.year)
def next(self, days=1):
"""
Next day counter.
Now supports skipping.
"""
self.daycount_from_gamestart += days
while days:
self.day += 1
days -= 1
if self.leapyear == self.year and self._month == 1:
if self.day > self.days_count[self._month] + 1:
self._month += 1
self.day = 1
self.leapyear += 4
elif self.day > self.days_count[self._month]:
self._month += 1
self.day = 1
if self._month > 11:
self._month = 0
self.year += 1
screen calendar_testing:
vbox:
xminimum 500
xfill True
spacing 10
align(0.5, 0.1)
text ("Day: %d"%calendar.game_day)
text ("Week: %d"%calendar.game_week)
text ("Date: %s"%calendar.string)
text ("Next Leap Year: %s"%calendar.leapyear)
text ("Lunar Progress: %d%%"%calendar.lunarprogress)
text ("Moon Phase: %s"%calendar.moonphase.capitalize())
text ("Last day of the month: %s"%calendar.last_day_of_the_month)
You will need pictures, representing stuff for images (just confirming if you are aware of that). If you just want text, that overlay should be different. (ui.text only) This does make a hell of a sense to do for the moonphase. Rest is likely to look better with nice font and a transform, less work as well.
I find it hard to believe that you have image for every possibly of what the string returns, it doesn't seem possible. Also, using overlay is outdated, screen will do the same with better syntax.
With new code:
calendar.game_day # Days player spent in game
calendar.game_week # Weeks player spent in game
calendar.weekday # Day of week in English
calendar.month_number # Number of a month
calendar.month # Name of the month
calendar.lunarprogress # Percent of the lunar progress as a number
calendar.moonphase # phase of a moon in English, without capitals
calendar.last_day_of_the_month # boolean (True/False)
calendar.string # date in a format as you see on the screen.
Code: Select all
init python: #Want to change this block so it works with your code
show_date = False
def date_overlay():
if show_date:
ui.image ("%d" %calendar.game_day + ".png", xalign=1.0, yalign=0.035)
ui.image ("%d" %calendar.month + ".png", xalign=0.965, yalign=0.0)
# ui.image ("%s" %calendar.string + ".png", xalign=1.0, yalign=0.0) < -- Does not seem possible, to many pictures... unless it's a short game.
ui.text(calendar.string, xalign=1.0, yalign=0.0)
ui.image ("%s" %calendar.moonphase + ".png", xalign=0.0, yalign=0.0)
ui.text(calendar.year, xalign=0.7, size=20)
config.overlay_functions.append(date_overlay)
Fixed code.
daikiraikimi wrote:
To make sure I always return from a weekly activity if it's the last day of the month:
Code: Select all
##############################################################################
# Weekly Activities
#
# This file is used to store the players activity choice for each week. Events
# are called from within each activity.
## SCHOOL
label Art:
$ calendar.next() #This will causes the calendar to advance by one day.
"You go to the forest in the back of the school to draw."
call check_events #check to see if any events have been triggered.
if current_day < 7: #want to make this if the current day < 7 AND it is not the last day of the month.
$ current_day += 1
jump Art
return
Maybe:
Code: Select all
if calendar.game_day % 7 != 0 and not calendar.last_day_of_the_month:
jump Art
This code will make sure that game jumps to Art as long as it is not last day of the month and it's not 7th, 14th, 23rd etc. day since player has started the game.
============
Having said that:
To make sure I always return from a weekly activity if it's the last day of the month:
if calendar.last_day_of_the_month:
jump (or call) Month_Report
Code: Select all
if current_day < 7: #want to make this if the current day < 7 AND it is not the last day of the month.
$ current_day += 1
jump Art
I do not understand this code, bigger than 7 of what? Maybe you've meant something like:
Code: Select all
if calendar.weekday != "Sunday":
...
? So every 7th day of the week, you get to pick something again (this should not be in Art label than, should be in the control label).
daikiraikimi wrote:
And in the event checker:
Code: Select all
label check_events:
"This function checks to see if any events have been triggered."
# if it is September 30th:
# jump Harvest_Festival
# if moon_phase = "full moon":
# insanity += 5
return
Very easy to understand what you want here:
Code: Select all
if calendar.moonphase == "full moon":
$ insanity += 5
Code: Select all
if calendar.month == "September" and calendar.day == 30:
jump Harvest_Festival
daikiraikimi wrote:I'm using 6.16.5 which was released in December... Is there a newer version I don't know of? This one is already awesome, especially since RAPT is rolled into it.
Yeap, but still only on the release channel.