mivalsten / ddb-dm-screen

MIT License
30 stars 10 forks source link

Direct Data Pull #32

Open TeaWithLucas opened 4 years ago

TeaWithLucas commented 4 years ago

I know you guys implimented iframes as using the direct json wasn't a good option, so i have been looking how I can basically use the javascript that D&D Beyond use for calculating and processing the json files. Today I managed it! The result of my test implementation is here: https://github.com/TeaWithLucas/DNDBeyond-DM-Screen/blob/JSON/test-direct-data.user.js Basically, for now, the retrieved data is just logged to console, the output sample is below. These are exactly what the character sheet outputs and if any of their code changes, it won't affect this script as thie code is imported. I am currently modifying the main script so that on autoreload, instead of deleting everything and doing the script from scratch, only the innerhtml in the specified elements are changed which so also speed things up! Each character can be loaded with the parsedata(characterId) Any feedback or questions are welcome! { abilities: Array(6) [ {…}, {…}, {…}, … ], abilityLookup: Object { 1: {…}, 2: {…}, 3: {…}, … }, activatables: Array(24) [ {…}, {…}, {…}, … ], age: 17, alignment: Object { availableToCharacter: true, description: "Chaotic neutral (CN) creatures follow their whims, holding their personal freedom above all else. Many barbarians and rogues, and some bards, are chaotic neutral.", id: 6, … }, armorClass: 18, attacks: Array(5) [ {…}, {…}, {…}, … ], attacksPerActionInfo: Object { value: 2, restriction: "" }, attunableArmor: Array [], attunableGear: Array [], attunableWeapons: Array [], attunedSlots: Array(3) [ {…}, {…}, null ], avatarUrl: "https://www.dndbeyond.com/avatars/6595/531/636991657997905650.png?width=150&height=150&fit=crop&quality=95&auto=webp", background: Object { customBackground: {…}, definition: {…}, hasCustomBackground: false, … }, carryCapacity: 150, choiceInfo: Object { proficiencyModifiers: (14) […], expertiseModifiers: [], languageModifiers: (6) […], … }, classes: Array [ {…} ], conditions: Array [], creatures: Array(3) [ {…}, {…}, {…} ], currencies: Object { cp: 0, ep: 0, gp: 286, … }, currentXp: 165888, customItems: Array(8) [ {…}, {…}, {…}, … ], customSkills: Array [], deathSaveInfo: Object { failCount: 0, successCount: 0, isStabilized: false, … }, encumberedWeight: 50, equipped: Object { armorItems: (1) […], weaponItems: (4) […], gearItems: (5) […] }, eyes: "Brown", fails: 0, faith: null, feats: Array [ {…}, {…} ], gender: "", hair: "Beige Feathers", hasInitiativeAdvantage: false, hasMaxAttunedItems: false, hasSpells: true, heavilyEncumberedWeight: 100, height: "4'11", hitPointInfo: Object { baseHp: 94, baseTotalHp: 109, possibleMaxHitPoints: 165, … }, immunities: Array [], initiative: 4, inspiration: false, inventory: Array(34) [ {…}, {…}, {…}, … ], levelSpells: Array(10) [ [], (3) […], (6) […], … ], name: "Rhillik Qreqiss", notes: Object { allies: "Clan of the Star Mountains", backstory: "\tGrew up in Star Mountins near Unicorn Run, most Aarakocra killed by achent green dragon, clan wants to find and kill them.\n\tExplorer, seen around the world, hates dragons.\n\n\nYou have advantage on animal handling with owlbears.", enemies: "An unknown Ancient green dragon \nChromocratic dragoniods \n", … }, pactMagicSlots: Array [], passiveInsight: 18, passiveInvestigation: 12, passivePerception: 18, preferences: Object { abilityScoreDisplayType: 2, encumbranceType: 1, enforceFeatRules: true, … }, proficiencyBonus: 5, proficiencyGroups: Array(4) [ {…}, {…}, {…}, … ], pushDragLiftWeight: 300, race: Object { isSubRace: false, baseRaceName: "Aarakocra", entityRaceId: 4, … }, resistances: Array [ {…} ], ritualSpells: Array [], ruleData: Object { minExhaustionLevel: 1, maxExhaustionLevel: 6, maxDeathsavesFail: 3, … }, savingThrowDiceAdjustments: Array [ {…}, {…} ], senses: Object { 1: 0, 2: 0, 3: 0, … }, situationalBonusSavingThrowsLookup: Object { }, size: Object { id: 4, entityTypeId: 127108918, name: "Medium", … }, skills: Array(18) [ {…}, {…}, {…}, … ], skin: "", speeds: Object { walk: 35, fly: 60, climb: 0, … }, spellCasterInfo: Object { characterLevel: 15, firstAvailableSpellSlotLevel: 1, lastAvailableSpellSlotLevel: 4, … }, spellSlots: Array(4) [ {…}, {…}, {…}, … ], startingClass: Object { definitionId: 0, entityTypeId: 1446578651, hitDiceUsed: 0, … }, successes: 0, totalClassLevel: 15, totalWeight: 147.5, traits: Object { appearance: null, bonds: null, flaws: null, … }, unequipped: Object { armorItems: [], weaponItems: [], gearItems: (24) […] }, vulnerabilities: Array [], weaponSpellDamageGroups: Array [], weight: 147.5, weightSpeedType: "normal", xpInfo: Object { classLevel: 15, currentLevel: 15, currentLevelXp: 165888, … } }

TeaWithLucas commented 4 years ago

A little update, the example can now handle multiple inputs

mivalsten commented 4 years ago

I'm shit at JS, but do I understand correctly that you found a way to get final character values instead of raw JSON that you need to reimplement all mechanics?

TeaWithLucas commented 4 years ago

@mivalsten , It's not an easy language to learn at all! I've actually finished implementing it if you want to see it in action: https://github.com/TeaWithLucas/DNDBeyond-DM-Screen Yes the script does, it basically retrieves the JSON data and passes them through D&DBeyonds own functions returning everything that their own site uses. This means all the data returned is exactly the same as what they use on the character sheet and as a bonus, if they ever change how the json or functions work, it will automatically update accordingly as the json and rulesets are directly passed to the functions.

mivalsten commented 4 years ago

Nice. <3 Love it very much.

mivalsten commented 4 years ago

Wow, just tested it and I fricking love how fast it works! <3

TeaWithLucas commented 4 years ago

Haha, I'm glad you like it so much :) It's a much more efficient way of getting the data, each webpage you load is doing the same and many more calculations, so it just cuts out the excess. Let me know if you have any questions on how it works.