Yeah, it's nice when things can bet simplified! =D Side note, there's no controlledby setting of "gm" because the GM can control everything. Here's a couple functions you might find handy for dealing with control: const playerCanControl = (obj, playerid='any') => {
const playerInControlledByList = (list, playerid) => list.includes('all') || list.includes(playerid) || ('any'===playerid && list.length);
let players = obj.get('controlledby')
.split(/,/)
.filter(s=>s.length);
if(playerInControlledByList(players,playerid)){
return true;
}
if('' !== obj.get('represents') ) {
players = (getObj('character',obj.get('represents')) || {get: function(){return '';} } )
.get('controlledby').split(/,/)
.filter(s=>s.length);
return playerInControlledByList(players,playerid);
}
return false;
};
const getControlList = (obj) => {
let list = obj.get('controlledby')
.split(/,/)
.filter(s=>s.length);
if('' !== obj.get('represents') ) {
list = [...new Set([
...list,
(getObj('character',obj.get('represents')) || {get: function(){return '';} } )
.get('controlledby').split(/,/)
.filter(s=>s.length)
])];
}
return list.join(',');
};
Two Functions: playerCanControl( object, optionalPlayerID) -- takes a graphic or character and returns true if a player can control it. Handles "all", and looking at the represented character as well. Optionally pass a playerID to check if that specific player can control it. getControlList( object ) -- takes a graphic or character and returns the composite list of controlledby entries.