Created
April 1, 2011 00:35
-
-
Save melinath/897547 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local game_events = wesnoth.game_events | |
| local time_utils = wesnoth.require "~/add-ons/Brent/lua/time/utils.lua" | |
| -- timedelta is the local time change per turn | |
| timedelta = 4 | |
| turns_per_day = 6 | |
| local old_on_load = game_events.on_load | |
| function game_events.on_load(cfg) | |
| turns_per_day = cfg.turns_per_day or turns_per_day | |
| timedelta = 24/turns_per_day | |
| old_on_load(cfg) | |
| end | |
| local old_on_save = game_events.on_save | |
| function game_events.on_save() | |
| local cfg = old_on_save() | |
| table.insert(cfg, {"time", {turns_per_day=turns_per_day}}) | |
| return cfg | |
| end | |
| local old_on_event = game_events.on_event | |
| function game_events.on_event(name) | |
| if name == "new turn" then | |
| local time = time_utils.get_time() | |
| time_utils.set_time(time + timedelta) | |
| end | |
| if old_on_event ~= nil then old_on_event(name) end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local time_utils = {} | |
| local time_variable = 'time' | |
| function time_utils.get_time() | |
| return wesnoth.get_variable(time_variable) or 0 | |
| end | |
| function time_utils.set_time(time) | |
| wesnoth.set_variable(time_variable, time) | |
| end | |
| return time_utils |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment