Add gameconfig.lua

master
Wuzzy 2020-08-28 11:17:16 +02:00
parent e96cbf9b18
commit a4a5e5a333
4 changed files with 83 additions and 15 deletions

23
API.md
View File

@ -20,6 +20,27 @@ The calendar mod uses cardinal numbers internally to store the date internally,
this is only done to make calculations a bit simpler. this is only done to make calculations a bit simpler.
`total_days` is also a cardinal number. `total_days` is also a cardinal number.
## Calendar configiguration
In `gameconfig.lua`, there several variables that customize the calendar:
* `calendar.MONTH_DAYS`: Days in a month
* `calendar.month_names`: List of month names
* `calendar.month_names_short`: List of short month names
* `calendar.weekday_names`: List of weekday names
* `calendar.weekday_names_short`: List of short weekday names
* `calendar.FIRST_WEEK_DAY`: Cardinal number of the weekday that
marks the beginning of a week
and the calendar
By default, a year has 12 months with 30 days each,
the months are January to December,
the week has 7 weekdays from Monday to Sunday, starting at Monday.
For convenience, there are also these shortcuts, derived from the other values:
* `calendar.MONTHS`: Number of months in a year
* `calendar.WEEK_DAYS`: Number of days in a week
* `calendar.YEAR_DAYS`: Number of days in a year
## Functions ## Functions
### `calendar.get_date(total_days, ordinal)` ### `calendar.get_date(total_days, ordinal)`
@ -101,3 +122,5 @@ have a tooltip.
* `show_controls`: If `true`, show buttons to change the month and year * `show_controls`: If `true`, show buttons to change the month and year
* `wanted_months`: Which cardinal calendar month to show (default: current one) * `wanted_months`: Which cardinal calendar month to show (default: current one)
* `wanted_years`: Which cardinal calendar year to show (default: current one) * `wanted_years`: Which cardinal calendar year to show (default: current one)

View File

@ -5,7 +5,15 @@ This mod adds a simple and customizable calender system.
The calendar supports days, weeks, months and years. The calendar supports days, weeks, months and years.
Holidays are also supported. Holidays are also supported.
By default, a year has 12 months with 30 days each, with a total of 360 days. To make things simpler, all months have the same length.
By default, a year has 12 months (January to December) with 30 days each.
There are 7 weekdays from Monday to Sunday, starting at Monday.
The calendar starts at Day 1, Month 1 (January), Year 1.
## Customizing the calendar
If you want to customize the calendar (e.g. change the length of months),
read the text file `API.md`.
## Info for programmers ## Info for programmers
See `API.md`. See `API.md`.
@ -15,3 +23,4 @@ Minetest stores the number of elapsed days in the world files and it
can be queried in Lua via `minetest.get_day_count()`. can be queried in Lua via `minetest.get_day_count()`.
The day count is stored in the world directory under `env_meta.txt` as The day count is stored in the world directory under `env_meta.txt` as
`day_count`. `day_count`.

45
gameconfig.lua Normal file
View File

@ -0,0 +1,45 @@
-- Get translator
local S
if minetest.get_translator then
S = minetest.get_translator("calendar")
else
S = function(s) return s end
end
----------------------------------
-- BEGINNING OF CALENDAR CONFIG --
----------------------------------
-- Number of days in a month
calendar.MONTH_DAYS = 30
-- List of long month names
-- (also determines the number of months in a year)
calendar.month_names = {
S('January'), S('February'), S('March'), S('April'),
S('May'), S('June'), S('July'), S('August'),
S('September'), S('October'), S('November'), S('December')
}
-- Short month names
-- (must have same length as `calendar.month.names`)
calendar.month_names_short = {
S('Jan'), S('Feb'), S('Mar'), S('Apr'),
S('May'), S('Jun'), S('Jul'), S('Aug'),
S('Sep'), S('Oct'), S('Nov'), S('Dec')
}
-- Long week day names
-- (also determines the number of days in a week)
calendar.weekday_names = {
S("Monday"), S("Tuesday"), S("Wednesday"),
S("Thursday"), S("Friday"), S("Saturday"), S("Sunday")
}
-- Short week day names
-- (must have same length as `calendar.weekday_names`)
calendar.weekday_names_short = {
S("Mo"), S("Tu"), S("We"), S("Th"), S("Fr"), S("Sa"), S("Su")
}
-- Cardinal number of the week day that marks the beginning of a week
calendar.FIRST_WEEK_DAY = 0

View File

@ -7,23 +7,14 @@ else
end end
local F = minetest.formspec_escape local F = minetest.formspec_escape
calendar.MONTH_DAYS = 30 dofile(minetest.get_modpath("calendar").."/gameconfig.lua")
-- Long month names -- Number of months in a year
calendar.month_names = { S('January'), S('February'), S('March'), S('April'), S('May'), S('June'), S('July'), S('August'), S('September'), S('October'), S('November'), S('December') }
--calendar.month_names = { S('Spring'), S('Summer'), S('Harvest'), S('Winter') }
-- Short month names
calendar.month_names_short = { S('Jan'), S('Feb'), S('Mar'), S('Apr'), S('May'), S('Jun'), S('Jul'), S('Aug'), S('Sep'), S('Oct'), S('Nov'), S('Dec') }
--calendar.month_names_short = { S('Spr'), S('Sum'), S('Har'), S('Win') }
calendar.MONTHS = #calendar.month_names calendar.MONTHS = #calendar.month_names
-- Number of days in a week
calendar.YEAR_DAYS = calendar.MONTHS * calendar.MONTH_DAYS
-- Week day names
calendar.weekday_names = { S("Monday"), S("Tuesday"), S("Wednesday"), S("Thursday"), S("Friday"), S("Saturday"), S("Sunday") }
calendar.weekday_names_short = { S("Mo"), S("Tu"), S("We"), S("Th"), S("Fr"), S("Sa"), S("Su") }
calendar.WEEK_DAYS = #calendar.weekday_names calendar.WEEK_DAYS = #calendar.weekday_names
calendar.FIRST_WEEK_DAY = 0 -- Number of days in a year
calendar.YEAR_DAYS = calendar.MONTHS * calendar.MONTH_DAYS
local holidays = {} local holidays = {}