Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entering data #84

Open
EldarcDM opened this issue Jun 12, 2021 · 1 comment
Open

Entering data #84

EldarcDM opened this issue Jun 12, 2021 · 1 comment

Comments

@EldarcDM
Copy link

Hi!

Thanks for this lovely Shadow of the Demon Lord system. It's awesome and you can tell the effort you've put into it.

My only issue with the system is that it's not easy entering data. I mean, when you create monsters, spells, whatever, you have to click lots of times to open a window, get a dropdown menu, select, close, open another menu... etc. It's quite slow and boring. Is there any other way to enter data so the system recognises it? Maybe from a CSV or excel file... or something?

Thank you!

@michalzc
Copy link

michalzc commented Jul 16, 2021

@EldarcDM
Here is my way for creating content. I'm using yaml format, yaml2json utility and custom function to load arrays of entities into foundry. It's not a best way, but much more faster than messing with foundry UI. First create and item of desirable type and export it as json for reference. Then create yaml file with array of such objects, work with yaml files is much more comfortable. Convert it to json and import to foundry.
Array import function:

async function createEntity(entityClass, jsonStr) {
    let json = JSON.parse(jsonStr);
    var importFolder = game.folders.find(e => e.name === "Import" && e.type === entityClass.name);
    if(!importFolder) {
        var folderData = {name: "Import", type: entityClass.name, parent: null};
        importFolder = await Folder.create(folderData);
    }
    var folderId = importFolder.id;
    
    var elems;
    if(Array.isArray(json)) elems = json;
    else elems = [json];
    let elemsToAdd = elems.map(e => mergeObject(e, {folder: folderId}));
    return entityClass.create(elemsToAdd);
}


async function importDialog(entityClass) {
    let dlg = new Dialog({
        title: `Bulk ${entityClass.name}s Import`,
        content: await renderTemplate("templates/apps/import-data.html", {entity: 'Items', name: 'New Items'}),
        buttons: {
            import: {
                icon: '<i class="fas fa-file-import"></i>',
                label: "Import",
                callback: html => {
                    let form = html.find("form")[0];
                    if (!form.data.files.length) return ui.notifications.error("You did not upload a file!");
                    else readTextFromFile(form.data.files[0]).then(json => createEntity(entityClass, json));
                }
            },
            no: {
                icon: '<i class="fas fa-times"></i>',
                label: "Cancel"                
            }
        },
        default: "import"
    }, {
        width: 400
    }).render(true);
}

Example yaml file with spell:

---
-
  name: Example Spell
  type: spell
  img: systems/demonlord/assets/icons/skills/wings.webp
  data:
    description: >-
      There is a multiline spell description
      <b>html</b> tags are also allowed.
    tradition: Spell Tradition
    spelltype: Attack
    rank: 1
    attribute: Will
    area: >-
      A sphere with a 5-yard radius centered on a point you
      can reach
    action:
      against: Will
    activatedEffect:
      target:
        value: 5
        type: sphere

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants