Skip to content

Commit

Permalink
Refactor api, implement CREL vanilla+TR scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaakma committed Sep 1, 2024
1 parent 2fe4a1a commit e80f9ed
Show file tree
Hide file tree
Showing 34 changed files with 1,654 additions and 839 deletions.
12 changes: 12 additions & 0 deletions Data Files/Chargen Scenarios-metadata.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "Chargen Scenarios"
description = "An alternate start / chargen overhaul mod for Morrowind."
repository = "https://github.com/jhaakma/chargenScenarios"
authors = [ "Merlord",]
version = "0.0.5"

[dependencies]
assets = [ "MWSE\\mods\\mer\\RightClickMenuExit",]

[dependencies.mwse]
buildnumber = 4093

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,34 @@
To use this
]]
local common = require('mer.chargenScenarios.common')
local logger = common.createLogger("registerLocations")
local Controls = require("mer.chargenScenarios.util.Controls")
local Location = require("mer.chargenScenarios.component.Location")


local luaLocationTemplate = [[
["${id}"] = {
position = {${posx}, ${posy}, ${posz}},
orientation =${orz},
cell = "${cell}"
},
]]


local function addLocation(locationToAdd, name)
common.mcmConfig.locations[name] = locationToAdd
common.log:debug("Storing location: %s", name)
common.log:debug(json.encode(locationToAdd))
common.log:debug("player position: ")
common.log:debug(json.encode(tes3.player.position))
common.log:debug("player orientation: ")
common.log:debug(json.encode(tes3.player.orientation))
common.saveConfig()
logger:info("Location: ")
local locationString = luaLocationTemplate:
gsub("${id}", name):
gsub("${posx}", locationToAdd.position[1]):
gsub("${posy}", locationToAdd.position[2]):
gsub("${posz}", locationToAdd.position[3]):
gsub("${orz}", locationToAdd.orientation[3])
if tes3.player.cell.isInterior then
locationString = locationString:gsub("${cell}", locationToAdd.cell.id)
else
locationString = locationString:gsub("${cell}", "nil")
end
mwse.log(locationString)
end

local function registerLocation()
Expand All @@ -25,57 +44,57 @@ local function registerLocation()
math.floor(tes3.player.orientation.y),
math.floor(tes3.player.orientation.z),
},
cell = tes3.player.cell.id
cell = tes3.player.cell
}
timer.delayOneFrame(function()
local menuId = tes3ui.registerID("Location_Register_Menu")
local menu = tes3ui.createMenu{ id = menuId, fixedFrame = true }
menu.minWidth = 400
menu.alignX = 0.5
menu.alignY = 0
menu.alignX = 0.5 ---@diagnostic disable-line
menu.alignY = 0 ---@diagnostic disable-line
menu.autoHeight = true
local name = { name = ""}
local t = { name = ""}
mwse.mcm.createTextField(
menu,
{
label = "Enter name of location:",
variable = mwse.mcm.createTableVariable{
id = "name",
table = name
table = t
},
callback = function()
if common.mcmConfig.locations[name.name] then
if Location.get(t.name) then
tes3ui.showMessageMenu{
message = "Location with this id already exists.",
buttons = {
{
text = "Overwrite",
callback = function()
addLocation(location, name.name)
tes3ui.leaveMenuMode(menuId)
addLocation(location, t.name)
tes3ui.leaveMenuMode()
tes3ui.findMenu(menuId):destroy()
end
},
{
text = "Rename",
callback = function()
tes3ui.leaveMenuMode(menuId)
tes3ui.leaveMenuMode()
tes3ui.findMenu(menuId):destroy()
registerLocation()
end,
},
{
text = "Cancel",
callback = function()
tes3ui.leaveMenuMode(menuId)
tes3ui.leaveMenuMode()
tes3ui.findMenu(menuId):destroy()
end
}
}
}
else
addLocation(location, name.name)
tes3ui.leaveMenuMode(menuId)
addLocation(location, t.name)
tes3ui.leaveMenuMode()
tes3ui.findMenu(menuId):destroy()
end
end
Expand All @@ -85,13 +104,10 @@ local function registerLocation()
end)
end




---@param e keyDownEventData
local function onKeyDown(e)
if common.mcmConfig.registerLocationsEnabled then
if common.isKeyPressed(e, common.mcmConfig.registerLocationsHotKey) then
if common.config.mcm.registerLocationsEnabled then
if Controls.isKeyPressed(e, common.config.mcm.registerLocationsHotKey) then
tes3ui.showMessageMenu{
message = "Register current position/orientation/cell as a starting location?",
buttons = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
--Controllers for the scenario builder
require('mer.chargenScenarios.ScenarioBuilder.controllers.registerLocations')
require('mer.chargenScenarios.ScenarioBuilder.controllers.registerClutter')
--Register existing scenarios
require('mer.chargenScenarios.ScenarioBuilder.scenarios').registerScenarios()

--MCM
local mcm = require('mer.chargenScenarios.ScenarioBuilder.mcm')
event.register("modConfigReady", mcm.registerModConfig)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local common = require('mer.chargenScenarios.common')
local config = require('mer.chargenScenarios.config')
local modName = "Chargen Scenario Builder"
local mcmConfig = common.mcmConfig
local mcmConfig = common.config.mcm
--MCM MENU
local this = {}

Expand Down Expand Up @@ -37,33 +37,12 @@ local function createSettingsPage(template)
variable = mwse.mcm.createTableVariable{ id = "registerClutterHotKey", table = mcmConfig},
allowCombinations = true,
}


end

local function createDevOptionsPage(template)
local devOptions = template:createSideBarPage("Development Options")
devOptions.description = "Tools for debugging etc."

devOptions:createDropdown{
label = "Log Level",
description = "Set the logging level for common.log:debug. Keep on INFO unless you are debugging.",
options = {
{ label = "TRACE", value = "TRACE"},
{ label = "DEBUG", value = "DEBUG"},
{ label = "INFO", value = "INFO"},
{ label = "ERROR", value = "ERROR"},
{ label = "NONE", value = "NONE"},
},
variable = mwse.mcm.createTableVariable{
id = "logLevel",
table = mcmConfig
},
callback = function(self)
common.log:setLogLevel(self.variable.value)
end
}

--Testing
devOptions:createOnOffButton{
label = "Enable Unit Tests",
Expand Down
Loading

0 comments on commit e80f9ed

Please sign in to comment.