Grabbed dndbeyond's source code
``` ~/go/bin/sourcemapper -output ddb -jsurl https://media.dndbeyond.com/character-app/static/js/main.90aa78c5.js ```
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
*
|
||||
* @param note
|
||||
*/
|
||||
export function getType(note) {
|
||||
return note.type;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
export var NoteTypeEnum;
|
||||
(function (NoteTypeEnum) {
|
||||
NoteTypeEnum["GROUP"] = "GROUP";
|
||||
NoteTypeEnum["PLAIN_TEXT"] = "PLAIN_TEXT";
|
||||
NoteTypeEnum["TOOLTIP"] = "TOOLTIP";
|
||||
NoteTypeEnum["DAMAGE"] = "DAMAGE";
|
||||
NoteTypeEnum["DISADVANTAGE_ICON"] = "DISADVANTAGE_ICON";
|
||||
NoteTypeEnum["DISTANCE"] = "DISTANCE";
|
||||
NoteTypeEnum["AOE_ICON"] = "AOE_ICON";
|
||||
})(NoteTypeEnum || (NoteTypeEnum = {}));
|
||||
export var DisplayIntentionEnum;
|
||||
(function (DisplayIntentionEnum) {
|
||||
DisplayIntentionEnum["SCALED"] = "scaled";
|
||||
DisplayIntentionEnum["POSITIVE"] = "positive";
|
||||
DisplayIntentionEnum["NEGATIVE"] = "negative";
|
||||
})(DisplayIntentionEnum || (DisplayIntentionEnum = {}));
|
||||
@@ -0,0 +1,66 @@
|
||||
import { NoteTypeEnum } from './constants';
|
||||
export function createGroup(notes, separator = ' ', key = null) {
|
||||
if (!notes.length) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
type: NoteTypeEnum.GROUP,
|
||||
data: {
|
||||
key,
|
||||
separator,
|
||||
notes,
|
||||
},
|
||||
};
|
||||
}
|
||||
export function createPlainText(text, displayIntention = null) {
|
||||
return {
|
||||
type: NoteTypeEnum.PLAIN_TEXT,
|
||||
data: {
|
||||
text,
|
||||
displayIntention,
|
||||
},
|
||||
};
|
||||
}
|
||||
export function createTooltip(text, tooltip = null, tooltipOpts = {}, displayIntention = null) {
|
||||
return {
|
||||
type: NoteTypeEnum.TOOLTIP,
|
||||
data: {
|
||||
text,
|
||||
tooltip,
|
||||
displayIntention,
|
||||
tooltipOpts,
|
||||
},
|
||||
};
|
||||
}
|
||||
export function createDamage(type, damage, info = '') {
|
||||
return {
|
||||
type: NoteTypeEnum.DAMAGE,
|
||||
data: {
|
||||
type,
|
||||
damage,
|
||||
info,
|
||||
},
|
||||
};
|
||||
}
|
||||
export function createDisadvantageIcon() {
|
||||
return {
|
||||
type: NoteTypeEnum.DISADVANTAGE_ICON,
|
||||
data: {},
|
||||
};
|
||||
}
|
||||
export function createDistance(distance) {
|
||||
return {
|
||||
type: NoteTypeEnum.DISTANCE,
|
||||
data: {
|
||||
distance,
|
||||
},
|
||||
};
|
||||
}
|
||||
export function createAoeIcon(type) {
|
||||
return {
|
||||
type: NoteTypeEnum.AOE_ICON,
|
||||
data: {
|
||||
type,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import * as NoteAccessors from './accessors';
|
||||
import * as NoteConstants from './constants';
|
||||
import * as NoteGenerators from './generators';
|
||||
import * as NoteTypings from './typings';
|
||||
import * as NoteUtils from './utils';
|
||||
export * from './constants';
|
||||
export * from './typings';
|
||||
export { NoteAccessors, NoteGenerators, NoteUtils };
|
||||
export default Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, NoteAccessors), NoteConstants), NoteGenerators), NoteTypings), NoteUtils);
|
||||
@@ -0,0 +1,65 @@
|
||||
import { DiceRenderers } from '../Dice';
|
||||
import { FormatUtils } from '../Format';
|
||||
import { getType } from './accessors';
|
||||
import { DisplayIntentionEnum, NoteTypeEnum } from './constants';
|
||||
function renderNotePlainText(note) {
|
||||
return `${note.data.text}${note.data.displayIntention === DisplayIntentionEnum.SCALED ? '*' : ''}`;
|
||||
}
|
||||
function renderNoteDistance(note) {
|
||||
return FormatUtils.renderDistance(note.data.distance);
|
||||
}
|
||||
function renderNoteAoeIcon(note) {
|
||||
return ` ${note.data.type}`; // space intentional
|
||||
}
|
||||
function renderNoteDamage(note) {
|
||||
let damageDisplay = '';
|
||||
if (note.data.damage !== null) {
|
||||
if (typeof note.data.damage === 'number') {
|
||||
damageDisplay = String(note.data.damage);
|
||||
}
|
||||
else {
|
||||
damageDisplay = DiceRenderers.renderDice(note.data.damage);
|
||||
}
|
||||
}
|
||||
return `${damageDisplay} ${note.data.type}`.trim();
|
||||
}
|
||||
function renderNoteDisadvantageIcon() {
|
||||
return ' Disadvantage'; // space intentional
|
||||
}
|
||||
function renderNote(note) {
|
||||
if (note === null) {
|
||||
return null;
|
||||
}
|
||||
switch (getType(note)) {
|
||||
case NoteTypeEnum.PLAIN_TEXT:
|
||||
case NoteTypeEnum.TOOLTIP:
|
||||
return renderNotePlainText(note);
|
||||
case NoteTypeEnum.DISTANCE:
|
||||
return renderNoteDistance(note);
|
||||
case NoteTypeEnum.AOE_ICON:
|
||||
return renderNoteAoeIcon(note);
|
||||
case NoteTypeEnum.DAMAGE:
|
||||
return renderNoteDamage(note);
|
||||
case NoteTypeEnum.DISADVANTAGE_ICON:
|
||||
return renderNoteDisadvantageIcon();
|
||||
case NoteTypeEnum.GROUP:
|
||||
return renderNoteGroup(note.data.notes, note.data.separator);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function renderNoteGroup(notes, separator = ' ') {
|
||||
if (notes === null) {
|
||||
return null;
|
||||
}
|
||||
return notes
|
||||
.map((note, idx) => {
|
||||
if (note === null) {
|
||||
return null;
|
||||
}
|
||||
return `${renderNote(note)}${idx + 1 < notes.length ? separator : ''}`;
|
||||
})
|
||||
.join('');
|
||||
}
|
||||
export function renderNoteComponents(notes) {
|
||||
return renderNoteGroup(notes, ', ');
|
||||
}
|
||||
Reference in New Issue
Block a user