This commit is contained in:
348
module/utils.mjs
348
module/utils.mjs
@@ -195,4 +195,352 @@ export default class FTLNomadUtils {
|
||||
document.documentElement.style.setProperty('--background-image-base', `linear-gradient(rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.8)), url("../assets/ui/${era}_background_main.webp")`);
|
||||
}
|
||||
|
||||
static getTechAgeKeyFromLabel(label) {
|
||||
return Object.keys(SYSTEM.TECH_AGES).find(key => game.i18n.localize(SYSTEM.TECH_AGES[key].label) === label);
|
||||
}
|
||||
|
||||
static async importPsionics() {
|
||||
// Create a psionics folder if it doesn't exist
|
||||
const psionicsFolder = game.folders.getName("Psionics") || await Folder.create({
|
||||
name: "Psionics", type: "Item"
|
||||
})
|
||||
if (!psionicsFolder) {
|
||||
console.error("Failed to create Psionics folder");
|
||||
return;
|
||||
}
|
||||
// Load the psionics JSON file
|
||||
const psionicsData = await fetch("systems/fvtt-ftl-nomad/assets/json_data/psionics.json")
|
||||
.then(response => response.json())
|
||||
.catch(error => {
|
||||
console.error("Failed to load psionics data:", error);
|
||||
return [];
|
||||
});
|
||||
// Import each psionic ability
|
||||
for (const psionic of psionicsData) {
|
||||
// Check if the psionic already exists
|
||||
const existingPsionic = game.items.find(i => i.name === psionic.name && i.type === "psionic");
|
||||
if (existingPsionic) {
|
||||
console.warn(`Psionic ${psionic.name} already exists, skipping import.`);
|
||||
continue;
|
||||
}
|
||||
// Create the psionic item
|
||||
await Item.create({
|
||||
name: psionic.name,
|
||||
type: "psionic",
|
||||
img: "systems/fvtt-ftl-nomad/assets/icons/icon_psionic.svg",
|
||||
system: {
|
||||
description: psionic.description,
|
||||
},
|
||||
folder: psionicsFolder.id
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static async importTalents() {
|
||||
// Create a talents folder if it doesn't exist
|
||||
const talentsFolder = game.folders.getName("Talents") || await Folder.create({
|
||||
name: "Talents", type: "Item"
|
||||
})
|
||||
if (!talentsFolder) {
|
||||
console.error("Failed to create Talents folder");
|
||||
return;
|
||||
}
|
||||
// Load the talents JSON file
|
||||
const talentsData = await fetch("systems/fvtt-ftl-nomad/assets/json_data/talents.json")
|
||||
.then(response => response.json())
|
||||
.catch(error => {
|
||||
console.error("Failed to load talents data:", error);
|
||||
return [];
|
||||
});
|
||||
// Import each talent
|
||||
for (const talent of talentsData) {
|
||||
// Check if the talent already exists
|
||||
const existingTalent = game.items.find(i => i.name === talent.name && i.type === "talent");
|
||||
if (existingTalent) {
|
||||
console.warn(`Talent ${talent.name} already exists, skipping import.`);
|
||||
continue;
|
||||
}
|
||||
talent.advantage = false;
|
||||
if (talent.description.includes(" +1D")) {
|
||||
talent.advantage = true
|
||||
}
|
||||
// Create the talent item
|
||||
await Item.create({
|
||||
name: talent.name,
|
||||
type: "talent",
|
||||
img: "systems/fvtt-ftl-nomad/assets/icons/icon_talent.svg",
|
||||
system: {
|
||||
description: talent.description,
|
||||
isAdvantage: talent.advantage,
|
||||
},
|
||||
folder: talentsFolder.id
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static async importImplants() {
|
||||
// Create a implants folder if it doesn't exist
|
||||
const implantsFolder = game.folders.getName("Implants") || await Folder.create({
|
||||
name: "Implants", type: "Item"
|
||||
})
|
||||
if (!implantsFolder) {
|
||||
console.error("Failed to create Implants folder");
|
||||
return;
|
||||
}
|
||||
// Load the implants JSON file
|
||||
const implantsData = await fetch("systems/fvtt-ftl-nomad/assets/json_data/implants.json")
|
||||
.then(response => response.json())
|
||||
.catch(error => {
|
||||
console.error("Failed to load implants data:", error);
|
||||
return [];
|
||||
});
|
||||
// Import each implant
|
||||
for (const implant of implantsData) {
|
||||
// Check if the implant already exists
|
||||
const existingImplant = game.items.find(i => i.name === implant.name && i.type === "implant");
|
||||
if (existingImplant) {
|
||||
console.warn(`Implant ${implant.name} already exists, skipping import.`);
|
||||
continue;
|
||||
}
|
||||
if (!Number(implant.cost)) {
|
||||
implant.cost = 1000000;
|
||||
}
|
||||
// Create the implant item
|
||||
await Item.create({
|
||||
name: implant.name,
|
||||
type: "implant",
|
||||
img: "systems/fvtt-ftl-nomad/assets/icons/icon_implant.svg",
|
||||
system: {
|
||||
cost: implant.cost,
|
||||
loss: implant.loss,
|
||||
techAge: this.getTechAgeKeyFromLabel(implant.tech_age),
|
||||
description: implant.description,
|
||||
},
|
||||
folder: implantsFolder.id
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static async importDrugs() {
|
||||
// Create a drugs folder if it doesn't exist
|
||||
const drugsFolder = game.folders.getName("Drugs") || await Folder.create({
|
||||
name: "Drugs", type: "Item"
|
||||
})
|
||||
if (!drugsFolder) {
|
||||
console.error("Failed to create Drugs folder");
|
||||
return;
|
||||
}
|
||||
// Load the drugs JSON file
|
||||
const drugsData = await fetch("systems/fvtt-ftl-nomad/assets/json_data/drugs.json")
|
||||
.then(response => response.json())
|
||||
.catch(error => {
|
||||
console.error("Failed to load drugs data:", error);
|
||||
return [];
|
||||
});
|
||||
// Import each drug
|
||||
for (const drug of drugsData) {
|
||||
// Check if the drug already exists
|
||||
const existingDrug = game.items.find(i => i.name === drug.name && i.type === "drug");
|
||||
if (existingDrug) {
|
||||
console.warn(`Drug ${drug.name} already exists, skipping import.`);
|
||||
continue;
|
||||
}
|
||||
// Create the drug item
|
||||
await Item.create({
|
||||
name: drug.name,
|
||||
type: "equipment",
|
||||
img: "systems/fvtt-ftl-nomad/assets/icons/icon_equipment.svg",
|
||||
system: {
|
||||
description: drug.description,
|
||||
cost: drug.cost,
|
||||
techAge: this.getTechAgeKeyFromLabel(drug.tech_age),
|
||||
},
|
||||
folder: drugsFolder.id
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static async importEquipments() {
|
||||
// Create a equipments folder if it doesn't exist
|
||||
const equipmentsFolder = game.folders.getName("Equipments") || await Folder.create({
|
||||
name: "Equipments", type: "Item"
|
||||
})
|
||||
if (!equipmentsFolder) {
|
||||
console.error("Failed to create Equipments folder");
|
||||
return;
|
||||
}
|
||||
// Load the equipments JSON file
|
||||
const equipmentsData = await fetch("systems/fvtt-ftl-nomad/assets/json_data/exploration_equipment.json")
|
||||
.then(response => response.json())
|
||||
.catch(error => {
|
||||
console.error("Failed to load equipments data:", error);
|
||||
return [];
|
||||
});
|
||||
// Import each equipment
|
||||
for (const equipment of equipmentsData) {
|
||||
// Check if the equipment already exists
|
||||
const existingEquipment = game.items.find(i => i.name === equipment.name && i.type === "equipment");
|
||||
if (existingEquipment) {
|
||||
console.warn(`Equipment ${equipment.name} already exists, skipping import.`);
|
||||
continue;
|
||||
}
|
||||
if (!Number(equipment.cost)) {
|
||||
equipment.cost = 1000000;
|
||||
}
|
||||
|
||||
// Create the equipment item
|
||||
await Item.create({
|
||||
name: equipment.name,
|
||||
type: "equipment",
|
||||
img: "systems/fvtt-ftl-nomad/assets/icons/icon_equipment.svg",
|
||||
system: {
|
||||
description: equipment.description,
|
||||
cost: equipment.cost,
|
||||
techAge: this.getTechAgeKeyFromLabel(equipment.tech_age),
|
||||
},
|
||||
folder: equipmentsFolder.id
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static async importDistanceWeapons() {
|
||||
// Create a distance weapons folder if it doesn't exist
|
||||
const distanceWeaponsFolder = game.folders.getName("Vehicle Weapons") || await Folder.create({
|
||||
name: "Vehicle Weapons", type: "Item"
|
||||
})
|
||||
if (!distanceWeaponsFolder) {
|
||||
console.error("Failed to create Distance Weapons folder");
|
||||
return;
|
||||
}
|
||||
// Load the distance weapons JSON file
|
||||
const distanceWeaponsData = await fetch("systems/fvtt-ftl-nomad/assets/json_data/vehicle_weapons.json")
|
||||
.then(response => response.json())
|
||||
.catch(error => {
|
||||
console.error("Failed to load distance weapons data:", error);
|
||||
return [];
|
||||
});
|
||||
|
||||
// Import each distance weapon
|
||||
for (const weapon of distanceWeaponsData) {
|
||||
// Check if the weapon already exists
|
||||
const existingWeapon = game.items.find(i => i.name === weapon.name && i.type === "weapon");
|
||||
if (existingWeapon) {
|
||||
console.warn(`Weapon ${weapon.name} already exists, skipping import.`);
|
||||
continue;
|
||||
}
|
||||
// Create the weapon item
|
||||
await Item.create({
|
||||
name: weapon.name,
|
||||
type: "weapon",
|
||||
img: "systems/fvtt-ftl-nomad/assets/icons/icon_weapon.svg",
|
||||
system: {
|
||||
description: weapon.description,
|
||||
damage: weapon.damage,
|
||||
techAge: this.getTechAgeKeyFromLabel(weapon.tech_age),
|
||||
weaponType: SYSTEM.WEAPON_TYPES.vehicle.id,
|
||||
rangeType: weapon.range.toLowerCase(),
|
||||
enc: 0,
|
||||
aspect: weapon.aspects.join(", "),
|
||||
cost: weapon.cost || 0,
|
||||
ammoCost: weapon.ammo_cost || 0,
|
||||
magazine: weapon.mag || 1,
|
||||
},
|
||||
folder: distanceWeaponsFolder.id
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static async importGrenadeWeapons() {
|
||||
// Create a grenade weapons folder if it doesn't exist
|
||||
const grenadeWeaponsFolder = game.folders.getName("Grenade") || await Folder.create({
|
||||
name: "Grenade", type: "Item"
|
||||
})
|
||||
if (!grenadeWeaponsFolder) {
|
||||
console.error("Failed to create Grenade Weapons folder");
|
||||
return;
|
||||
}
|
||||
// Load the grenade weapons JSON file
|
||||
const grenadeWeaponsData = await fetch("systems/fvtt-ftl-nomad/assets/json_data/grenades.json")
|
||||
.then(response => response.json())
|
||||
.catch(error => {
|
||||
console.error("Failed to load grenade weapons data:", error);
|
||||
return [];
|
||||
});
|
||||
|
||||
// Import each grenade weapon
|
||||
for (const weapon of grenadeWeaponsData) {
|
||||
// Check if the weapon already exists
|
||||
const existingWeapon = game.items.find(i => i.name === weapon.name && i.type === "weapon");
|
||||
if (existingWeapon) {
|
||||
console.warn(`Weapon ${weapon.name} already exists, skipping import.`);
|
||||
continue;
|
||||
}
|
||||
// Create the weapon item
|
||||
await Item.create({
|
||||
name: weapon.name,
|
||||
type: "weapon",
|
||||
img: "systems/fvtt-ftl-nomad/assets/icons/icon_weapon.svg",
|
||||
system: {
|
||||
description: weapon.description,
|
||||
damage: weapon.damage,
|
||||
techAge: this.getTechAgeKeyFromLabel(weapon.tech_age),
|
||||
weaponType: SYSTEM.WEAPON_TYPES.grenade.id,
|
||||
rangeType: SYSTEM.WEAPON_RANGE.thrownweapon.id,
|
||||
enc: 0,
|
||||
aspect: weapon.aspects.join(", "),
|
||||
cost: weapon.cost || 0,
|
||||
ammoCost: 0,
|
||||
},
|
||||
folder: grenadeWeaponsFolder.id
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static async importMeleeWeapons() {
|
||||
// Create a melee weapons folder if it doesn't exist
|
||||
const meleeWeaponsFolder = game.folders.getName("Melee Weapons") || await Folder.create({
|
||||
name: "Melee Weapons", type: "Item"
|
||||
})
|
||||
if (!meleeWeaponsFolder) {
|
||||
console.error("Failed to create Melee Weapons folder");
|
||||
return;
|
||||
}
|
||||
// Load the melee weapons JSON file
|
||||
const meleeWeaponsData = await fetch("systems/fvtt-ftl-nomad/assets/json_data/weapon_melee.json")
|
||||
.then(response => response.json())
|
||||
.catch(error => {
|
||||
console.error("Failed to load melee weapons data:", error);
|
||||
return [];
|
||||
});
|
||||
|
||||
console.log("Melee Weapons Data", meleeWeaponsData);
|
||||
// Import each melee weapon
|
||||
for (const weapon of meleeWeaponsData) {
|
||||
// Check if the weapon already exists
|
||||
const existingWeapon = game.items.find(i => i.name === weapon.name && i.type === "weapon");
|
||||
if (existingWeapon) {
|
||||
console.warn(`Weapon ${weapon.name} already exists, skipping import.`);
|
||||
continue;
|
||||
}
|
||||
// Create the weapon item
|
||||
await Item.create({
|
||||
name: weapon.name,
|
||||
type: "weapon",
|
||||
img: "systems/fvtt-ftl-nomad/assets/icons/icon_weapon.svg",
|
||||
system: {
|
||||
description: weapon.description,
|
||||
damage: weapon.damage,
|
||||
techAge: this.getTechAgeKeyFromLabel(weapon.tech_age),
|
||||
weaponType: SYSTEM.WEAPON_TYPES.melee.id,
|
||||
rangeType: SYSTEM.WEAPON_RANGE.melee.id,
|
||||
enc: 0,
|
||||
aspect: weapon.aspects.join(", "),
|
||||
cost: weapon.cost || 0,
|
||||
ammoCost: 0,
|
||||
},
|
||||
folder: meleeWeaponsFolder.id
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user