fvtt-hawkmoon-cyd/modules/hawkmoon-main.js

141 lines
4.6 KiB
JavaScript
Raw Normal View History

2022-10-22 11:09:48 +02:00
/**
* Hawkmoon system
* Author: Uberwald
* Software License: Prop
*/
/* -------------------------------------------- */
/* -------------------------------------------- */
// Import Modules
import { HawkmoonActor } from "./hawkmoon-actor.js";
import { HawkmoonItemSheet } from "./hawkmoon-item-sheet.js";
import { HawkmoonActorSheet } from "./hawkmoon-actor-sheet.js";
import { HawkmoonUtility } from "./hawkmoon-utility.js";
import { HawkmoonCombat } from "./hawkmoon-combat.js";
import { HawkmoonItem } from "./hawkmoon-item.js";
/* -------------------------------------------- */
/* Foundry VTT Initialization */
/* -------------------------------------------- */
/************************************************************************************/
Hooks.once("init", async function () {
console.log(`Initializing Hawkmoon RPG`);
/* -------------------------------------------- */
// preload handlebars templates
HawkmoonUtility.preloadHandlebarsTemplates();
/* -------------------------------------------- */
// Set an initiative formula for the system
CONFIG.Combat.initiative = {
formula: "1d6",
decimals: 1
};
/* -------------------------------------------- */
game.socket.on("system.fvtt-hawkmoon-cyd", data => {
HawkmoonUtility.onSocketMesssage(data);
});
/* -------------------------------------------- */
// Define custom Entity classes
CONFIG.Combat.documentClass = HawkmoonCombat
CONFIG.Actor.documentClass = HawkmoonActor
CONFIG.Item.documentClass = HawkmoonItem
2022-10-23 09:55:02 +02:00
game.system.hawkmosn = {
2022-10-22 11:09:48 +02:00
HawkmoonUtility
}
/* -------------------------------------------- */
// Register sheet application classes
Actors.unregisterSheet("core", ActorSheet);
Actors.registerSheet("fvtt-hawkmoon-cyd", HawkmoonActorSheet, { types: ["personnage"], makeDefault: true })
//Actors.registerSheet("fvtt-hawkmoon-cyd", HawkmoonNPCSheet, { types: ["npc"], makeDefault: false });
Items.unregisterSheet("core", ItemSheet);
Items.registerSheet("fvtt-hawkmoon-cyd", HawkmoonItemSheet, { makeDefault: true })
HawkmoonUtility.init();
2022-10-23 09:55:02 +02:00
2022-10-22 11:09:48 +02:00
});
/* -------------------------------------------- */
function welcomeMessage() {
ChatMessage.create({
user: game.user.id,
whisper: [game.user.id],
content: `<div id="welcome-message-Hawkmoon"><span class="rdd-roll-part">
2022-10-23 09:55:02 +02:00
<strong>Bienvenue dans Hawkmoon et le troisième Millénaire !</strong>
2022-10-22 11:09:48 +02:00
<p>Les livres de Hawkmoon sont nécessaires pour jouer : https://www.titam-france.fr</p>
<p>Hawkmoon est jeude rôle publié par Titam France/Sombres projets, tout les droits leur appartiennent.<p>
` });
}
/* -------------------------------------------- */
// Register world usage statistics
2022-10-23 09:55:02 +02:00
function registerUsageCount(registerKey) {
if (game.user.isGM) {
2022-10-22 11:09:48 +02:00
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")
2022-10-23 09:55:02 +02:00
if (worldKey == undefined || worldKey == "") {
2022-10-22 11:09:48 +02:00
worldKey = randomID(32)
2022-10-23 09:55:02 +02:00
game.settings.set(registerKey, "world-key", worldKey)
2022-10-22 11:09:48 +02:00
}
// 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({
2022-10-23 09:55:02 +02:00
//headers: { 'Access-Control-Allow-Origin': '*' }
2022-10-22 11:09:48 +02:00
//})
$.ajax(regURL)
}
}
/* -------------------------------------------- */
/* Foundry VTT Initialization */
/* -------------------------------------------- */
Hooks.once("ready", function () {
HawkmoonUtility.ready();
// User warning
if (!game.user.isGM && game.user.character == undefined) {
ui.notifications.info("Attention ! Aucun personnage n'est relié au joueur !");
ChatMessage.create({
content: "<b>ATTENTION</b> Le joueur " + game.user.name + " n'est relié à aucun personnage !",
user: game.user._id
});
}
2022-10-23 09:55:02 +02:00
2022-10-22 11:09:48 +02:00
registerUsageCount('fvtt-hawkmoon-cyd')
welcomeMessage()
2022-10-23 09:55:02 +02:00
// CSS patch for v9
if (game.version) {
let sidebar = document.getElementById("sidebar");
sidebar.style.width = "min-content";
}
2022-10-22 11:09:48 +02:00
});
/* -------------------------------------------- */
/* Foundry VTT Initialization */
/* -------------------------------------------- */
Hooks.on("chatMessage", (html, content, msg) => {
if (content[0] == '/') {
let regExp = /(\S+)/g;
let commands = content.match(regExp);
if (game.system.mournblade.commands.processChatCommand(commands, content, msg)) {
return false;
}
}
return true;
});