Datagen is generated inside convinient mongodb schemas
This commit is contained in:
parent
1e4072dae6
commit
2a12f70c91
12
backend/models/DatagenCollection.js
Normal file
12
backend/models/DatagenCollection.js
Normal file
@ -0,0 +1,12 @@
|
||||
const mongoose = require("mongoose");
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const DatagenCollectionSchema = new Schema({
|
||||
name: {type: String, required: true},
|
||||
id: { type: String, required: true },
|
||||
package: { type: String, required: true},
|
||||
desc: { type: String },
|
||||
entries: [ {type: mongoose.Types.ObjectId, ref: "DatagenEntry"} ],
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('DatagenCollection', DatagenCollectionSchema);
|
11
backend/models/DatagenEntry.js
Normal file
11
backend/models/DatagenEntry.js
Normal file
@ -0,0 +1,11 @@
|
||||
const mongoose = require("mongoose");
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const DatagenEntrySchema = new Schema({
|
||||
id: {type: String, required: true},
|
||||
schema: { type: String, required: true},
|
||||
data: { type: Object },
|
||||
datagen_collection: {type: mongoose.Types.ObjectId, ref: "DatagenCollection"},
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('DatagenEntry', DatagenEntrySchema);
|
@ -4,14 +4,19 @@ const path = require('path');
|
||||
|
||||
const basePath = path.resolve(__dirname, '../')
|
||||
|
||||
const DatagenCollection = require("../models/DatagenCollection");
|
||||
const DatagenEntry = require('../models/DatagenEntry');
|
||||
|
||||
async function datagenTask(models) {
|
||||
console.log("Inicializing datagen task");
|
||||
|
||||
await DatagenCollection.deleteMany({});
|
||||
await DatagenEntry.deleteMany({});
|
||||
|
||||
const datagenPluginFolders = fs.readdirSync(path.resolve(basePath + '/datagen'));
|
||||
datagenPluginFolders.forEach(datagenPluginFolder => {
|
||||
const datagenFolders = fs.readdirSync(path.resolve(basePath + '/datagen/' + datagenPluginFolder));
|
||||
datagenFolders.forEach(datagenFolder => {
|
||||
console.log(datagenFolder);
|
||||
let folder = basePath + '/datagen/' + datagenPluginFolder + "/" + datagenFolder;
|
||||
const datagenInfo = JSON.parse(fs.readFileSync(
|
||||
path.resolve(folder + "/datagen.json")
|
||||
@ -26,6 +31,13 @@ async function datagenTask(models) {
|
||||
|
||||
async function resolveDatagen(models, path, info){
|
||||
// Do locale translation with info somewhere...?
|
||||
const datagenCollection = await DatagenCollection.create({
|
||||
name: info.name,
|
||||
id: info.id,
|
||||
desc: info.desc,
|
||||
package: info.package
|
||||
});
|
||||
|
||||
const modelNames = models[info.package].modelNames;
|
||||
modelNames.forEach(modelName => {
|
||||
if(Object.keys(mongoose.models).includes(modelName)){
|
||||
@ -36,7 +48,7 @@ async function resolveDatagen(models, path, info){
|
||||
let modelPath = path + "/data/" + modelLastName;
|
||||
jsonFiles.forEach(file => {
|
||||
if(fs.lstatSync(modelPath + "/" + file).isFile()){
|
||||
appendDatagen(modelPath + "/" + file, modelName, info);
|
||||
appendDatagen(modelPath + "/" + file, modelName, info, datagenCollection);
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -44,8 +56,15 @@ async function resolveDatagen(models, path, info){
|
||||
})
|
||||
}
|
||||
|
||||
async function appendDatagen(file, modelName, info){
|
||||
async function appendDatagen(file, modelName, info, datagenCollection){
|
||||
// "Appending " + file + " to model " + modelName + " from " + info.id + " for package " + info.package
|
||||
let fileData = JSON.parse(fs.readFileSync(file));
|
||||
await DatagenEntry.create({
|
||||
id: fileData.id,
|
||||
data: fileData.value,
|
||||
schema: modelName,
|
||||
datagen_collection: datagenCollection
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
@ -1,3 +1,4 @@
|
||||
{
|
||||
|
||||
"id": "effects/test_effect",
|
||||
"value": {}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
{
|
||||
|
||||
"id": "consumables/test_consumable",
|
||||
"value": {}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
{
|
||||
|
||||
"id": "container/test_container",
|
||||
"value": {}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
{
|
||||
|
||||
"id": "equipment/test_equipment",
|
||||
"value": {}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
{
|
||||
|
||||
"id": "feature/test_feature",
|
||||
"value": {}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
{
|
||||
|
||||
"id": "spells/test_spell",
|
||||
"value": {}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
{
|
||||
|
||||
"id": "tools/test_tool",
|
||||
"value": {}
|
||||
}
|
@ -1,3 +1,19 @@
|
||||
{
|
||||
|
||||
"id": "weapon/test_weapon",
|
||||
"value": {
|
||||
"name": "Test datagen weapon",
|
||||
"type": "Weapon",
|
||||
"data": {},
|
||||
"info": {
|
||||
"icon": "icons/weapons/ammunition/shot-round-blue.webp",
|
||||
"weapon_type": "Natural",
|
||||
"rarity": "Rare",
|
||||
"quantity": "1",
|
||||
"weight": "10",
|
||||
"price": "10",
|
||||
"properties": [
|
||||
"Finesse"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
{
|
||||
|
||||
"id": "monsters/test_monster",
|
||||
"value": {}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
{
|
||||
|
||||
"id": "classes/test_class",
|
||||
"value": {}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
{
|
||||
|
||||
"id": "races/test_race",
|
||||
"value": {}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
{
|
||||
|
||||
"id": "table/test_table",
|
||||
"value": {}
|
||||
}
|
Loading…
Reference in New Issue
Block a user