-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
local MINIMUM_SPEED = 0.125 | ||
local MAXIMUM_SPEED = 64 | ||
|
||
local function timewarp(event, mult) | ||
local player = game.players[event.player_index] | ||
if not (player and player.permission_group and player.permission_group.allows_action(defines.server_command)) then | ||
return | ||
end | ||
|
||
local msg = "timecontrol.speed-changed" | ||
|
||
local oldspeed = game.speed | ||
local newspeed | ||
|
||
if mult == 0 then | ||
newspeed = 1 | ||
msg = "timecontrol.speed-reset" | ||
else | ||
newspeed = game.speed * mult | ||
if newspeed < MINIMUM_SPEED then | ||
newspeed = MINIMUM_SPEED | ||
elseif newspeed > MAXIMUM_SPEED then | ||
newspeed = MAXIMUM_SPEED | ||
end | ||
end | ||
|
||
-- If the effective speed wouldn't change, end now to avoid console spam. | ||
if newspeed == oldspeed then | ||
return | ||
end | ||
|
||
if #game.players > 1 then | ||
msg = msg .. "-by" | ||
end | ||
|
||
game.print{msg, newspeed, player.name } | ||
game.speed = newspeed | ||
end | ||
|
||
script.on_event("timecontrol_normal", function(event) return timewarp(event, 0) end) | ||
script.on_event("timecontrol_slower", function(event) return timewarp(event, 0.5) end) | ||
script.on_event("timecontrol_faster", function(event) return timewarp(event, 2.0) end) | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-- Add keybindings | ||
|
||
data:extend({ | ||
{ | ||
type = "custom-input", | ||
name = "timecontrol_normal", | ||
key_sequence = "BACKSPACE", | ||
order = 'a-z', | ||
}, | ||
{ | ||
type = "custom-input", | ||
name = "timecontrol_faster", | ||
key_sequence = "KEY62", | ||
order = 'a-a', | ||
-- consuming = "all", | ||
}, | ||
{ | ||
type = "custom-input", | ||
name = "timecontrol_slower", | ||
key_sequence = "KEY61", | ||
order = 'a-b', | ||
-- consuming = "all" | ||
}, | ||
}) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "TimeControl", | ||
"version": "0.1.0", | ||
"title": "Time Control", | ||
"author": "Dewin", | ||
"contact": "https://github.com/dewiniaid/TimeControl", | ||
"homepage": "https://github.com/dewiniaid/TimeControl", | ||
"factorio_version": "0.15", | ||
"dependencies": ["base >= 0.15"], | ||
"description": "Adds bindings for adjusting game speed." | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[timecontrol] | ||
speed-changed=Game speed changed to __1__x. | ||
speed-changed-by=__2__ changed game speed to __1__x. | ||
speed-reset=Game speed reset to normal . | ||
speed-reset-by=Game speed reset to normal by __2__. | ||
|
||
[controls] | ||
timecontrol_normal=Normal speed | ||
timecontrol_faster=Faster | ||
timecontrol_slower=Slower |