Skip to content

Commit cd54243

Browse files
committed
Added !magic --clean command
* New !magic --clean command replaces a character sheet with one that has been cleaned of corrupted attributes
1 parent 5cd76ad commit cd54243

File tree

3 files changed

+195
-0
lines changed

3 files changed

+195
-0
lines changed

MagicMaster/4.0.5/MagicMaster.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7255,6 +7255,68 @@ var MagicMaster = (function() {
72557255
}
72567256
};
72577257

7258+
/*
7259+
* Copy a character to a new character sheet e.g. to dump corrupted attributes
7260+
*/
7261+
7262+
var handleCleanCS = function( charCS, silent=false ) {
7263+
7264+
var newCS = createObj( 'character', {
7265+
name: (charCS.get('name')),
7266+
avatar: charCS.get('avatar'),
7267+
inplayerjournals: charCS.get('inplayerjournals'),
7268+
controlledby: charCS.get('controlledby')
7269+
});
7270+
charCS.get('bio', function(bio) {
7271+
newCS.set('bio',bio);
7272+
});
7273+
charCS.get('gmnotes',function(gmnotes) {
7274+
newCS.set('gmnotes',gmnotes);
7275+
});
7276+
7277+
var objList = filterObjs( obj => {
7278+
let type = obj.get('type');
7279+
if (type === 'graphic' && obj.get('subtype') === 'token') {
7280+
if (obj.get('represents') !== charCS.id) return false;
7281+
obj.set('represents',newCS.id);
7282+
return false;
7283+
}
7284+
if (type !== 'attribute' && type !== 'ability') return false;
7285+
if (obj.get('characterid') !== charCS.id) return false;
7286+
if (obj.get('name').length && obj.get('name') != 'Untitled') {
7287+
if (type !== 'ability') {
7288+
createObj( 'attribute', {
7289+
characterid: newCS.id,
7290+
name: obj.get('name'),
7291+
current: obj.get('current'),
7292+
max: obj.get('max')
7293+
});
7294+
} else {
7295+
createObj( 'ability', {
7296+
characterid: newCS.id,
7297+
name: obj.get('name'),
7298+
description: obj.get('description'),
7299+
action: obj.get('action'),
7300+
istokenaction: obj.get('istokenaction')
7301+
});
7302+
};
7303+
};
7304+
return true;
7305+
});
7306+
7307+
// Remove all objects on objList
7308+
// then remove charCS
7309+
7310+
for (const obj of objList) {
7311+
obj.remove();
7312+
}
7313+
charCS.remove();
7314+
7315+
if (!silent) sendFeedback('&{template:'+fields.messageTemplate+'}{{name='+newCS.get('name')+' has been cleaned}}{{desc=The character sheet for '+newCS.get('name')+' has been cleaned of any corrupted attributes or abilities.}}');
7316+
7317+
return newCS;
7318+
}
7319+
72587320
/*
72597321
* Handle changes to the Strength of a character, which is not
72607322
* a linear progression due to Exceptional Strength
@@ -9732,6 +9794,9 @@ var MagicMaster = (function() {
97329794
case 'tidy':
97339795
doTidyCS(arg,selected);
97349796
break;
9797+
case 'clean':
9798+
doCleanCS(arg,selected);
9799+
break;
97359800
case 'message':
97369801
doMessage(arg,selected,senderId);
97379802
break;

MagicMaster/MagicMaster.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7255,6 +7255,68 @@ var MagicMaster = (function() {
72557255
}
72567256
};
72577257

7258+
/*
7259+
* Copy a character to a new character sheet e.g. to dump corrupted attributes
7260+
*/
7261+
7262+
var handleCleanCS = function( charCS, silent=false ) {
7263+
7264+
var newCS = createObj( 'character', {
7265+
name: (charCS.get('name')),
7266+
avatar: charCS.get('avatar'),
7267+
inplayerjournals: charCS.get('inplayerjournals'),
7268+
controlledby: charCS.get('controlledby')
7269+
});
7270+
charCS.get('bio', function(bio) {
7271+
newCS.set('bio',bio);
7272+
});
7273+
charCS.get('gmnotes',function(gmnotes) {
7274+
newCS.set('gmnotes',gmnotes);
7275+
});
7276+
7277+
var objList = filterObjs( obj => {
7278+
let type = obj.get('type');
7279+
if (type === 'graphic' && obj.get('subtype') === 'token') {
7280+
if (obj.get('represents') !== charCS.id) return false;
7281+
obj.set('represents',newCS.id);
7282+
return false;
7283+
}
7284+
if (type !== 'attribute' && type !== 'ability') return false;
7285+
if (obj.get('characterid') !== charCS.id) return false;
7286+
if (obj.get('name').length && obj.get('name') != 'Untitled') {
7287+
if (type !== 'ability') {
7288+
createObj( 'attribute', {
7289+
characterid: newCS.id,
7290+
name: obj.get('name'),
7291+
current: obj.get('current'),
7292+
max: obj.get('max')
7293+
});
7294+
} else {
7295+
createObj( 'ability', {
7296+
characterid: newCS.id,
7297+
name: obj.get('name'),
7298+
description: obj.get('description'),
7299+
action: obj.get('action'),
7300+
istokenaction: obj.get('istokenaction')
7301+
});
7302+
};
7303+
};
7304+
return true;
7305+
});
7306+
7307+
// Remove all objects on objList
7308+
// then remove charCS
7309+
7310+
for (const obj of objList) {
7311+
obj.remove();
7312+
}
7313+
charCS.remove();
7314+
7315+
if (!silent) sendFeedback('&{template:'+fields.messageTemplate+'}{{name='+newCS.get('name')+' has been cleaned}}{{desc=The character sheet for '+newCS.get('name')+' has been cleaned of any corrupted attributes or abilities.}}');
7316+
7317+
return newCS;
7318+
}
7319+
72587320
/*
72597321
* Handle changes to the Strength of a character, which is not
72607322
* a linear progression due to Exceptional Strength
@@ -9732,6 +9794,9 @@ var MagicMaster = (function() {
97329794
case 'tidy':
97339795
doTidyCS(arg,selected);
97349796
break;
9797+
case 'clean':
9798+
doCleanCS(arg,selected);
9799+
break;
97359800
case 'message':
97369801
doMessage(arg,selected,senderId);
97379802
break;

MagicMaster/magicMaster.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7255,6 +7255,68 @@ var MagicMaster = (function() {
72557255
}
72567256
};
72577257

7258+
/*
7259+
* Copy a character to a new character sheet e.g. to dump corrupted attributes
7260+
*/
7261+
7262+
var handleCleanCS = function( charCS, silent=false ) {
7263+
7264+
var newCS = createObj( 'character', {
7265+
name: (charCS.get('name')),
7266+
avatar: charCS.get('avatar'),
7267+
inplayerjournals: charCS.get('inplayerjournals'),
7268+
controlledby: charCS.get('controlledby')
7269+
});
7270+
charCS.get('bio', function(bio) {
7271+
newCS.set('bio',bio);
7272+
});
7273+
charCS.get('gmnotes',function(gmnotes) {
7274+
newCS.set('gmnotes',gmnotes);
7275+
});
7276+
7277+
var objList = filterObjs( obj => {
7278+
let type = obj.get('type');
7279+
if (type === 'graphic' && obj.get('subtype') === 'token') {
7280+
if (obj.get('represents') !== charCS.id) return false;
7281+
obj.set('represents',newCS.id);
7282+
return false;
7283+
}
7284+
if (type !== 'attribute' && type !== 'ability') return false;
7285+
if (obj.get('characterid') !== charCS.id) return false;
7286+
if (obj.get('name').length && obj.get('name') != 'Untitled') {
7287+
if (type !== 'ability') {
7288+
createObj( 'attribute', {
7289+
characterid: newCS.id,
7290+
name: obj.get('name'),
7291+
current: obj.get('current'),
7292+
max: obj.get('max')
7293+
});
7294+
} else {
7295+
createObj( 'ability', {
7296+
characterid: newCS.id,
7297+
name: obj.get('name'),
7298+
description: obj.get('description'),
7299+
action: obj.get('action'),
7300+
istokenaction: obj.get('istokenaction')
7301+
});
7302+
};
7303+
};
7304+
return true;
7305+
});
7306+
7307+
// Remove all objects on objList
7308+
// then remove charCS
7309+
7310+
for (const obj of objList) {
7311+
obj.remove();
7312+
}
7313+
charCS.remove();
7314+
7315+
if (!silent) sendFeedback('&{template:'+fields.messageTemplate+'}{{name='+newCS.get('name')+' has been cleaned}}{{desc=The character sheet for '+newCS.get('name')+' has been cleaned of any corrupted attributes or abilities.}}');
7316+
7317+
return newCS;
7318+
}
7319+
72587320
/*
72597321
* Handle changes to the Strength of a character, which is not
72607322
* a linear progression due to Exceptional Strength
@@ -9732,6 +9794,9 @@ var MagicMaster = (function() {
97329794
case 'tidy':
97339795
doTidyCS(arg,selected);
97349796
break;
9797+
case 'clean':
9798+
doCleanCS(arg,selected);
9799+
break;
97359800
case 'message':
97369801
doMessage(arg,selected,senderId);
97379802
break;

0 commit comments

Comments
 (0)