mirror of
https://github.com/OpenMW/openmw.git
synced 2025-12-23 22:23:09 +00:00
Fixes in calendar.lua
This commit is contained in:
parent
618b912a20
commit
f442e2831e
5 changed files with 33 additions and 16 deletions
|
|
@ -6,6 +6,7 @@ set(BUILTIN_DATA_MW_FILES
|
||||||
# Month names and date formatting
|
# Month names and date formatting
|
||||||
l10n/Calendar/de.yaml
|
l10n/Calendar/de.yaml
|
||||||
l10n/Calendar/en.yaml
|
l10n/Calendar/en.yaml
|
||||||
|
l10n/Calendar/gmst.yaml
|
||||||
l10n/Calendar/ru.yaml
|
l10n/Calendar/ru.yaml
|
||||||
l10n/Calendar/sv.yaml
|
l10n/Calendar/sv.yaml
|
||||||
l10n/Calendar/fr.yaml
|
l10n/Calendar/fr.yaml
|
||||||
|
|
@ -15,6 +16,9 @@ set(BUILTIN_DATA_MW_FILES
|
||||||
|
|
||||||
# L10n for OpenMW menus and non-game-specific messages
|
# L10n for OpenMW menus and non-game-specific messages
|
||||||
l10n/OMWEngine/gmst.yaml
|
l10n/OMWEngine/gmst.yaml
|
||||||
|
|
||||||
|
# Game-specific settings for calendar.lua
|
||||||
|
openmw_aux/calendarconfig.lua
|
||||||
)
|
)
|
||||||
|
|
||||||
foreach (f ${BUILTIN_DATA_MW_FILES})
|
foreach (f ${BUILTIN_DATA_MW_FILES})
|
||||||
|
|
|
||||||
7
files/data-mw/openmw_aux/calendarconfig.lua
Normal file
7
files/data-mw/openmw_aux/calendarconfig.lua
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
return {
|
||||||
|
monthsDuration = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
|
||||||
|
daysInWeek = 7,
|
||||||
|
startingYear = 427,
|
||||||
|
startingYearDay = 227,
|
||||||
|
startingWeekDay = 1,
|
||||||
|
}
|
||||||
|
|
@ -58,6 +58,7 @@ set(BUILTIN_DATA_FILES
|
||||||
openmw_aux/util.lua
|
openmw_aux/util.lua
|
||||||
openmw_aux/time.lua
|
openmw_aux/time.lua
|
||||||
openmw_aux/calendar.lua
|
openmw_aux/calendar.lua
|
||||||
|
openmw_aux/calendarconfig.lua
|
||||||
openmw_aux/ui.lua
|
openmw_aux/ui.lua
|
||||||
|
|
||||||
builtin.omwscripts
|
builtin.omwscripts
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,13 @@
|
||||||
|
|
||||||
local core = require('openmw.core')
|
local core = require('openmw.core')
|
||||||
local time = require('openmw_aux.time')
|
local time = require('openmw_aux.time')
|
||||||
|
local conf = require('openmw_aux.calendarconfig')
|
||||||
local l10n = core.l10n('Calendar')
|
local l10n = core.l10n('Calendar')
|
||||||
|
|
||||||
local monthsDuration = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
|
local monthsDuration = conf.monthsDuration
|
||||||
local daysInWeek = 7
|
|
||||||
local daysInYear = 0
|
local daysInYear = 0
|
||||||
for _, d in ipairs(monthsDuration) do daysInYear = daysInYear + d end
|
for _, d in ipairs(monthsDuration) do daysInYear = daysInYear + d end
|
||||||
|
|
||||||
local startingYear = 427
|
|
||||||
local startingYearDay = 227
|
|
||||||
local startingWeekDay = 1
|
|
||||||
|
|
||||||
local function gameTime(t)
|
local function gameTime(t)
|
||||||
if not t then
|
if not t then
|
||||||
return core.getGameTime()
|
return core.getGameTime()
|
||||||
|
|
@ -43,10 +39,10 @@ local function formatGameTime(formatStr, timestamp)
|
||||||
timestamp = timestamp or core.getGameTime()
|
timestamp = timestamp or core.getGameTime()
|
||||||
|
|
||||||
local t = {}
|
local t = {}
|
||||||
local day = math.floor(timestamp / time.day)
|
local day = math.floor(timestamp / time.day) + conf.startingYearDay - 1
|
||||||
t.year = math.floor(day / daysInYear) + startingYear
|
t.year = math.floor(day / daysInYear) + conf.startingYear
|
||||||
t.yday = (day + startingYearDay - 1) % daysInYear + 1
|
t.yday = day % daysInYear + 1
|
||||||
t.wday = (day + startingWeekDay - 1) % daysInWeek + 1
|
t.wday = (day + conf.startingWeekDay - conf.startingYearDay) % conf.daysInWeek + 1
|
||||||
timestamp = timestamp % time.day
|
timestamp = timestamp % time.day
|
||||||
t.hour = math.floor(timestamp / time.hour)
|
t.hour = math.floor(timestamp / time.hour)
|
||||||
timestamp = timestamp % time.hour
|
timestamp = timestamp % time.hour
|
||||||
|
|
@ -75,10 +71,10 @@ local function formatGameTime(formatStr, timestamp)
|
||||||
if tag == '%M' then return string.format('%02d', t.min) end
|
if tag == '%M' then return string.format('%02d', t.min) end
|
||||||
if tag == '%m' then return string.format('%02d', t.month) end
|
if tag == '%m' then return string.format('%02d', t.month) end
|
||||||
if tag == '%p' then
|
if tag == '%p' then
|
||||||
if t.hour > 0 and t.hour <= 12 then
|
if t.hour >= 0 and t.hour < 12 then
|
||||||
return 'am'
|
return l10n('am')
|
||||||
else
|
else
|
||||||
return 'pm'
|
return l10n('pm')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if tag == '%S' then return string.format('%02d', t.sec) end
|
if tag == '%S' then return string.format('%02d', t.sec) end
|
||||||
|
|
@ -122,7 +118,7 @@ return {
|
||||||
|
|
||||||
--- The number of days in a week
|
--- The number of days in a week
|
||||||
-- @field [parent=#calendar] #number daysInWeek
|
-- @field [parent=#calendar] #number daysInWeek
|
||||||
daysInWeek = daysInWeek,
|
daysInWeek = conf.daysInWeek,
|
||||||
|
|
||||||
--- The number of days in a month
|
--- The number of days in a month
|
||||||
-- @function [parent=#calendar] daysInMonth
|
-- @function [parent=#calendar] daysInMonth
|
||||||
|
|
@ -153,7 +149,7 @@ return {
|
||||||
-- @param dayIndex
|
-- @param dayIndex
|
||||||
-- @return #string
|
-- @return #string
|
||||||
weekdayName = function(d)
|
weekdayName = function(d)
|
||||||
return l10n('weekday' .. ((d-1) % daysInWeek + 1))
|
return l10n('weekday' .. ((d-1) % conf.daysInWeek + 1))
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
9
files/data/openmw_aux/calendarconfig.lua
Normal file
9
files/data/openmw_aux/calendarconfig.lua
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
return {
|
||||||
|
monthsDuration = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
|
||||||
|
daysInWeek = 7,
|
||||||
|
|
||||||
|
-- It is the day of OpenMW 0.1.0 release, we use it as default starting date
|
||||||
|
startingYear = 2008,
|
||||||
|
startingYearDay = 151,
|
||||||
|
startingWeekDay = 0,
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue