mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-15 07:41:21 +02:00
Merge pull request #1246 from 1Jamie/fix/gen2-battle-rng-static-damage
This commit is contained in:
@@ -8,11 +8,16 @@ local function quote(value)
|
||||
return "'" .. tostring(value):gsub("'", "'\\''") .. "'"
|
||||
end
|
||||
|
||||
local function execOk(cmd)
|
||||
local status = os.execute(cmd)
|
||||
return status == 0 or status == true
|
||||
end
|
||||
|
||||
local function full(path) return root .. "/" .. path end
|
||||
|
||||
local fs = {}
|
||||
function fs.createDirectory(path)
|
||||
return os.execute("mkdir -p " .. quote(full(path))) == 0
|
||||
return execOk("mkdir -p " .. quote(full(path)))
|
||||
end
|
||||
function fs.write(path, body)
|
||||
local parent = path:match("^(.*)/[^/]+$")
|
||||
@@ -34,7 +39,7 @@ function fs.remove(path)
|
||||
return true
|
||||
end
|
||||
function fs.getInfo(path)
|
||||
if os.execute("test -d " .. quote(full(path))) == 0 then
|
||||
if execOk("test -d " .. quote(full(path))) then
|
||||
return { type = "directory" }
|
||||
end
|
||||
local handle = io.open(full(path), "rb")
|
||||
|
||||
@@ -138,7 +138,25 @@ check(not pcall(Manifest.parseGithub, "not a repo"),
|
||||
check(not pcall(Manifest.validate, {
|
||||
id = "badgh", name = "Bad", version = "1.0.0", entry = "main.lua",
|
||||
github = "ftp://example.com/x",
|
||||
}), "a bad github field fails manifest validation")
|
||||
}), "an unsupported github URL fails validation")
|
||||
|
||||
-- ------- dependency github repo spec hints & dependency resolver
|
||||
local depGh = Manifest.validate({
|
||||
id = "depgh", name = "DepGH", version = "1.0.0", entry = "main.lua",
|
||||
dependencies = { "colorlib@^1.2.0#Acme/ColorLib", "soundpack#Acme/SoundPack" },
|
||||
dependency_sources = { helper = "Acme/Helper" },
|
||||
})
|
||||
check(depGh.dependencySpecs[1].id == "colorlib" and depGh.dependencySpecs[1].github == "Acme/ColorLib",
|
||||
"dependency spec hash hint parses github owner/repo")
|
||||
check(depGh.dependencySpecs[2].id == "soundpack" and depGh.dependencySpecs[2].github == "Acme/SoundPack",
|
||||
"dependency spec hash hint without range parses github owner/repo")
|
||||
|
||||
local LauncherMods = require("src.mods.LauncherMods")
|
||||
local depCheck = LauncherMods.checkDependencies(depGh)
|
||||
check(depCheck.hasIssues == true, "missing dependencies trigger issues verdict")
|
||||
check(#depCheck.deps == 2, "dependency check lists all specs")
|
||||
check(depCheck.deps[1].status == "missing", "absent dependency reports missing")
|
||||
check(depCheck.deps[1].safeUrl == "https://github.com/Acme/ColorLib", "safeUrl built from validated github repo")
|
||||
|
||||
local v1 = Manifest.validate({
|
||||
id = "v1", name = "V1", version = "1.0.0", entry = "main.lua",
|
||||
@@ -519,8 +537,61 @@ local emptyLoader = Loader.new({ fs = memfs({}) })
|
||||
check(emptyLoader:load(pristine) == true, "an empty mods dir still loads clean")
|
||||
check(#emptyLoader:status().errors == 0, "no mods means no diagnostics")
|
||||
check(#emptyLoader.order == 0, "no mods means an empty load order")
|
||||
check(pristine.pokemon.A.hp == 1 and next(pristine.items) == nil,
|
||||
"no-mod load leaves data untouched")
|
||||
-- ------- dependency resolver conflict detection test
|
||||
local LauncherMods = require("src.mods.LauncherMods")
|
||||
local testTargetManifest = Manifest.validate({
|
||||
id = "new_mod",
|
||||
name = "New Mod",
|
||||
version = "1.0.0",
|
||||
entry = "main.lua",
|
||||
incompatible = { "colorlib" },
|
||||
}, "mods/new_mod")
|
||||
local installedColorlib = Manifest.validate({
|
||||
id = "colorlib",
|
||||
name = "Color Lib",
|
||||
version = "1.0.0",
|
||||
entry = "main.lua",
|
||||
}, "mods/colorlib")
|
||||
-- ------- scoped dependency tests
|
||||
local Json = require("src.link.Json")
|
||||
local scopedDepManifest = Manifest.validate({
|
||||
id = "dual_gen_mod",
|
||||
name = "Dual Gen Mod",
|
||||
version = "1.0.0",
|
||||
entry = "main.lua",
|
||||
games = { "gen1", "gen2" },
|
||||
dependencies = {
|
||||
{ id = "gen2_only_dep", games = { "gen2" }, version = "^1.0.0" }
|
||||
},
|
||||
}, "mods/dual_gen_mod")
|
||||
check(#scopedDepManifest.dependencySpecs == 1, "scoped dependency parsed")
|
||||
check(scopedDepManifest.dependencySpecs[1].games ~= nil, "dependency carries games list")
|
||||
|
||||
local dualGenFiles = {
|
||||
["mods/dual_gen_mod/manifest.json"] = Json.encode({
|
||||
id = "dual_gen_mod",
|
||||
name = "Dual Gen Mod",
|
||||
version = "1.0.0",
|
||||
entry = "main.lua",
|
||||
games = { "gen1", "gen2" },
|
||||
dependencies = {
|
||||
{ id = "gen2_only_dep", games = { "gen2" } }
|
||||
},
|
||||
}),
|
||||
["mods/dual_gen_mod/main.lua"] = [[
|
||||
return function(mod)
|
||||
mod.content.pokemon:register("DUAL_MON", { hp = 100 })
|
||||
end
|
||||
]],
|
||||
}
|
||||
local gen1Loader = Loader.new({ fs = memfs(dualGenFiles), generation = 1 })
|
||||
check(gen1Loader:load({}) == true, "dual gen mod loads on Gen 1 when Gen 2 dep is absent")
|
||||
check(gen1Loader.content.pokemon:get("DUAL_MON") ~= nil, "dual gen mod executed on Gen 1")
|
||||
|
||||
local gen2Loader = Loader.new({ fs = memfs(dualGenFiles), generation = 2 })
|
||||
check(gen2Loader:load({}) == false, "loader returns false on Gen 2 when missing required Gen 2 dep")
|
||||
check(gen2Loader.content.pokemon:get("DUAL_MON") == nil, "dual gen mod is blocked on Gen 2 when missing required Gen 2 dep")
|
||||
check(#gen2Loader:status().errors > 0, "missing dependency error logged on Gen 2")
|
||||
|
||||
Runtime.install(savedEvents, savedHooks)
|
||||
|
||||
|
||||
@@ -1162,6 +1162,18 @@ seedOpts.modProfiles = {}
|
||||
ModProfile.ensureFirst(seedOpts, ms.status.available, {})
|
||||
check(#seedOpts.modProfiles == 0, "seeding never runs twice")
|
||||
|
||||
local LauncherMods = require("src.mods.LauncherMods")
|
||||
local testProfOpts = { activeProfile = "P1", modProfiles = { { name = "P1", enabled = { a = true } } } }
|
||||
local dupSnap = LauncherMods.duplicateProfile("P1", testProfOpts)
|
||||
check(dupSnap and dupSnap.name == "P1 (Copy)" and testProfOpts.activeProfile == "P1 (Copy)",
|
||||
"duplicateProfile creates P1 (Copy) and activates it")
|
||||
check(LauncherMods.renameProfile("P1 (Copy)", "RenamedP", testProfOpts) == true,
|
||||
"renameProfile renames active profile")
|
||||
check(testProfOpts.activeProfile == "RenamedP", "activeProfile updates on rename")
|
||||
check(LauncherMods.deleteProfile("RenamedP", testProfOpts) == true, "deleteProfile removes profile")
|
||||
check(#testProfOpts.modProfiles == 1 and testProfOpts.modProfiles[1].name == "P1", "only original profile remains")
|
||||
check(testProfOpts.activeProfile == "P1", "activeProfile falls back to remaining profile")
|
||||
|
||||
-- permissions rows
|
||||
local permy = manifest("permy", { permissions = { "network" } })
|
||||
local msP = ManagerState.new(managerGame(fakeLoader({ permy })))
|
||||
|
||||
Reference in New Issue
Block a user