fvtt-te-deum/modules/tedeum-main.js

141 lines
4.5 KiB
JavaScript
Raw Normal View History

2023-12-11 20:11:10 +01:00
/**
2023-12-11 21:41:51 +01:00
* Te Deum system
2023-12-11 20:11:10 +01:00
* Author: Uberwald
* Software License: Prop
*/
/* -------------------------------------------- */
/* -------------------------------------------- */
// Import Modules
2023-12-11 21:41:51 +01:00
import { TeDeumActor } from "./actors/tedeum-actor.js";
import { TeDeumItemSheet } from "./items/tedeum-item-sheet.js";
import { TeDeumActorSheet } from "./actors/tedeum-actor-sheet.js";
import { TeDeumUtility } from "./common/tedeum-utility.js";
import { TeDeumCombat } from "./app/tedeum-combat.js";
import { TeDeumItem } from "./items/tedeum-item.js";
import { TeDeumHotbar } from "./app/tedeum-hotbar.js"
import { TEDEUM_CONFIG } from "./common/tedeum-config.js"
2023-12-11 20:11:10 +01:00
/* -------------------------------------------- */
/* Foundry VTT Initialization */
/* -------------------------------------------- */
/************************************************************************************/
Hooks.once("init", async function () {
2023-12-11 21:41:51 +01:00
console.log(`Initializing TeDeum RPG`);
2023-12-11 20:11:10 +01:00
2023-12-11 21:41:51 +01:00
game.system.tedeum = {
2023-12-11 20:11:10 +01:00
config: ECRYME_CONFIG,
2023-12-11 21:41:51 +01:00
TeDeumHotbar
2023-12-11 20:11:10 +01:00
}
/* -------------------------------------------- */
// preload handlebars templates
2023-12-11 21:41:51 +01:00
TeDeumUtility.preloadHandlebarsTemplates();
2023-12-11 20:11:10 +01:00
/* -------------------------------------------- */
// Set an initiative formula for the system
CONFIG.Combat.initiative = {
formula: "1d6",
decimals: 1
};
/* -------------------------------------------- */
2023-12-11 21:41:51 +01:00
game.socket.on("system.fvtt-tedeum", data => {
TeDeumUtility.onSocketMesssage(data)
2023-12-11 20:11:10 +01:00
});
/* -------------------------------------------- */
// Define custom Entity classes
2023-12-11 21:41:51 +01:00
CONFIG.Combat.documentClass = TeDeumCombat
CONFIG.Actor.documentClass = TeDeumActor
CONFIG.Item.documentClass = TeDeumItem
2023-12-11 20:11:10 +01:00
/* -------------------------------------------- */
// Register sheet application classes
Actors.unregisterSheet("core", ActorSheet);
2023-12-11 21:41:51 +01:00
Actors.registerSheet("fvtt-tedeum", TeDeumActorSheet, { types: ["pc"], makeDefault: true });
Actors.registerSheet("fvtt-tedeum", TeDeumActorSheet, { types: ["npc"], makeDefault: true });
Actors.registerSheet("fvtt-tedeum", TeDeumAnnencySheet, { types: ["annency"], makeDefault: false });
2023-12-11 20:11:10 +01:00
Items.unregisterSheet("core", ItemSheet);
2023-12-11 21:41:51 +01:00
Items.registerSheet("fvtt-tedeum", TeDeumItemSheet, { makeDefault: true });
2023-12-11 20:11:10 +01:00
2023-12-11 21:41:51 +01:00
TeDeumUtility.init()
2023-12-11 20:11:10 +01:00
});
/* -------------------------------------------- */
function welcomeMessage() {
if (game.user.isGM) {
ChatMessage.create({
user: game.user.id,
whisper: [game.user.id],
2023-12-11 21:41:51 +01:00
content: `<div id="welcome-message-tedeum"><span class="rdd-roll-part">
<strong>Bienvenu dans TeDeum !</strong>` });
2023-12-11 20:11:10 +01:00
}
}
/* -------------------------------------------- */
// Register world usage statistics
function registerUsageCount(registerKey) {
if (game.user.isGM) {
game.settings.register(registerKey, "world-key", {
name: "Unique world key",
scope: "world",
config: false,
default: "",
type: String
});
let worldKey = game.settings.get(registerKey, "world-key")
if (worldKey == undefined || worldKey == "") {
worldKey = randomID(32)
game.settings.set(registerKey, "world-key", worldKey)
}
// Simple API counter
let regURL = `https://www.uberwald.me/fvtt_appcount/count.php?name="${registerKey}"&worldKey="${worldKey}"&version="${game.release.generation}.${game.release.build}"&system="${game.system.id}"&systemversion="${game.system.version}"`
//$.ajaxSetup({
//headers: { 'Access-Control-Allow-Origin': '*' }
//})
$.ajax(regURL)
}
}
/* -------------------------------------------- */
/* Foundry VTT Initialization */
/* -------------------------------------------- */
Hooks.once("ready", function () {
// User warning
if (!game.user.isGM && game.user.character == undefined) {
ui.notifications.info("Attention ! Aucun personnage relié au joueur !");
ChatMessage.create({
content: "<b>WARNING</b> Le joueur " + game.user.name + " n'est pas relié à un personnage !",
user: game.user._id
});
}
registerUsageCount(game.system.id)
welcomeMessage();
2023-12-11 21:41:51 +01:00
TeDeumUtility.ready()
2023-12-11 20:11:10 +01:00
})
/* -------------------------------------------- */
/* Foundry VTT Initialization */
/* -------------------------------------------- */
Hooks.on("chatMessage", (html, content, msg) => {
if (content[0] == '/') {
let regExp = /(\S+)/g;
let commands = content.match(regExp);
2023-12-11 21:41:51 +01:00
if (game.system.tedeum.commands.processChatCommand(commands, content, msg)) {
2023-12-11 20:11:10 +01:00
return false;
}
}
return true;
});