Skip to content

Commit

Permalink
v13.1.10 - x64 import dialog
Browse files Browse the repository at this point in the history
- Changed import dialog to account for x64 version of Acrobat
- Added method for dealing with spell sheet generation throwing an error and generating a blank page
- Fixed bugs: `savetxt.text` being converted to metric, spellcasting changes not being saved
  • Loading branch information
morepurplemorebetter committed Sep 29, 2023
1 parent a591428 commit e80667b
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 69 deletions.
76 changes: 64 additions & 12 deletions _functions/Functions0.js
Original file line number Diff line number Diff line change
Expand Up @@ -1067,27 +1067,79 @@ function similarLen(str1, str2) {

//test if a template is visible or not
function isTemplVis(tempNm, returnPrefix) {
if (!BookMarkList[tempNm] || !tDoc.getField(BookMarkList[tempNm])) return false;
var isVisible = false;
var bkmrkFld = BookMarkList[tempNm];
if (!bkmrkFld || !tDoc.getField(bkmrkFld)) return false;
var isVisible = false, firstTempl = false, prefixes = false;
var multiTemp = TemplatesWithExtras.indexOf(tempNm) !== -1;
var firstTempl = "";
if (!multiTemp) {
var tempPage = tDoc.getField(BookMarkList[tempNm]).page;
var tempPage = tDoc.getField(bkmrkFld).page;
isVisible = (isArray(tempPage) ? Math.max.apply(Math, tempPage) : tempPage) !== -1;
} else {
isVisible = What("Template.extras." + tempNm) !== "";
firstTempl = What("Template.extras." + tempNm).split(",")[1];
prefixes = What("Template.extras." + tempNm).split(",");
isVisible = prefixes.length > 1;
firstTempl = prefixes[1];
lastTempl = prefixes.slice(-1)[0];
};
if (!isVisible && tempNm === "SSfront") {
isVisible = isTemplVis("SSmore", returnPrefix);
if (isArray(isVisible)) {
firstTempl = isVisible[1];
isVisible = isVisible[0];
};
return isTemplVis("SSmore", returnPrefix);
};
return returnPrefix && firstTempl ? [isVisible, firstTempl] : isVisible;
if (isVisible && prefixes) {
// check all the template prefixes if they actually exist, otherwise fix the issue
var errorPrefixes = [];
for (var i = 1; i < prefixes.length; i++) {
if (!tDoc.getField(prefixes[i] + bkmrkFld)) errorPrefixes.push(prefixes[i]);
}
if (errorPrefixes.length) {
// error with one or more pages, fix that and then start this function again
pageErrorCleanup(tempNm, errorPrefixes);
return isTemplVis(tempNm, returnPrefix);
}
}
return isVisible && returnPrefix && firstTempl ? [isVisible, returnPrefix === "last" ? lastTempl : firstTempl] : isVisible;
};

// Error fixing: remove pages without form fields
function pageErrorCleanup(tempNm, prefixes) {
// Cleanup the saved field for extra generated templates
var tempPrefixList = What("Template.extras." + tempNm).split(",");
for (var i = 0; i < prefixes.length; i++) {
tempPrefixList.splice(tempPrefixList.indexOf(prefixes[i]), 1);
}
Value("Template.extras." + tempNm, tempPrefixList);
// Distill the template prefixes to just their page number (0-index)
var expectedPageNo = prefixes.map(function(n) {
return Number(n.replace(/P(\d+)\..+/, '$1'));
});
// Find all pages with fields on them
var pagesWithFields = {};
for (var i = 0; i < tDoc.numFields; i++) {
var fld = tDoc.getField(tDoc.getNthFieldName(i));
var arrPageNo = isArray(fld.page) ? fld.page : [fld.page];
for (var n = 0; n < arrPageNo.length; n++) {
var pageNo = arrPageNo[n];
if ( !pagesWithFields[pageNo] ) pagesWithFields[pageNo] = true;
}
}
// Compare that to the actual pages
for (var i = 0; i < tDoc.numPages; i++) {
if ( !pagesWithFields[i] ) {
// A page without any fields on it, should probably delete
var goOn = expectedPageNo.indexOf(i) !== -1 || expectedPageNo.indexOf(i+1) !== -1 || expectedPageNo.indexOf(i-1) !== -1; // Test if matches (or close enough) an expected page number
if ( !goOn ) { // Didn't match, so ask the user if this page should be deleted
var userResponse = app.alert({
cMsg: "Delete erroneous page " + (i+1) + "?",
cTitle: "Page number " + (i+1) + " seems to have no fields on it. This is probably due to an error when generating new pages or deleting them."+
"\n\nWould you like to delete page " + (i+1) + "?",
nIcon: 2,
nType: 2
});
goOn = userResponse === 4;
}
if (goOn) tDoc.deletePages(i);
}
}
}

// A way to return a new, fresh object
function newObj(inObj) {
return typeof inObj === "string" ? inObj : eval(inObj.toSource());
Expand Down
2 changes: 1 addition & 1 deletion _functions/Functions1.js
Original file line number Diff line number Diff line change
Expand Up @@ -6114,7 +6114,7 @@ function ClassFeatureOptions(Input, AddRemove, ForceExtraname) {

// initialize some variables
var triggerIsMenu = event.target && event.target.name && event.target.name == "Class Features Menu";
var addIt = (AddRemove !== undefined ? AddRemove : MenuSelection[4] !== undefined ? MenuSelection[4] : "add").toString().toLowerCase() === "add"; // default add, remove if second variable or 4th array entry is defined and not "add"
var addIt = (AddRemove !== undefined ? AddRemove : MenuSelection[4] !== undefined ? MenuSelection[4] : "add").toString().toLowerCase() === "add"; // default add, remove if second variable or 5th array entry is defined and not "add"
var aClass = MenuSelection[0];
var prop = MenuSelection[1];
var choice = MenuSelection[2];
Expand Down
12 changes: 6 additions & 6 deletions _functions/Functions2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2813,10 +2813,10 @@ function DoTemplate(tempNm, AddRemove, removePrefix, GoOn) {
return Math.max.apply(Math, DepTypeFld.page) + 1;
};
} else {
var DepTypeFlds = What("Template.extras." + theDep);
if (DepTypeFlds) {
return tDoc.getField(DepTypeFlds.split(",").slice(-1)[0] + BookMarkList[theDep]).page + 1;
};
var depVisible = isTemplVis(theDep, "last");
if (depVisible) {
return tDoc.getField(depVisible[1] + BookMarkList[theDep]).page + 1;
}
};
};
return 2;
Expand Down Expand Up @@ -7280,7 +7280,7 @@ function SetProf(ProfType, AddRemove, ProfObj, ProfSrc, Extra) {
setT[iAddLC].conditionBase = iAddLC.replace(aMatchCond[1], "");
}
if (attr === "text") {
AddString(fld, metric ? iAdd : iAddM, "; ");
AddString(fld, metric ? iAddM : iAdd, "; ");
} else if (attr === "immune" && CurrentProfs.resistance[iAddLC]) {
//adding immunity to something that the character also has resistance to, so remove the resistance
var theRes = CurrentProfs.resistance[iAddLC];
Expand All @@ -7300,7 +7300,7 @@ function SetProf(ProfType, AddRemove, ProfObj, ProfSrc, Extra) {
if (setT[iAddLC].src.length === 0) {
delete setT[iAddLC];
if (attr === "text") {
RemoveString(fld, metric ? iAdd : iAddM);
RemoveString(fld, metric ? iAddM : iAdd);
} else if (attr === "immune" && CurrentProfs.resistance[iAddLC]) {
//removing immunity to something that the character also has resistance to, so add the resistance (again)
DoResistance(iAddLC);
Expand Down
16 changes: 13 additions & 3 deletions _functions/Functions3.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,15 @@ function ApplyFeatureAttributes(type, fObjName, lvlA, choiceA, forceNonCurrent)
// spellcasting
if (uObj.spellcastingBonus) processSpBonus(addIt, uniqueObjNm, uObj.spellcastingBonus, type, aParent, objNm, forceNonCurrent ? true : false);
if (CurrentSpells[useSpCasting] && (uObj.spellFirstColTitle || uObj.spellcastingExtra || uObj.spellChanges || uObj.spellcastingExtraApplyNonconform !== undefined)) {
CurrentUpdates.types.push("spells");
var aCast = CurrentSpells[useSpCasting];

if (uObj.spellFirstColTitle) aCast.firstCol = addIt ? uObj.spellFirstColTitle : false;
if (uObj.spellFirstColTitle) {
aCast.firstCol = addIt ? uObj.spellFirstColTitle : false;
if (!uObj.spellcastingBonus && !uObj.spellcastingExtra && !uObj.spellChanges) {
SetStringifieds('spells');
CurrentUpdates.types.push("spells");
}
}

if (uObj.spellcastingExtra || uObj.spellcastingExtraApplyNonconform !== undefined) {
processSpellcastingExtra(addIt, useSpCasting, fObj.minlevel, tipNmF, uObj.spellcastingExtra, uObj.spellcastingExtraApplyNonconform);
Expand All @@ -230,7 +235,6 @@ function ApplyFeatureAttributes(type, fObjName, lvlA, choiceA, forceNonCurrent)
}
if (!uObj.spellcastingBonus && addIt && CurrentSpells[useSpCasting] && type !== "classes" && type !== "race" && (uObj.spellcastingAbility !== undefined || uObj.fixedDC || uObj.fixedSpAttack || uObj.allowUpCasting !== undefined || uObj.magicItemComponents !== undefined)) {
// will already have been processed if uObj has `spellcastingBonus`
CurrentUpdates.types.push("spells");
var aCast = CurrentSpells[useSpCasting];
if (uObj.spellcastingAbility !== undefined) {
aCast.ability = ReturnSpellcastingAbility(useSpCasting, uObj.spellcastingAbility);
Expand All @@ -240,6 +244,9 @@ function ApplyFeatureAttributes(type, fObjName, lvlA, choiceA, forceNonCurrent)
if (uObj.fixedSpAttack) aCast.fixedSpAttack = Number(uObj.fixedSpAttack);
if (uObj.allowUpCasting !== undefined) aCast.allowUpCasting = uObj.allowUpCasting;
if (uObj.magicItemComponents !== undefined) aCast.magicItemComponents = uObj.magicItemComponents;

SetStringifieds('spells');
CurrentUpdates.types.push("spells");
};
if (uObj.spellcastingBonusElsewhere) processSpellcastingBonusElsewhere(addIt, type, tipNm, uniqueObjNm, uObj.spellcastingBonusElsewhere);

Expand Down Expand Up @@ -898,6 +905,8 @@ function processSpChanges(AddRemove, srcNm, spChng, spObjName) {
// now maybe delete the whole spellAttrOverride if it is empty
if (!ObjLength(spCast.spellAttrOverride)) delete spCast.spellAttrOverride;
}
SetStringifieds('spells');
CurrentUpdates.types.push("spells");
}

// process the spellcastingExtra and spellcastingExtraApplyNonconform attributes
Expand Down Expand Up @@ -930,6 +939,7 @@ function processSpellcastingExtra(AddRemove, spObjName, lvl, name, spExtra, spNo
var keysArrSort = Object.keys(aCast[remNm]).sort().reverse();
aCast[useNm] = aCast[remNm][keysArrSort[0]];
}
SetStringifieds('spells');
CurrentUpdates.types.push("spells");
}

Expand Down
128 changes: 84 additions & 44 deletions _functions/FunctionsImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,79 @@ function AddFolderJavaScript(justConsole) {
var isContin = app.viewerVersion.substring(6, 8) != 30;
var vYear = 20 + app.viewerVersion.substring(0, 2);

var textLoc = "The 'JavaScripts' folder for Adobe Acrobat " + isType + " DC on " + (isWindows ? "Windows 10 x64" : "Mac OS") + " is:";
var textLoc = "The 'JavaScripts' folder" + (isWindows ? 's' : '') + " for Adobe Acrobat " + isType + " DC on " + (isWindows ? "Windows are:" : "macOS is:");
var locWin = "C:\\Program Files (x86)\\Adobe\\Acrobat " + (isType === "Reader" ? "Reader " : "") + (isContin ? "DC" : vYear) + "\\" + (isType === "Reader" ? "Reader" : "Acrobat") + "\\Javascripts\\";
var locWin64 = locWin.replace(' (x86)', '');
var locMac = "/Applications/Adobe Acrobat " + (isType === "Reader" ? "Reader " : "") + (isContin ? "DC" : vYear) + ".app/Contents/Resources/JavaScripts/";

var Text0 = justConsole ? "In order to import user-defined icons, you will have to manually add a JavaScript file to your Adobe Acrobat installation. This is necessary, because of Adobe Acrobat's security protocol. You will have to do this only once to get this function working." : "In order to use the 'Direct Import' functionality, you will need to do something to appease Adobe Acrobat's security settings. You have two options:\nOption 1 is that you add a JavaScript file to your installation. After you've done this, you will never see this dialog again.\nOption 2 is that you run the code from console, but you will have to do this every time if you want to use this function.";
var Text1 = "Do the following steps:\n 1) Use the button below to save the file somewhere (don't change the filename).\n 2) Rename the file so that its extension is \".js\" (can't be done while saving).\n 3) Move the file to the right location mentioned below (can't be saved there directly).\n 4) Restart Adobe Acrobat and try the 'Direct Import' function again.";
var Text2 = "The directory where you have to put this file depends on your version of Adobe Acrobat and your operating system. The path shown here is an estimated guess for your installation. It is possible that this folder doesn't exist yet, or that it is hidden.\n" + toUni("Note that you can't save the file directly to this location!");
var Text3 = "Open the console (a.k.a. \"JavaScript Debugger\") and run the code that is printed there. Running the code is done by selecting the line it is on and pressing " + (isWindows ? "Ctrl+Enter" : "Command+Enter") + " (or the numpad Enter).";
var LocJS = isWindows ? locWin : locMac;

var Text2 = (isWindows ? "The paths shown above are an estimated guess for your installation. Use the x64 or x86 path, depending on which version of Adobe Acrobat you have installed." : "The path shown above is an estimated guess for your installation.")+
" You can select and copy the path above. It is possible that this folder doesn't exist yet, or that it is hidden.\n" + toUni("Note that you can't save the file directly to this location!\n ");
var Text3 = 'Open the console (a.k.a. "JavaScript Debugger") and run the code that is printed there. Running the code is done by selecting the line it is on and pressing ' + (isWindows ? "Ctrl+Enter" : "Command+Enter") + " (or the numpad Enter).";

var windowsLocations = {
type : "view",
align_children : "align_left",
elements : [{
type : "view",
align_children : "align_row",
elements : [{
type : "static_text",
item_id : "l1tx",
name : " 32-bit Acrobat (x86):",
width : 80,
font : "dialog",
bold : true
}, {
type : "edit_text",
item_id : "loc1",
alignment : "align_fill",
font : "dialog",
width : 390,
readonly : true
}]
}, {
type : "view",
align_children : "align_row",
elements : [{
type : "static_text",
item_id : "l2tx",
name : " 64-bit Acrobat (x64):",
width : 80,
font : "dialog",
bold : true
}, {
type : "edit_text",
item_id : "loc2",
alignment : "align_fill",
font : "dialog",
width : 390,
readonly : true
}]
}]
};
var macLocations = {
type : "edit_text",
item_id : "loc1",
alignment : "align_fill",
font : "dialog",
width : 470,
readonly : true
};
var AddJS_dialog = {
initialize : function(dialog) {
dialog.load({
locJ : LocJS
});
if (isWindows) {
var toLoad = {
loc1 : locWin,
loc2 : locWin64
};
} else {
var toLoad = {
loc1 : locMac
};
}
dialog.load(toLoad);
},
bADD : function(dialog) {
tDoc.exportDataObject({ cName: "MPMB-IF Remove '.txt' from the end.js.txt", nLaunch: 0});
Expand Down Expand Up @@ -137,37 +195,21 @@ function AddFolderJavaScript(justConsole) {
back_color: "windowDialog",
alignment : "align_fill",
width : 500,
elements : [{
type : "cluster",
item_id : "txtJ",
elements : [isWindows ? windowsLocations : macLocations].concat([{
type : "static_text",
item_id : "txt2",
alignment : "align_fill",
font : "dialog",
bold : true,
width : 500,
name : textLoc,
elements : [{
type : "edit_text",
item_id : "locJ",
alignment : "align_fill",
font : "dialog",
width : 470,
readonly : true
}, {
type : "static_text",
item_id : "txt2",
alignment : "align_fill",
font : "dialog",
wrap_name : true,
width : 470,
name : Text2
}, ]
}, ]
}, ]
}, ]
wrap_name : true,
width : 470,
name : Text2
}])
}]
}]
}, {
type : "gap",
height : 5
}, {
}].concat(justConsole ? [] : [{
type : "view",
item_id : "vieC",
back_color: "windowBackground",
Expand Down Expand Up @@ -195,20 +237,18 @@ function AddFolderJavaScript(justConsole) {
font : "heading",
bold : true,
alignment : "align_center"
}, ]
}, ]
}, ]
}]
}]
}])
}, {
type : justConsole ? "ok_cancel" : "ok",
ok_name : "Done",
cancel_name : "Continue without importing icons"
}, ]
}, ]
}]
}]
}
};

if (justConsole) delete AddJS_dialog.description.elements[0].elements[0].elements[4];

var theDialog = app.execDialog(AddJS_dialog);

if (theDialog === "cons") {
Expand Down Expand Up @@ -2199,11 +2239,11 @@ function MakeXFDFExport(partial) {
}, {
type : "gap",
height : 5
}, ]
}]
}, {
type : "ok"
}, ]
}, ]
}]
}]
}
}
app.execDialog(DisplayExport_dialog);
Expand Down
2 changes: 1 addition & 1 deletion _variables/ListsMagicItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -3860,7 +3860,7 @@ var Base_MagicItemsList = {
action : [["action", " (create/dismiss)"]]
},
"swan boat" : {
description : "As an action, I can touch the token to a body of water at least 60-ft in diameter, having it turn into a 50 ft by 20 ft boat shaped like a swan that remains for 24 hours. It moves itself at 6 miles per hour. As an action, I can command it to turn up to 90°. It can hold up to 32 Medium creatures (Large count as 4, Huge as 9).",
description : "As an action, I can touch the token to a body of water at least 60-ft in diameter, having it turn into a 50 ft by 20 ft boat shaped like a swan that remains for 24 hours. It moves itself at 6 miles per hour. As an action, I can command it to turn up to 90\u00B0. It can hold up to 32 Medium creatures (Large count as 4, Huge as 9).",
descriptionFull : "This tiny object looks like a feather. You can use an action to touch the token to a body of water at least 60 feet in diameter. The token disappears, and a 50-foot-long, 20-foot-wide boat shaped like a swan takes its place. The boat is self-propelled and moves across water at a speed of 6 miles per hour. You can use an action while on the boat to command it to move or to turn up to 90 degrees. The boat can carry up to thirty-two Medium or smaller creatures. A Large creature counts as four Medium creatures, while a Huge creature counts as nine. The boat remains for 24 hours and then disappears. You can dismiss the boat as an action.",
action : [["action", " (create/dismiss)"]]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SourceList["WR:W"] = {
name : "William Russell: Witch",
abbreviation : "WR:W",
group : "Dungeon Masters Guild",
url : "https://www.dropbox.com/s/39mm98n3uygfiai/Witch_Class_5e_9305741.pdf?dl=0",
url : "https://www.dropbox.com/s/39mm98n3uygfiai/Witch_Class_5e_9305741.pdf?dl=1",
date : "2016/05/18"
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/* -INFORMATION-
Subject: Subclass
Effect: This script adds a subclass for the Rogue, called "Field Support"
This subclass is made by Monty and can be found here: https://www.dropbox.com/s/49lcya9a11xmoi1/Field%20Support%2C%20Roguish%20Archetype.pdf?dl=0
This subclass is made by Monty and can be found here: https://www.dropbox.com/s/49lcya9a11xmoi1/Field%20Support%2C%20Roguish%20Archetype.pdf?dl=1
Code by: Monty & MorePurpleMoreBetter
Date: 2017-11-29 (sheet v12.999)
*/
Expand Down

0 comments on commit e80667b

Please sign in to comment.