From a4a5e5a333ee65278f0e38779cc788c172b7ca06 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 28 Aug 2020 11:17:16 +0200 Subject: [PATCH] Add gameconfig.lua --- API.md | 23 +++++++++++++++++++++++ README.md | 11 ++++++++++- gameconfig.lua | 45 +++++++++++++++++++++++++++++++++++++++++++++ init.lua | 19 +++++-------------- 4 files changed, 83 insertions(+), 15 deletions(-) create mode 100644 gameconfig.lua diff --git a/API.md b/API.md index 1a26d86..950af84 100644 --- a/API.md +++ b/API.md @@ -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. `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 ### `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 * `wanted_months`: Which cardinal calendar month to show (default: current one) * `wanted_years`: Which cardinal calendar year to show (default: current one) + + diff --git a/README.md b/README.md index 0d904cf..c5ec034 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,15 @@ This mod adds a simple and customizable calender system. The calendar supports days, weeks, months and years. 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 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()`. The day count is stored in the world directory under `env_meta.txt` as `day_count`. + diff --git a/gameconfig.lua b/gameconfig.lua new file mode 100644 index 0000000..6d6cbf5 --- /dev/null +++ b/gameconfig.lua @@ -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 diff --git a/init.lua b/init.lua index 8945dcd..5983a27 100644 --- a/init.lua +++ b/init.lua @@ -7,23 +7,14 @@ else end local F = minetest.formspec_escape -calendar.MONTH_DAYS = 30 +dofile(minetest.get_modpath("calendar").."/gameconfig.lua") --- Long month names -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') } +-- Number of months in a year calendar.MONTHS = #calendar.month_names - -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") } +-- Number of days in a week 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 = {}