Importers ready
This commit is contained in:
140
module/utils.mjs
140
module/utils.mjs
@@ -450,6 +450,146 @@ export default class FTLNomadUtils {
|
||||
}
|
||||
}
|
||||
|
||||
static async importStarships() {
|
||||
// Create a starships folder if it doesn't exist
|
||||
const starshipsFolder = game.folders.getName("Starships") || await Folder.create({
|
||||
name: "Starships", type: "Actor"
|
||||
})
|
||||
if (!starshipsFolder) {
|
||||
console.error("Failed to create Starships folder");
|
||||
return;
|
||||
}
|
||||
// Load the starships JSON file
|
||||
const starshipsData = await fetch("systems/fvtt-ftl-nomad/assets/json_data/starships.json")
|
||||
.then(response => response.json())
|
||||
.catch(error => {
|
||||
console.error("Failed to load starships data:", error);
|
||||
return [];
|
||||
});
|
||||
|
||||
// Import each starship
|
||||
for (const starship of starshipsData) {
|
||||
// Check if the starship already exists
|
||||
const existingStarship = game.actors.find(a => a.name === starship.name && a.type === "starship");
|
||||
if (existingStarship) {
|
||||
console.warn(`Starship ${starship.name} already exists, skipping import.`);
|
||||
continue;
|
||||
}
|
||||
// Create the starship actor
|
||||
await Actor.create({
|
||||
name: starship.name,
|
||||
type: "starship",
|
||||
img: "systems/fvtt-ftl-nomad/assets/icons/icon_starship.svg",
|
||||
system: {
|
||||
description: starship.description,
|
||||
agility: starship.agility,
|
||||
hullType: starship.hullType.toLowerCase(),
|
||||
endurance: starship.endurance,
|
||||
armor: starship.armor,
|
||||
crew: starship.crew,
|
||||
cargo: starship.cargo,
|
||||
guns: starship.guns,
|
||||
travelMultiplier: starship.travelMultiplier,
|
||||
cost: starship.cost || 0,
|
||||
monthlyCost: starship.monthlyCost || 0,
|
||||
damages: starship.damages,
|
||||
},
|
||||
folder: starshipsFolder.id
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static async importVehicles() {
|
||||
// Create a vehicles folder if it doesn't exist
|
||||
const vehiclesFolder = game.folders.getName("Vehicles") || await Folder.create({
|
||||
name: "Vehicles", type: "Actor"
|
||||
})
|
||||
if (!vehiclesFolder) {
|
||||
console.error("Failed to create Vehicles folder");
|
||||
return;
|
||||
}
|
||||
// Load the vehicles JSON file
|
||||
const vehiclesData = await fetch("systems/fvtt-ftl-nomad/assets/json_data/vehicles.json")
|
||||
.then(response => response.json())
|
||||
.catch(error => {
|
||||
console.error("Failed to load vehicles data:", error);
|
||||
return [];
|
||||
});
|
||||
|
||||
// Import each vehicle
|
||||
for (const vehicle of vehiclesData) {
|
||||
// Check if the vehicle already exists
|
||||
const existingVehicle = game.items.find(i => i.name === vehicle.name && i.type === "vehicle");
|
||||
if (existingVehicle) {
|
||||
console.warn(`Vehicle ${vehicle.name} already exists, skipping import.`);
|
||||
continue;
|
||||
}
|
||||
// Create the vehicle item
|
||||
await Actor.create({
|
||||
name: vehicle.name,
|
||||
type: "vehicle",
|
||||
img: "systems/fvtt-ftl-nomad/assets/icons/icon_vehicle.svg",
|
||||
system: {
|
||||
description: vehicle.description,
|
||||
agility: vehicle.agility,
|
||||
armor: vehicle.armor,
|
||||
cargo: vehicle.cargo,
|
||||
crew: vehicle.crew,
|
||||
force: vehicle.force,
|
||||
range: vehicle.range,
|
||||
speed: vehicle.speed,
|
||||
techAge: this.getTechAgeKeyFromLabel(vehicle.tech_age),
|
||||
tonnage: vehicle.tonnage,
|
||||
damages: vehicle.damages,
|
||||
cost: vehicle.cost || 0,
|
||||
},
|
||||
folder: vehiclesFolder.id
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static async importArmors() {
|
||||
// Create an armors folder if it doesn't exist
|
||||
const armorsFolder = game.folders.getName("Armors") || await Folder.create({
|
||||
name: "Armors", type: "Item"
|
||||
})
|
||||
if (!armorsFolder) {
|
||||
console.error("Failed to create Armors folder");
|
||||
return;
|
||||
}
|
||||
// Load the armors JSON file
|
||||
const armorsData = await fetch("systems/fvtt-ftl-nomad/assets/json_data/armors.json")
|
||||
.then(response => response.json())
|
||||
.catch(error => {
|
||||
console.error("Failed to load armors data:", error);
|
||||
return [];
|
||||
});
|
||||
|
||||
// Import each armor
|
||||
for (const armor of armorsData) {
|
||||
// Check if the armor already exists
|
||||
const existingArmor = game.items.find(i => i.name === armor.name && i.type === "armor");
|
||||
if (existingArmor) {
|
||||
console.warn(`Armor ${armor.name} already exists, skipping import.`);
|
||||
continue;
|
||||
}
|
||||
// Create the armor item
|
||||
await Item.create({
|
||||
name: armor.name,
|
||||
type: "armor",
|
||||
img: "systems/fvtt-ftl-nomad/assets/icons/icon_armor.svg",
|
||||
system: {
|
||||
description: armor.description,
|
||||
enc: armor.enc || 0,
|
||||
techAge: this.getTechAgeKeyFromLabel(armor.tech_age),
|
||||
cost: armor.cost || 0,
|
||||
protection: armor.protection || 0,
|
||||
},
|
||||
folder: armorsFolder.id
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static async importGrenadeWeapons() {
|
||||
// Create a grenade weapons folder if it doesn't exist
|
||||
const grenadeWeaponsFolder = game.folders.getName("Grenade") || await Folder.create({
|
||||
|
||||
Reference in New Issue
Block a user