Centalize compendium searchs and make them compatible with uuid
This commit is contained in:
+9
-107
@@ -1375,34 +1375,8 @@ export class MothershipActor extends Actor {
|
||||
|
||||
//A script to return the data from a table.
|
||||
async getRollTableData(tableId){
|
||||
let currentLocation = '';
|
||||
let tableLocation = '';
|
||||
//find where this table is located
|
||||
//get current compendium
|
||||
let compendium = game.packs;
|
||||
//loop through each compendium
|
||||
compendium.forEach(function(pack){
|
||||
//is this a pack of rolltables?
|
||||
if (pack.metadata.type === 'RollTable') {
|
||||
//log where we are
|
||||
currentLocation = pack.metadata.id;
|
||||
//loop through each pack to find the right table
|
||||
pack.index.forEach(function(table) {
|
||||
//is this our table?
|
||||
if (table._id === tableId) {
|
||||
//grab the table location
|
||||
tableLocation = currentLocation;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if (tableLocation){
|
||||
// Item found in a compendium -> get table data
|
||||
let tableData = await game.packs.get(tableLocation).getDocument(tableId);
|
||||
}else{
|
||||
//try to find the item in the world. (user defined)
|
||||
let tableData = game.tables.filter(i=> i.id == tableId)
|
||||
}
|
||||
|
||||
let tableData = await fromIdUuid(tableId,type="RollTable");
|
||||
//get table name
|
||||
let tableName = tableData.name;
|
||||
//get table name
|
||||
@@ -1550,32 +1524,9 @@ export class MothershipActor extends Actor {
|
||||
//set variables
|
||||
rollString = chosenRollType[0];
|
||||
}
|
||||
//find where this table is located
|
||||
|
||||
let tableData = await fromIdUuid(tableId,type="RollTable");
|
||||
//get current compendium
|
||||
let compendium = game.packs;
|
||||
//loop through each compendium
|
||||
compendium.forEach(function(pack){
|
||||
//is this a pack of rolltables?
|
||||
if (pack.metadata.type === 'RollTable') {
|
||||
//log where we are
|
||||
currentLocation = pack.metadata.id;
|
||||
//loop through each pack to find the right table
|
||||
pack.index.forEach(function(table) {
|
||||
//is this our table?
|
||||
if (table._id === tableId) {
|
||||
//grab the table location
|
||||
tableLocation = currentLocation;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if (tableLocation){
|
||||
// Table found in a compendium -> get table data
|
||||
let tableData = await game.packs.get(tableLocation).getDocument(tableId);
|
||||
}else{
|
||||
//try to find the item in the world. (user defined)
|
||||
let tableData = game.tables.filter(i=> i.id == tableId)
|
||||
}
|
||||
//get table name
|
||||
let tableName = tableData.name;
|
||||
//get table name
|
||||
@@ -2635,34 +2586,9 @@ export class MothershipActor extends Actor {
|
||||
//prepare attribute label
|
||||
attributeLabel = 'Bankruptcy';
|
||||
//get the bankruptcy table
|
||||
//get current compendium
|
||||
let compendium = game.packs;
|
||||
let currentLocation = ``;
|
||||
let tableLocation = ``;
|
||||
let tableId = game.settings.get('mosh','table1eBankruptcy');
|
||||
//loop through each compendium
|
||||
compendium.forEach(function(pack){
|
||||
//is this a pack of rolltables?
|
||||
if (pack.metadata.type === 'RollTable') {
|
||||
//log where we are
|
||||
currentLocation = pack.metadata.id;
|
||||
//loop through each pack to find the right table
|
||||
pack.index.forEach(function(table) {
|
||||
//is this our table?
|
||||
if (table._id === tableId) {
|
||||
//grab the table location
|
||||
tableLocation = currentLocation;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if (tableLocation){
|
||||
// Table found in a compendium -> get table data
|
||||
let tableData = await game.packs.get(tableLocation).getDocument(tableId);
|
||||
}else{
|
||||
//try to find the item in the world. (user defined)
|
||||
let tableData = game.tables.filter(i=> i.id == tableId)
|
||||
}
|
||||
let tableId = game.settings.get('mosh','table1eBankruptcy');
|
||||
//get Table Data
|
||||
let tableData = await fromIdUuid(tableId,type="RollTable");
|
||||
//prep text for success
|
||||
if (parsedRollResult.success && parsedRollResult.critical) {
|
||||
//flavor text
|
||||
@@ -3136,32 +3062,8 @@ export class MothershipActor extends Actor {
|
||||
let newValue = 0;
|
||||
let flavorText = ``;
|
||||
let chatId = (game.release.generation >= 12 ? foundry.utils.randomID(): randomID())
|
||||
//find where this item is located
|
||||
//get current compendium
|
||||
let compendium = game.packs;
|
||||
//loop through each compendium
|
||||
compendium.forEach(function(pack){
|
||||
//is this a pack of items?
|
||||
if (pack.metadata.type === 'Item') {
|
||||
//log where we are
|
||||
currentLocation = pack.metadata.id;
|
||||
//loop through each pack to find the right table
|
||||
pack.index.forEach(function(item) {
|
||||
//is this our table?
|
||||
if (item._id === itemId) {
|
||||
//grab the table location
|
||||
itemLocation = currentLocation;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if (itemLocation){
|
||||
// Item found in a compendium -> get table data
|
||||
let itemData = await game.packs.get(itemLocation).getDocument(itemId);
|
||||
}else{
|
||||
//try to find the item in the world. (user defined)
|
||||
let itemData = game.items.filter(i=> i.id == itemId)
|
||||
}
|
||||
//get item data
|
||||
let itemData = await fromIdUuid(itemId,type="Item");
|
||||
//add or increase the count of the item, depending on type, if the actor has it
|
||||
if (this.items.getName(itemData.name)) {
|
||||
//if this is an item, increase the count
|
||||
|
||||
@@ -179,29 +179,8 @@ export class MothershipShipSheetSBT extends ActorSheet {
|
||||
const actorData = sheetData;
|
||||
//A script to return the data from a table.
|
||||
let tableId = game.settings.get('mosh', 'table1eMegadamageEffects');
|
||||
let currentLocation = '';
|
||||
let tableLocation = '';
|
||||
//find where this table is located
|
||||
//get current compendium
|
||||
let compendium = game.packs;
|
||||
//loop through each compendium
|
||||
compendium.forEach(function (pack) {
|
||||
//is this a pack of rolltables?
|
||||
if (pack.metadata.type === 'RollTable') {
|
||||
//log where we are
|
||||
currentLocation = pack.metadata.id;
|
||||
//loop through each pack to find the right table
|
||||
pack.index.forEach(function (table) {
|
||||
//is this our table?
|
||||
if (table._id === tableId) {
|
||||
//grab the table location
|
||||
tableLocation = currentLocation;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
//get table data
|
||||
let tableData = await game.packs.get(tableLocation).getDocument(tableId);
|
||||
let tableData = await fromIdUuid(tableId,type="RollTable");
|
||||
|
||||
let megadamageHTML = "";
|
||||
|
||||
|
||||
@@ -933,4 +933,58 @@ async function noShipSelected() {
|
||||
//log what was done
|
||||
console.log(`Told the user that no character was selected.`);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//get item from world or compendiums by id or UUID.
|
||||
export async function fromIdUuid(id_uuid,type="", options={}){
|
||||
let item = await fromUuid(id_uuid,options);
|
||||
if(item != null){
|
||||
//we found the item with the id, it probably was an uuid.
|
||||
return item;
|
||||
}
|
||||
|
||||
//we need to manualy find the item:
|
||||
let currentLocation = '';
|
||||
let objectLocation = '';
|
||||
//loop through each compendium
|
||||
game.packs.forEach(function(pack){
|
||||
//is this a pack of rolltables?
|
||||
if (pack.metadata.type === type) {
|
||||
//log where we are
|
||||
currentLocation = pack.metadata.id;
|
||||
//loop through each pack to find the right table
|
||||
pack.index.forEach(function(table) {
|
||||
//is this our table?
|
||||
if (table._id === id_uuid) {
|
||||
//grab the table location
|
||||
objectLocation = currentLocation;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if (objectLocation){
|
||||
// Item found in a compendium -> get table data
|
||||
return await game.packs.get(objectLocation).getDocument(id_uuid);
|
||||
}else{
|
||||
//it is a world item.
|
||||
switch (type) {
|
||||
case "RollTable":
|
||||
return game.tables.filter(i=> i.id == id_uuid);
|
||||
case "Item":
|
||||
return game.items.filter(i=> i.id == id_uuid);
|
||||
default:
|
||||
//type is not defined, and we could not find it in a compendium,
|
||||
//now we search all world elements.
|
||||
let itemData = game.tables.filter(i=> i.id == id_uuid);
|
||||
if (itemData){
|
||||
return itemData
|
||||
}
|
||||
itemData = game.items.filter(i=> i.id == id_uuid);
|
||||
if (itemData){
|
||||
return itemData
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -41,29 +41,8 @@ export class DLShipMegaDamage extends FormApplication {
|
||||
|
||||
//A script to return the data from a table.
|
||||
let tableId = game.settings.get('mosh','table1eMegadamageEffects');
|
||||
let currentLocation = '';
|
||||
let tableLocation = '';
|
||||
//find where this table is located
|
||||
//get current compendium
|
||||
let compendium = game.packs;
|
||||
//loop through each compendium
|
||||
compendium.forEach(function(pack){
|
||||
//is this a pack of rolltables?
|
||||
if (pack.metadata.type === 'RollTable') {
|
||||
//log where we are
|
||||
currentLocation = pack.metadata.id;
|
||||
//loop through each pack to find the right table
|
||||
pack.index.forEach(function(table) {
|
||||
//is this our table?
|
||||
if (table._id === tableId) {
|
||||
//grab the table location
|
||||
tableLocation = currentLocation;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
//get table data
|
||||
let tableData = await game.packs.get(tableLocation).getDocument(tableId);
|
||||
let tableData = await fromIdUuid(tableId,type="RollTable");
|
||||
|
||||
let entries = Array.from(tableData.results.entries());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user