Skip to content

Commit

Permalink
Fixed a bug that didn't allow some popular mods to be installed
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicJinn committed May 13, 2024
1 parent e3f7fc4 commit d7491f1
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions game-sunlesssea/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var installPath
var modType

var namelessModInstalls = 0
var prepath = ""

var cont // Save context for later use

Expand Down Expand Up @@ -124,41 +125,61 @@ function installContent(files) {
(!file.endsWith(path.sep)));

let instructions = filtered.map(file => {
console.log("removing prepath " + prepath)

const destinationPath = path.join(installPath, file.startsWith(prepath) ? file.substring(prepath.length) : file);
console.log("install to " + destinationPath)
return {
type: 'copy',
source: file,
destination: path.join(installPath, file),
destination: destinationPath,
};

});

if (modType == "json") { // Change the install path if it's a json mod
if (modType === "json") { // Change the install path if it's a json mod
const modTypeInstr = {
type: 'setmodtype',
value: 'JSON Addon Mod',
}
instructions.push(modTypeInstr)
};
instructions.push(modTypeInstr);
}

return Promise.resolve({
instructions
});
}


function checkJsonDirectoryStructure(files) {
const baseFolders = ['addons\\', 'images\\'];
const subFolders = ['entities\\', 'encyclopaedia\\', 'geography\\']
const baseFolders = ['addon', 'images'];
const subFolders = ['entities', 'encyclopaedia', 'geography']

prepath = ""
let pathto = ""
for (let i = 0; i < files.length; i++) {
let parts = files[i].split("\\")
for (let i2 = 0; i2 < parts.length; i2++) {
if (baseFolders.includes(parts[i2].replace(/[\/\\]/g, ""))) {
prepath = pathto
break
}
pathto = parts[i2]
}
if (prepath !== "") {
return ""
}
}

// Check if it's a base mod
const isBaseMod = baseFolders.some(folder => files.includes(folder));
const isBaseMod = files.some(file => baseFolders.includes(file.replace(/[\/\\]/g, "")));

// const isBaseMod = baseFolders.some(folder => files.includes(folder.replace(/[\/\\]/g, "")));

if (isBaseMod) {
return "";
}

// Checks whether the first entry in the files list is a folder that should be inside another folder
const isAModFolder = !subFolders.includes(files[0])
const isAModFolder = !subFolders.includes(files[0].replace(/[\/\\]/g, ""))
// If not, just install it as is to addon

if (isAModFolder) {
Expand Down

0 comments on commit d7491f1

Please sign in to comment.