Differences From
Artifact [f67589c567]:
- File
calendar.lua
— part of check-in
[3f6a913e4e]
at
2020-09-29 12:40:28
on branch trunk
— * remove former hacky registration system, replace with consistent and flexible API; rewrite metal/gem generation to take advantage of this new API; tweaks to init system to enable world-local tweaks to lore and sorcery behavior
* initial documentation commit
* initial steps towards calendar - add default date format, astrolabe; prepare infra for division/melding/transmutation spells, various tweaks and fixes
(user:
lexi,
size: 2475)
[annotate]
[blame]
[check-ins using]
- File
calendar.lua
— part of check-in
[ea6e475e44]
at
2020-10-19 09:52:11
on branch trunk
— continue dev on celestial mechanics, add melding+division spells (resonance), refine itemclasses, add keypunch and punchcards, add paper pulp, add a shitload of visuals, add convenience scripts for working with the wiki, make the flamebolt spell actually useful instead of just a pretty lightshow, add essences, inferno crystal, and other goodies; iterate on wands, lots of shit i can't remember, various bugfixes
(user:
lexi,
size: 3372)
[annotate]
[blame]
[check-ins using]
1 1 if not sorcery then
2 - sorcery = { data = {
2 + sorcery = {
3 + lib = { tbl=dofile('lib/tbl.lua') };
4 + }
5 + sorcery.data = {
3 6 calendar = dofile('data/calendar.lua');
4 7 signs = dofile('data/signs.lua');
5 - } }
8 + }
6 9 end
7 10
8 -sorcery.calendar = {}
11 +sorcery.calendar = {
12 + moon_phases = {
13 + [0] = 'New';
14 + [0.125] = 'Waxing Crescent';
15 + [0.25] = 'First Quarter';
16 + [0.375] = 'Waxing Gibbous';
17 + [0.5] = 'Full';
18 + [0.625] = 'Waning Gibbous';
19 + [0.75] = 'Last Quarter';
20 + [0.875] = 'Waning Crescent';
21 + };
22 + timesofday = {
23 + [0.00] = 'Midnight';
24 + [0.10] = 'Early Morning';
25 + [0.25] = 'Morning';
26 + [0.50] = 'Noon';
27 + [0.65] = 'Afternoon';
28 + [0.80] = 'Evening';
29 + [0.90] = 'Late Evening';
30 + };
31 +}
32 +
33 +sorcery.calendar.contmatch = function(tbl,f)
34 + local r
35 + if f>=1 then f = f - math.floor(f) end
36 + sorcery.lib.tbl.each_o(tbl, function(phase,point)
37 + if point <= f
38 + then r=phase
39 + else return nil, false
40 + end
41 + end)
42 + return r
43 +end
9 44
10 45 sorcery.calendar.stats = function(style)
11 46 if not style then style = sorcery.data.calendar.default end
12 47 local s = sorcery.data.calendar.styles[style]
13 48 local days, moons, weeks = s.days, s.moons, s.weeks
14 49
15 50 return {
................................................................................
24 59
25 60 sorcery.calendar.date = function(day,style)
26 61 local s = sorcery.calendar.stats(style)
27 62
28 63 local day_of_year = day % s.days_in_year;
29 64 local day_of_moon = day_of_year % s.days_in_moon;
30 65 local day_of_week = day_of_moon % s.days_in_week;
66 + local moon_days = sorcery.data.calendar.days_per_lunar_cycle
31 67
32 68 return {
33 69 day_of_year = 1 + day_of_year;
34 70 day_of_moon = 1 + day_of_moon;
35 71 day_of_week = 1 + day_of_week;
36 72 week_of_moon = 1 + math.floor(day_of_moon / s.days_in_week);
37 73 week_of_year = 1 + math.floor(day_of_year / s.days_in_week);
38 74 moon_of_year = 1 + math.floor(day_of_year / s.days_in_moon);
39 75 year = math.floor(day / s.days_in_year);
40 76 moons_passed = math.floor(day / s.days_in_moon);
41 77 weeks_passed = math.floor(day / s.days_in_week);
78 + lunar_cycle = 1 + math.floor(day / moon_days);
79 + lunar_phase = (day % moon_days) / moon_days;
42 80 }
43 81 end
44 82
45 -sorcery.calendar.stars = function(day,style)
83 +sorcery.calendar.stars = function(day)
46 84 local periods = math.floor(day / sorcery.data.calendar.days_per_stellar_cycle)
47 85
48 86 local elapsed = 0
49 87 local cycle = 1
50 88 while true do
51 89 for _, c in pairs(sorcery.data.signs) do
52 90 if c.cycle then
................................................................................
60 98 }
61 99 end
62 100 ::skip::end
63 101 cycle = cycle + 1
64 102 end
65 103 end
66 104
67 -sorcery.calendar.longdate = function(day)
105 +sorcery.calendar.longdate = function(day,style)
68 106 if not style then style = sorcery.data.calendar.default end
69 - return sorcery.data.calendar.styles[style].longdate(sorcery.calendar.date(day))
107 + return sorcery.data.calendar.styles[style].longdate(sorcery.calendar.date(day,style))
70 108 end
71 109
72 110 sorcery.calendar.shortdate = function(day,style)
73 111 if not style then style = sorcery.data.calendar.default end
74 - return sorcery.data.calendar.styles[style].shortdate(sorcery.calendar.date(day))
112 + return sorcery.data.calendar.styles[style].shortdate(sorcery.calendar.date(day,style))
75 113 end
76 114
77 115 sorcery.calendar.stardate = function(day)
78 116 local s = sorcery.calendar.stars(day)
79 117 return string.format('sign of the %s, stellar cycle %u', s.sign.patron, s.cycle)
80 118 end
81 119
82 120 -- math.randomseed(os.time())
83 121 -- local d = math.random(500,256000)
84 --- print(string.format('%s :: %s in the %s',
85 --- sorcery.calendar.shortdate(d),
86 --- sorcery.calendar.longdate(d),
122 +-- print(string.format('%s :: %s under the %s',
123 +-- sorcery.calendar.shortdate(d,'magisterial'),
124 +-- sorcery.calendar.longdate(d,'magisterial'),
87 125 -- sorcery.calendar.stardate(d)))