Skip to content

Commit

Permalink
Add support for mta. Fixes #21
Browse files Browse the repository at this point in the history
  • Loading branch information
MrVauxs committed Nov 1, 2023
1 parent 6389ad8 commit 1e190dd
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 41 deletions.
2 changes: 2 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"loadingPack": "Loading Pack {pack}",
"loadingComplete": "Loading Complete",
"error": {
"summon": "An error has occured while summoning a creature. Please check the console!",
"blanks": "Could not find the default blank NPC. Please refresh to generate one!",
"loadingPack": "Error loading pack \"{pack}\", does it exist?",
"permission": "You don't have permission to do that. How did you run this function?",
"warpgate": "Warpgate is a REQUIRED dependency of Foundry Summons, please enable it!",
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packs/macros/CURRENT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MANIFEST-000552
MANIFEST-000565
21 changes: 7 additions & 14 deletions packs/macros/LOG
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
2023/11/01-16:20:29.175765 ffff6ffff160 Recovering log #551
2023/11/01-16:20:29.183931 ffff6ffff160 Delete type=0 #551
2023/11/01-16:20:29.183962 ffff6ffff160 Delete type=3 #550
2023/11/01-16:21:29.225133 ffff6f791160 Level-0 table #555: started
2023/11/01-16:21:29.228069 ffff6f791160 Level-0 table #555: 1201 bytes OK
2023/11/01-16:21:29.231250 ffff6f791160 Delete type=0 #553
2023/11/01-16:21:29.234021 ffff6f791160 Manual compaction at level-0 from '!macros!BkJGkiXhrmghklQ4' @ 72057594037927935 : 1 .. '!macros!mnKNj84r6ZmGZyX3' @ 0 : 0; will stop at '!macros!BkJGkiXhrmghklQ4' @ 20 : 1
2023/11/01-16:21:29.234035 ffff6f791160 Compacting 1@0 + 1@1 files
2023/11/01-16:21:29.237042 ffff6f791160 Generated table #556@0: 4 keys, 1826 bytes
2023/11/01-16:21:29.237065 ffff6f791160 Compacted 1@0 + 1@1 files => 1826 bytes
2023/11/01-16:21:29.239804 ffff6f791160 compacted to: files[ 0 1 0 0 0 0 0 ]
2023/11/01-16:21:29.239923 ffff6f791160 Delete type=2 #525
2023/11/01-16:21:29.239987 ffff6f791160 Delete type=2 #555
2023/11/01-16:21:29.243120 ffff6f791160 Manual compaction at level-0 from '!macros!BkJGkiXhrmghklQ4' @ 20 : 1 .. '!macros!mnKNj84r6ZmGZyX3' @ 0 : 0; will stop at (end)
2023/11/01-20:02:52.724974 ffff7dd17160 Recovering log #563
2023/11/01-20:02:52.733002 ffff7dd17160 Delete type=3 #561
2023/11/01-20:02:52.733031 ffff7dd17160 Delete type=0 #563
2023/11/01-20:17:12.926270 ffff6f791160 Level-0 table #568: started
2023/11/01-20:17:12.926315 ffff6f791160 Level-0 table #568: 0 bytes OK
2023/11/01-20:17:12.929574 ffff6f791160 Delete type=0 #566
2023/11/01-20:17:12.929669 ffff6f791160 Manual compaction at level-0 from '!macros!BkJGkiXhrmghklQ4' @ 72057594037927935 : 1 .. '!macros!mnKNj84r6ZmGZyX3' @ 0 : 0; will stop at (end)
10 changes: 7 additions & 3 deletions packs/macros/LOG.old
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2023/11/01-16:07:16.624125 ffff6ffff160 Recovering log #548
2023/11/01-16:07:16.631301 ffff6ffff160 Delete type=0 #548
2023/11/01-16:07:16.631340 ffff6ffff160 Delete type=3 #546
2023/11/01-19:51:48.086537 ffff6ffff160 Recovering log #559
2023/11/01-19:51:48.095614 ffff6ffff160 Delete type=0 #559
2023/11/01-19:51:48.095642 ffff6ffff160 Delete type=3 #557
2023/11/01-20:02:45.672737 ffff6f791160 Level-0 table #564: started
2023/11/01-20:02:45.672793 ffff6f791160 Level-0 table #564: 0 bytes OK
2023/11/01-20:02:45.676101 ffff6f791160 Delete type=0 #562
2023/11/01-20:02:45.676226 ffff6f791160 Manual compaction at level-0 from '!macros!BkJGkiXhrmghklQ4' @ 72057594037927935 : 1 .. '!macros!mnKNj84r6ZmGZyX3' @ 0 : 0; will stop at (end)
Binary file removed packs/macros/MANIFEST-000552
Binary file not shown.
Binary file added packs/macros/MANIFEST-000565
Binary file not shown.
2 changes: 1 addition & 1 deletion src/settings/systemSpecific.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function selectDefaultSources() {
break;
}
default: {
gameSettings.getStore('sources').set(['']);
gameSettings.getStore('sources').set([]);
break;
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/settings/templateActors/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ export default async function createBlanks(defaultToken) {
game.settings.set(moduleID, 'hiddenFolder', npcFolder.id);
}

const blankNPCs = game.settings.get(moduleID, 'blankNPC');
let blankNPCs = game.settings.get(moduleID, 'blankNPC');

debug('Available Blank NPCs', blankNPCs);

if (blankNPCs.length > 1) {
npcFolder.content.forEach(async (actor) => {
await actor.delete();
});
game.settings.set(moduleID, 'blankNPC', []);
blankNPCs = [];
}

if (blankNPCs.length === 0) {
Actor.create({
name: `Blank NPC`,
Expand All @@ -27,8 +35,8 @@ export default async function createBlanks(defaultToken) {
prototypeToken: {
width: 1,
height: 1,
...defaultToken,
},
...defaultToken,
folder: npcFolder.id,
}).then((actor) => {
blankNPCs.push({ id: actor.id });
Expand Down
3 changes: 3 additions & 0 deletions src/settings/templateActors/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pf2e from './pf2e.js';
import mta from './mta.js';
import defaultBlanks from './default.js';
import { moduleID } from '../../utils.js';

Expand All @@ -23,6 +24,8 @@ export async function createBlanks() {
switch (game.system.id) {
case 'pf2e':
return await pf2e(defaultToken);
case 'mta':
return await mta(defaultToken);
default:
return await defaultBlanks(defaultToken);
}
Expand Down
64 changes: 64 additions & 0 deletions src/settings/templateActors/mta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { moduleID, debug } from '../../utils';
/**
* Creates new actors.
*
* @param {object} defaultToken The default token to use for the blank actors.
*
* @returns {Promise<boolean>} Returns true once the actors are created.
*/
export default async function createBlanks(defaultToken) {
let npcFolder = game.folders.get(game.settings.get(moduleID, 'hiddenFolder'));

if (!npcFolder) {
npcFolder = await Folder.create({ name: 'Foundry Summons Blank Actors', type: 'Actor', parent: null });
game.settings.set(moduleID, 'hiddenFolder', npcFolder.id);
}

let blankNPCs = game.settings.get(moduleID, 'blankNPC');

debug('Available Blank NPCs', blankNPCs);

if (blankNPCs.length > 2) {
npcFolder.content.forEach(async (actor) => {
await actor.delete();
});
game.settings.set(moduleID, 'blankNPC', []);
blankNPCs = [];
}

if (!blankNPCs.find((blank) => game.actors.get(blank.id)?.type === 'character')) {
Actor.create({
name: `Blank Character`,
type: 'character',
img: `icons/svg/cowled.svg`,
prototypeToken: {
width: 1,
height: 1,
...defaultToken,
},
folder: npcFolder.id,
}).then((actor) => {
blankNPCs.push({ id: actor.id });
game.settings.set(moduleID, 'blankNPC', blankNPCs);
});
}

if (!blankNPCs.find((blank) => game.actors.get(blank.id)?.type === 'ephemeral')) {
Actor.create({
name: `Blank Ephemeral`,
type: 'ephemeral',
img: `icons/svg/cowled.svg`,
prototypeToken: {
width: 1,
height: 1,
...defaultToken,
},
folder: npcFolder.id,
}).then((actor) => {
blankNPCs.push({ id: actor.id });
game.settings.set(moduleID, 'blankNPC', blankNPCs);
});
}

return true;
}
12 changes: 10 additions & 2 deletions src/settings/templateActors/pf2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ export default async function createBlanks(defaultToken) {
game.settings.set(moduleID, 'hiddenFolder', npcFolder.id);
}

const blankNPCs = game.settings.get(moduleID, 'blankNPC');
let blankNPCs = game.settings.get(moduleID, 'blankNPC');

debug('Available Blank NPCs', blankNPCs);

const neededSizes = ['tiny', 'med', 'lg', 'huge', 'grg'];

if (blankNPCs.length > neededSizes.length) {
npcFolder.content.forEach(async (actor) => {
await actor.delete();
});
game.settings.set(moduleID, 'blankNPC', []);
blankNPCs = [];
}

if (blankNPCs.length < neededSizes.length) {
const message = `Foundry Summons | ${localize(`${moduleID}.notifications.blanks`)}`;
debug(message, ui.notifications.info(message));
Expand Down Expand Up @@ -48,6 +56,7 @@ export default async function createBlanks(defaultToken) {
prototypeToken: {
width,
height,
...defaultToken,
},
system: {
attributes: {
Expand All @@ -64,7 +73,6 @@ export default async function createBlanks(defaultToken) {
},
},
},
...defaultToken,
folder: npcFolder.id,
}).then((actor) => {
blankNPCs.push({ id: actor.id, size });
Expand Down
57 changes: 39 additions & 18 deletions src/summon/summon.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ async function summon(data) {
}

// Then we can proceed.
let actorName = (await fromUuid(`Actor.${game.settings.get(moduleID, 'blankNPC')[0].id}`)).name;
let actorName;
try {
actorName = (await fromUuid(`Actor.${game.settings.get(moduleID, 'blankNPC')[0].id}`)).name;
} catch (error) {
ui.notifications.error(`Foundry Summons | ${localize('fs.notifications.error.blanks')}`);
}
if (!actorName) {
ui.notifications.error(`Foundry Summons | ${localize('fs.notifications.error.blanks')}`);
return;
}
let actor = actorData;
let token = actor.prototypeToken;

Expand Down Expand Up @@ -241,25 +250,37 @@ async function summon(data) {
options
);

const results = warpgate.spawnAt(
{
x,
y,
},
actorName,
updates,
callbacks,
options
);
try {
const results = warpgate.spawnAt(
{
x,
y,
},
actorName,
updates,
callbacks,
options
);

results.then(() => {
if (data.location?.constructor?.name.includes('MeasuredTemplate')) {
data.location.delete();
}
});

results.then(() => {
if (data.location?.constructor?.name.includes('MeasuredTemplate')) {
data.location.delete();
}
});
warpgate.event.notify('fs-summonNotifyPlayer', { ...data, tokenIds: await results });

warpgate.event.notify('fs-summonNotifyPlayer', { ...data, tokenIds: await results });
return results;
return results;
} catch (error) {
ui.notifications.error(`Foundry Summons | ${localize('fs.notifications.error.summon')}`);
console.log(`Foundry Summons | ${localize('fs.notifications.error.summon')}`, {
actorName,
updates,
callbacks,
options,
});
throw Error(error);
}
}

window.foundrySummons = window.foundrySummons || {};
Expand Down

0 comments on commit 1e190dd

Please sign in to comment.