Skip to content

Commit

Permalink
Merge branch 'bugtest'
Browse files Browse the repository at this point in the history
  • Loading branch information
Zakkon committed Oct 14, 2024
2 parents 75c99b6 + a8a35ee commit c20479f
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 35 deletions.
1 change: 1 addition & 0 deletions charbuilder.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<script src="js/charbuilder/plutonium/filter.js"></script>
<script src="js/charbuilder/helperfunctions.js"></script>
<script src="js/charbuilder/plutonium/charactermancer.js"></script>
<script src="js/charbuilder/system5e.js"></script>
<script src="js/charbuilder/sheet.js"></script>
<script src="js/charbuilder/charexport.js"></script>
<script src="js/charbuilder/plutonium/sourcemodal.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion js/charbuilder/plutonium/vetools.js
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ class Vetools {
}
}
Vetools._RE_HTTP_URL = /(^https?:\/\/)/;
Vetools._BASE_SITE_URL = "https://5etools-mirror-2.github.io/";
Vetools._BASE_SITE_URL = "https://5etools-mirror-3.github.io/";
Vetools.BESTIARY_FLUFF_INDEX = null;
Vetools.BESTIARY_TOKEN_LOOKUP = null;
Vetools._CACHED_GET_ROLLABLE_ENTRY_DICE = null;
Expand Down
37 changes: 3 additions & 34 deletions js/charbuilder/sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class ActorCharactermancerSheet extends ActorCharactermancerBaseComponent{
//Only print this if the optional feature is chosen
text = isOptFeatureEnabled(l, text); continue;
}
//else{tryPrintSpecialClassFeatures(l, cls);}
else{tryPrintSpecialClassFeatures(l, cls);}
text += `${text.length > 0? ", " : ""}`;
text += hotlinkFeatures? ActorCharactermancerSheet.hotlink_classFeature(l, cls) : l.entity.name;
}
Expand Down Expand Up @@ -346,40 +346,9 @@ class ActorCharactermancerSheet extends ActorCharactermancerBaseComponent{
this._meta.attributes.push(attr);
}
}
const calcAttribute = (attribute) => {
let formula = attribute.formula;
for(let alteration of attribute.alterations){
formula = formula + "+" + alteration.formula;
}
//Calculate the formula

const pattern = /@\w+(\.\w+)*/g;



// Replace object references with random numbers
const result = formula.replace(pattern, (match) => {
//calculate the object reference
//split the string by periods
//remove @
let words = (match.startsWith('@') ? match.slice(1) : match).split(".");
console.log(words);
if(words[0] == "class"){
//assume the next word is the name of a class
let className = words[1];
const ourClass = getClassByName(classData, className);
if(words[2] == "level"){
return ourClass.targetLevel.toString();
}
}
return "4";
});
return eval(result);

}
const tryPrintSpecialClassFeatures = (feature, cls) => {
if(feature.entity.name == "Sorcery Points" && cls.name == "Sorcerer"){
//createAttribute(feature.entity.name, "@class.sorcerer.level", `${feature.entity.name}|${cls.name}|${cls.source}`);
createAttribute(feature.entity.name, "@scale.sorcerer.sorcery-points", `${feature.entity.name}|${cls.name}|${cls.source}`);
}

}
Expand All @@ -393,7 +362,7 @@ class ActorCharactermancerSheet extends ActorCharactermancerBaseComponent{

/* for(let attr of this._meta.attributes){
try {
$$`<div><b>${attr.name}: </b>${calcAttribute(attr)}</div>`.appendTo($divClassFeatures);
$$`<div><b>${attr.name}: </b>${System5e.replaceFormulaData(attr, this._parent)}</div>`.appendTo($divClassFeatures);
}
catch(e){console.error(e);}
Expand Down
95 changes: 95 additions & 0 deletions js/charbuilder/system5e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
class System5e{
/**
* @param {string} formula
* * @param {{formula:string}[]} alterations
* @returns {number}
*/
static calculateFormula(formula, parent){
//Calculate the formula

const pattern = /@\w+(\.\w+)*/g;

// Replace object references with random numbers
const result = formula.replace(pattern, (match) => {
//calculate the object reference
//split the string by periods
//remove @
let words = (match.startsWith('@') ? match.slice(1) : match).split(".");
console.log(words);
if(words[0] == "scale"){
const val = this.calculateClassScale(words[1], words[2], parent);
return val.toString();
}
return "4";
});
return eval(result);
}
static calculateClassScale(className, identifier, parent){
const activeClassData = ActorCharactermancerSheet.getClassData(parent.compClass);
console.log("classData", activeClassData);
const classLevel = System5e.getClassLevel(className, activeClassData);
//const scale = this._getClassScales(className)[identifier];
//return scale.scale[classLevel.toString()].value;
return this._getTableColumnValue(this._getClassTable(className, parent.compClass._data.class), identifier, (classLevel-1).toString());
}
static _getTableColumnValue(table, columnName, rowValue){
columnName = columnName.toLowerCase();
let colIx = 0;
for(let i = 0; i < table.colLabels.length; ++i){if(table.colLabels[i].toLowerCase() == columnName){colIx = i;}}
return table.rows[rowValue][colIx];
}
static _getClassTable(className, classDatas){
console.log(classDatas);
for(let cls of classDatas){
if(cls.name.toLowerCase() == className){
return cls.classTableGroups[0];
}
}
}
static _getClassScales(className){
const data = this.getClassData(className);
//Get scales
//in advancements
let scales = {};
for(let ad of data.advancement){
switch (ad.type.toLowerCase()){
case "scalevalue": scales[ad.configuration.identifier] = ad; break;
default: break;
}
}
return scales;
}
static getClassData(className){
//not implemented
}
static getClassLevel(className, activeClassData){
for(let cls of activeClassData){
if(cls.cls.name.toLowerCase() == className){
return cls.targetLevel;}
}
return 0;
}
static replaceFormulaData(formula, data){
const dataRgx = new RegExp(/@([a-z.0-9_-]+)/gi);
console.log("input", formula);
const missingReferences = new Set();
console.log(formula);
formula = formula.replace(dataRgx, (match, term) => {
/* let value = foundry.utils.getProperty(data, term);
if ( value == null ) {
missingReferences.add(match);
return "0";
}
return String(value).trim(); */
let words = (match.startsWith('@') ? match.slice(1) : match).split(".");
console.log(words);
if(words[0] == "scale"){
const val = this.calculateClassScale(words[1], words[2], data);
return val.toString();
}
return "4";

});
console.log(formula);
}
}

0 comments on commit c20479f

Please sign in to comment.