Skip to content

Commit

Permalink
Files initial release.
Browse files Browse the repository at this point in the history
  • Loading branch information
dewiniaid committed Dec 5, 2017
1 parent 43b6a5f commit 98d337a
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
44 changes: 44 additions & 0 deletions control.lua
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)


24 changes: 24 additions & 0 deletions data.lua
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"
},
})
11 changes: 11 additions & 0 deletions info.json
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."
}
10 changes: 10 additions & 0 deletions locale/en/locale.cfg
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

0 comments on commit 98d337a

Please sign in to comment.