PDA

View Full Version : Calendar modification help



OffRoadSP
January 31st, 2019, 06:38
Hello All,

I am relatively new to Fantasy Grounds and this is my first time posting in the forums. If this question is in the wrong place, I apologize and ask that you point me in the correct direction. I also hope my question is not too stupid...

As to my question: I would like to modify the Golarion calendar to include a leap year every 8 years rather than 4, as the source material indicates. How would I go about modifying the leap year frequency in the db.xml file?

I have reviewed several threads here over the last hour that point to custom calendars but none seem to answer this question specifically. What I have done so far: I have copied the calendars.mod file to a new location, changed the file extension to .zip, extracted the files, and opened the db.xml in Notepad. I'm looking at the code for the Golarion calendar, but nothing is jumping out at me as to what part controls the leap year frequency. Any advice?

I appreciate any help that can be provided.

damned
January 31st, 2019, 08:02
Hey OffRoadSP

Anything non repeating/static every week/month/year is usually done in Lua.
I dont believe that the included Gregorian calendar does do leap years at all.

OffRoadSP
January 31st, 2019, 08:14
Thanks for the reply, damned!

Sorry if this is a dumb question, but... what is LUA?

It does appear that the Gregorian calendar does include a leap year though.

Edit: OH! But you gave me an idea. Could the interval be determined by the following? If so, are there other "period var"s that could change this?

<periodvarcalc type="string">gregorian</periodvarcalc>

(If it's not obvious, coding is not one of my skillsets, heh.)

damned
January 31st, 2019, 08:22
Have a look in CoreRPG (unpack it)
\scripts\manager_calendar.lua
and search for the many Calendar mods that Andraax has helped people with to better understand how to do the Lua side.

OffRoadSP
January 31st, 2019, 08:35
I found the data you mentioned in the CoreRPG.pak file. Thank you very much! This has been extremely helpful. I would never have thought to look under the ruleset itself for this piece. I will search out Andraax's threads for further info.

Edit: So, I think I found the necessary code I need to change. I'm hoping someone could just double check me in case I'm way off.

In manager_calendar.lua, I assume I need to change the (nYear % 4) == 0 to (nYear % 8) == 0, does that seem right? Original section below for reference/context:

function calcGregorianMonthVar(nYear, nMonth)
if nMonth == 2 then
local nYear = DB.getValue("calendar.current.year", 0);
if (nYear % 400) == 0 then
return 1;
elseif (nYear % 100) == 0 then
return 0;
elseif (nYear % 4) == 0 then
return 1;

Edit 2: Well, I just learned something new about leap years in the Gregorian calendar. I was curious about the lines of text regarding nYear 400 & 100, and who'd-a-thunk... I never knew years divisible by 100 but not 400 did not contain a leap day. The more you know!

So... based on this, in addition to what I said above, I need to remove:

(nYear % 400) == 0 then
return 1;
elseif (nYear % 100) == 0 then
return 0;

....I know, I'm making this whole calendar tracking thing more difficult than it probably needs to be, but now I'm just determined to figure it out, if for no reason more than to learn more about how Fantasy Grounds works!

Edit 3: SUCCESS!! When I went in and modified it as described, it seemed to work. However something was still off. After a bit of searching I finally noticed that although it did not add a 29th day every 4 years, it still "skipped" ahead a day. So I tried modifying the line of code right above it (it seemed to make sense to), and finally... it worked perfectly!

So thanks again, damned... you steering me in the right direction helped me so much in figuring this out!

Andraax
January 31st, 2019, 12:39
I dont believe that the included Gregorian calendar does do leap years at all.

The included Gregorian calendar code does do leap years, using the pattern defined for Gregorian calendars (every 4 years, except centuries unless the century is a multiple of 400).

damned
January 31st, 2019, 12:41
You have a problem in that 100 is not cleanly divisible by 8... while 400 still is...
You may with every 128 years skip the leap year (no exceptions) for example...

Andraax
January 31st, 2019, 12:41
I found the data you mentioned in the CoreRPG.pak file. Thank you very much! This has been extremely helpful. I would never have thought to look under the ruleset itself for this piece. I will search out Andraax's threads for further info.

You'll want to create and register a new function for your world's calendar rather than modify the ruleset. You can see this in many of the various extensions I've written. Doing it via an extension means you won't have to rewrite it every time CoreRPG updates.

OffRoadSP
January 31st, 2019, 18:26
Thanks, Andraax! I did review some of your threads as well. They helped me understand how the modules and extensions work with each other. I did download some of your custom extensions for examples... I'm hoping I can eventually figure out enough to duplicate what I'm trying to do in an extension.

Andraax
January 31st, 2019, 20:58
Most of my extensions only require a custom "LunarDayHandler" - you'll need to look for one that has leap years, those need a custom "MonthVarHandler".

Actually, here is one that has both: