Skip to content

Commit

Permalink
Indent size 4 -> 2
Browse files Browse the repository at this point in the history
  • Loading branch information
aidant19 committed Jan 10, 2024
1 parent 9127a2b commit a11406a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 74 deletions.
140 changes: 70 additions & 70 deletions scripts/ajexport.js
Original file line number Diff line number Diff line change
@@ -1,100 +1,100 @@
// With thanks to elenterius on discord for troubleshooting ideas

const consoleLogJson = (args) => {
console.log(JSON.stringify(args));
console.log(JSON.stringify(args));
};

if (typeof AnimatedJava === 'undefined') {
throw new Error('Failed to load Animated Java plugin before CLI plugin');
throw new Error('Failed to load Animated Java plugin before CLI plugin');
}
let [blockbenchPath, ...ARGV] = electron.getGlobal('process').argv;
const scriptIndicator = ARGV.indexOf('--bb-cli');
const paths = getConfigPaths(
'C:\\Users\\Aidan\\Documents\\Media_Storage\\active_projects\\flowey_remaster\\omega-flowey-minecraft-remastered\\scripts\\config.json',
'C:\\Users\\Aidan\\Documents\\Media_Storage\\active_projects\\flowey_remaster\\omega-flowey-minecraft-remastered\\scripts\\config.json',
);
const dir = paths[3].concat('/');
console.log('Target paths: ', paths);
const files = fs.readdirSync(dir).filter((file) => file.includes('ajmodel'));
const exportNextFile = () => {
if (Project) {
Project.close();
}
const file = files.pop();
if (typeof file === 'undefined') {
return;
}
consoleLogJson({ file });
if (file.includes('ajmodel')) {
let content = fs.readFileSync(dir.concat(file), 'utf-8');
let name = file.split('/').pop();
let fileObj = {
path: file,
content: injectModelPackPaths(content, paths),
name: name,
};
loadModelFile(fileObj);
AnimatedJava.API.safeExportProject(exportNextFile);
}
if (Project) {
Project.close();
}
const file = files.pop();
if (typeof file === 'undefined') {
return;
}
consoleLogJson({ file });
if (file.includes('ajmodel')) {
let content = fs.readFileSync(dir.concat(file), 'utf-8');
let name = file.split('/').pop();
let fileObj = {
path: file,
content: injectModelPackPaths(content, paths),
name: name,
};
loadModelFile(fileObj);
AnimatedJava.API.safeExportProject(exportNextFile);
}
};
exportNextFile();

function getModelPackPaths(modelContent) {
var f = JSON.parse(modelContent);
var resourcePackPath = f.animated_java.settings.resource_pack_mcmeta;
var dataPackPath =
f.animated_java.exporter_settings['animated_java:datapack_exporter']
.datapack_mcmeta;
return [resourcePackPath, dataPackPath];
var f = JSON.parse(modelContent);
var resourcePackPath = f.animated_java.settings.resource_pack_mcmeta;
var dataPackPath =
f.animated_java.exporter_settings['animated_java:datapack_exporter']
.datapack_mcmeta;
return [resourcePackPath, dataPackPath];
}

function writeModelPackPaths(modelContent, modelFile, paths) {
var f = JSON.parse(modelContent);
f.animated_java.settings.resource_pack_mcmeta = paths[0];
f.animated_java.exporter_settings[
'animated_java:datapack_exporter'
].datapack_mcmeta = paths[1];
fs.writeFileSync(modelFile, JSON.stringify(f));
var f = JSON.parse(modelContent);
f.animated_java.settings.resource_pack_mcmeta = paths[0];
f.animated_java.exporter_settings[
'animated_java:datapack_exporter'
].datapack_mcmeta = paths[1];
fs.writeFileSync(modelFile, JSON.stringify(f));
}

function injectModelPackPaths(modelContent, paths) {
var f = JSON.parse(modelContent);
f.animated_java.settings.resource_pack_mcmeta = paths[0];
f.animated_java.exporter_settings[
'animated_java:datapack_exporter'
].datapack_mcmeta = paths[1];
for (const texture of f.textures) {
texture.path = texture.path.replaceAll('\\', '/');
// TODO this should maybe be regex?
if (texture.path.includes('.minecraft')) {
const x = texture.path.split('assets')[1];
const newPath = `${paths[2]}/assets${x}`;
// consoleLogJson({
// texturePath: texture.path,
// afterAssets: x,
// newPath,
// });
texture.path = newPath;
} else if (texture.path.includes('resourcepack/assets')) {
const x = texture.path.split('resourcepack/assets')[1];
const resourcePackBase = paths[0].split('resourcepack')[0];
const newPath = `${resourcePackBase}resourcepack/assets${x}`;
// consoleLogJson({
// texturePath: texture.path,
// resourcePackBase,
// afterAssets: x,
// newPath,
// });
texture.path = newPath;
}
var f = JSON.parse(modelContent);
f.animated_java.settings.resource_pack_mcmeta = paths[0];
f.animated_java.exporter_settings[
'animated_java:datapack_exporter'
].datapack_mcmeta = paths[1];
for (const texture of f.textures) {
texture.path = texture.path.replaceAll('\\', '/');
// TODO this should maybe be regex?
if (texture.path.includes('.minecraft')) {
const x = texture.path.split('assets')[1];
const newPath = `${paths[2]}/assets${x}`;
// consoleLogJson({
// texturePath: texture.path,
// afterAssets: x,
// newPath,
// });
texture.path = newPath;
} else if (texture.path.includes('resourcepack/assets')) {
const x = texture.path.split('resourcepack/assets')[1];
const resourcePackBase = paths[0].split('resourcepack')[0];
const newPath = `${resourcePackBase}resourcepack/assets${x}`;
// consoleLogJson({
// texturePath: texture.path,
// resourcePackBase,
// afterAssets: x,
// newPath,
// });
texture.path = newPath;
}
return JSON.stringify(f);
}
return JSON.stringify(f);
}

function getConfigPaths(configFile) {
const f = JSON.parse(fs.readFileSync(configFile).toString());
let resourcePackPath = f.resource_pack_mcmeta;
let dataPackPath = f.datapack_mcmeta;
let assetsPath = f.assets_path;
let ajmodelPath = f.ajmodel_folder;
return [resourcePackPath, dataPackPath, assetsPath, ajmodelPath];
const f = JSON.parse(fs.readFileSync(configFile).toString());
let resourcePackPath = f.resource_pack_mcmeta;
let dataPackPath = f.datapack_mcmeta;
let assetsPath = f.assets_path;
let ajmodelPath = f.ajmodel_folder;
return [resourcePackPath, dataPackPath, assetsPath, ajmodelPath];
}
8 changes: 4 additions & 4 deletions scripts/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"resource_pack_mcmeta": "C:\\Users\\Aidan\\Documents\\Media_Storage\\active_projects\\flowey_remaster\\test\\resourcepack\\pack.mcmeta",
"datapack_mcmeta": "C:\\Users\\Aidan\\Documents\\Media_Storage\\active_projects\\flowey_remaster\\test\\datapacks\\omega-flowey\\pack.mcmeta",
"assets_path": "C:\\Users\\Aidan\\AppData\\Roaming\\.minecraft\\versions\\1.20.4\\1.20.4",
"ajmodel_folder": "C:\\Users\\Aidan\\Documents\\Media_Storage\\active_projects\\flowey_remaster\\test\\resourcepack\\assets\\omega-flowey\\models\\entity\\hostile\\omega-flowey"
"resource_pack_mcmeta": "C:\\Users\\Aidan\\Documents\\Media_Storage\\active_projects\\flowey_remaster\\test\\resourcepack\\pack.mcmeta",
"datapack_mcmeta": "C:\\Users\\Aidan\\Documents\\Media_Storage\\active_projects\\flowey_remaster\\test\\datapacks\\omega-flowey\\pack.mcmeta",
"assets_path": "C:\\Users\\Aidan\\AppData\\Roaming\\.minecraft\\versions\\1.20.4\\1.20.4",
"ajmodel_folder": "C:\\Users\\Aidan\\Documents\\Media_Storage\\active_projects\\flowey_remaster\\test\\resourcepack\\assets\\omega-flowey\\models\\entity\\hostile\\omega-flowey"
}

0 comments on commit a11406a

Please sign in to comment.