@@ -1,12 +1,47 @@ if not sorcery then - sorcery = { data = { + sorcery = { + lib = { tbl=dofile('lib/tbl.lua') }; + } + sorcery.data = { calendar = dofile('data/calendar.lua'); signs = dofile('data/signs.lua'); - } } + } end -sorcery.calendar = {} +sorcery.calendar = { + moon_phases = { + [0] = 'New'; + [0.125] = 'Waxing Crescent'; + [0.25] = 'First Quarter'; + [0.375] = 'Waxing Gibbous'; + [0.5] = 'Full'; + [0.625] = 'Waning Gibbous'; + [0.75] = 'Last Quarter'; + [0.875] = 'Waning Crescent'; + }; + timesofday = { + [0.00] = 'Midnight'; + [0.10] = 'Early Morning'; + [0.25] = 'Morning'; + [0.50] = 'Noon'; + [0.65] = 'Afternoon'; + [0.80] = 'Evening'; + [0.90] = 'Late Evening'; + }; +} + +sorcery.calendar.contmatch = function(tbl,f) + local r + if f>=1 then f = f - math.floor(f) end + sorcery.lib.tbl.each_o(tbl, function(phase,point) + if point <= f + then r=phase + else return nil, false + end + end) + return r +end sorcery.calendar.stats = function(style) if not style then style = sorcery.data.calendar.default end local s = sorcery.data.calendar.styles[style] @@ -27,8 +62,9 @@ local day_of_year = day % s.days_in_year; local day_of_moon = day_of_year % s.days_in_moon; local day_of_week = day_of_moon % s.days_in_week; + local moon_days = sorcery.data.calendar.days_per_lunar_cycle return { day_of_year = 1 + day_of_year; day_of_moon = 1 + day_of_moon; @@ -38,12 +74,14 @@ moon_of_year = 1 + math.floor(day_of_year / s.days_in_moon); year = math.floor(day / s.days_in_year); moons_passed = math.floor(day / s.days_in_moon); weeks_passed = math.floor(day / s.days_in_week); + lunar_cycle = 1 + math.floor(day / moon_days); + lunar_phase = (day % moon_days) / moon_days; } end -sorcery.calendar.stars = function(day,style) +sorcery.calendar.stars = function(day) local periods = math.floor(day / sorcery.data.calendar.days_per_stellar_cycle) local elapsed = 0 local cycle = 1 @@ -63,16 +101,16 @@ cycle = cycle + 1 end end -sorcery.calendar.longdate = function(day) +sorcery.calendar.longdate = function(day,style) if not style then style = sorcery.data.calendar.default end - return sorcery.data.calendar.styles[style].longdate(sorcery.calendar.date(day)) + return sorcery.data.calendar.styles[style].longdate(sorcery.calendar.date(day,style)) end sorcery.calendar.shortdate = function(day,style) if not style then style = sorcery.data.calendar.default end - return sorcery.data.calendar.styles[style].shortdate(sorcery.calendar.date(day)) + return sorcery.data.calendar.styles[style].shortdate(sorcery.calendar.date(day,style)) end sorcery.calendar.stardate = function(day) local s = sorcery.calendar.stars(day) @@ -80,8 +118,8 @@ end -- math.randomseed(os.time()) -- local d = math.random(500,256000) --- print(string.format('%s :: %s in the %s', --- sorcery.calendar.shortdate(d), --- sorcery.calendar.longdate(d), +-- print(string.format('%s :: %s under the %s', +-- sorcery.calendar.shortdate(d,'magisterial'), +-- sorcery.calendar.longdate(d,'magisterial'), -- sorcery.calendar.stardate(d)))