slight refactor

This commit is contained in:
Lilian Jónsdóttir 2020-09-12 13:58:53 -07:00
parent f2e3846fe1
commit 188257cdee
3 changed files with 18 additions and 8 deletions

View file

@ -15,16 +15,14 @@ function this.log(str) mwse.log("[%s] %s", this.modName, str) end
function this.changedLayout(layout) function this.changedLayout(layout)
local changed = false local changed = false
if keys[layout] and (#keys[layout].lowercase == 256 and #keys[layout].uppercase == 256) then if keys[layout] and (#keys[layout].lowercase == 256 and #keys[layout].uppercase == 256) then
-- Thanks NullCascade -- Thanks NullCascade
mwse.memory.writeBytes({address = 0x775148, bytes = keys[layout].lowercase}) mwse.memory.writeBytes({address = 0x775148, bytes = keys[layout].lowercase})
mwse.memory.writeBytes({address = 0x775248, bytes = keys[layout].uppercase}) mwse.memory.writeBytes({address = 0x775248, bytes = keys[layout].uppercase})
changed = true changed = true
else
local message = "Bad keys.lua file, please re-install."
this.log(message)
tes3.messageBox(string.format("(%s) %s", this.modName, message))
end end
return changed return changed
end end

View file

@ -2,9 +2,16 @@ local common = require("celediel.Keyboard Layout Changer.common")
local config = require("celediel.Keyboard Layout Changer.config").getConfig() local config = require("celediel.Keyboard Layout Changer.config").getConfig()
local function onInitialized() local function onInitialized()
local message = ""
if common.changedLayout(config.keyboardLayout) then if common.changedLayout(config.keyboardLayout) then
common.log("Changed layout to " .. config.keyboardLayout) message = "Changed layout to " .. config.keyboardLayout
else
message = "Bad keys.lua file, please re-install."
tes3.messageBox(string.format("(%s) %s", common.modName, message))
end end
common.log(message)
end end
event.register("initialized", onInitialized) event.register("initialized", onInitialized)

View file

@ -25,12 +25,17 @@ local function createOptions()
end end
local function applyLayout() local function applyLayout()
local message = ""
if common.changedLayout(config.keyboardLayout) then if common.changedLayout(config.keyboardLayout) then
local message = "Changed layout to " .. config.keyboardLayout message = "Changed layout to " .. config.keyboardLayout
else
message = "Bad keys.lua file, length must be 256."
end
tes3.messageBox(message) tes3.messageBox(message)
common.log(message) common.log(message)
end end
end
local template = mwse.mcm.createTemplate(common.modName) local template = mwse.mcm.createTemplate(common.modName)
template:saveOnClose(common.configString, config) template:saveOnClose(common.configString, config)