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:
+95
@@ -0,0 +1,95 @@
|
||||
import * as React from "react";
|
||||
|
||||
import {
|
||||
ConditionContract,
|
||||
ConditionLevelUtils,
|
||||
ConditionUtils,
|
||||
Constants,
|
||||
VehicleActiveConditionLookup,
|
||||
} from "@dndbeyond/character-rules-engine/es";
|
||||
|
||||
import VehicleConditionsTrackerSpecial from "./VehicleConditionsTrackerSpecial";
|
||||
|
||||
interface Props {
|
||||
activeConditionLookup: VehicleActiveConditionLookup;
|
||||
enabledConditions: Array<ConditionContract>;
|
||||
isInteractive: boolean;
|
||||
initiallyCollapsed: boolean;
|
||||
onLevelChange?: (
|
||||
conditionId: number,
|
||||
newLevel: number | null,
|
||||
activeLevel: number | null
|
||||
) => void;
|
||||
}
|
||||
export default class VehicleConditionTrackers extends React.PureComponent<Props> {
|
||||
static defaultProps = {
|
||||
isInteractive: false,
|
||||
initiallyCollapsed: true,
|
||||
};
|
||||
|
||||
render() {
|
||||
const {
|
||||
activeConditionLookup,
|
||||
enabledConditions,
|
||||
onLevelChange,
|
||||
isInteractive,
|
||||
} = this.props;
|
||||
|
||||
const specialConditions: Array<ConditionContract> = [];
|
||||
const standardConditions: Array<ConditionContract> = [];
|
||||
|
||||
enabledConditions.forEach((condition) => {
|
||||
switch (ConditionUtils.getType(condition)) {
|
||||
case Constants.ConditionTypeEnum.SPECIAL:
|
||||
specialConditions.push(condition);
|
||||
break;
|
||||
case Constants.ConditionTypeEnum.STANDARD:
|
||||
standardConditions.push(condition);
|
||||
break;
|
||||
default:
|
||||
//not implemented
|
||||
}
|
||||
});
|
||||
|
||||
//TODO handle standard conditions in future
|
||||
return (
|
||||
<React.Fragment>
|
||||
{specialConditions.map((condition, idx) => {
|
||||
const levels = ConditionUtils.getDefinitionLevels(condition).map(
|
||||
(level) => ConditionLevelUtils.getLevel(level)
|
||||
);
|
||||
const id = ConditionUtils.getId(condition);
|
||||
// get this override from data eventually
|
||||
let levelOverrides: Record<number, string> = {};
|
||||
if (id === Constants.ConditionIdEnum.EXHAUSTION) {
|
||||
levelOverrides = {
|
||||
6: 'The vehicle "breaks down" and hit points drop to 0',
|
||||
};
|
||||
}
|
||||
|
||||
let activeLevel: number | null = null;
|
||||
|
||||
if (activeConditionLookup.hasOwnProperty(id)) {
|
||||
activeLevel = ConditionUtils.getActiveLevel(
|
||||
activeConditionLookup[id]
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<VehicleConditionsTrackerSpecial
|
||||
key={`${idx}-${id}`}
|
||||
conditionId={id}
|
||||
name={ConditionUtils.getName(condition)}
|
||||
activeLevel={activeLevel}
|
||||
isInteractive={isInteractive}
|
||||
levels={levels}
|
||||
levelEffectLookup={ConditionUtils.getLevelEffectLookup(condition)}
|
||||
levelOverrides={levelOverrides}
|
||||
onLevelChange={onLevelChange}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
import * as React from "react";
|
||||
|
||||
import {
|
||||
Collapsible,
|
||||
CollapsibleHeaderCallout,
|
||||
CollapsibleHeaderContent,
|
||||
} from "@dndbeyond/character-components/es";
|
||||
import { ConditionLevelEffectLookup } from "@dndbeyond/character-rules-engine/es";
|
||||
|
||||
import ConditionLevelsTable from "../../ConditionLevelsTable";
|
||||
|
||||
interface Props {
|
||||
name: string;
|
||||
conditionId: number;
|
||||
activeLevel: number | null;
|
||||
isInteractive: boolean;
|
||||
initiallyCollapsed: boolean;
|
||||
levels: Array<number>;
|
||||
levelOverrides: Record<number, string>;
|
||||
levelEffectLookup: ConditionLevelEffectLookup | null;
|
||||
onLevelChange?: (
|
||||
conditionId: number,
|
||||
newLevel: number | null,
|
||||
activeLevel: number | null
|
||||
) => void;
|
||||
}
|
||||
export default class VehicleConditionsTrackerSpecial extends React.PureComponent<Props> {
|
||||
static defaultProps = {
|
||||
isInteractive: false,
|
||||
initiallyCollapsed: true,
|
||||
activeLevel: null,
|
||||
};
|
||||
|
||||
handleConditionLevelChange = (newLevel: number | null): void => {
|
||||
const { onLevelChange, conditionId, isInteractive, activeLevel } =
|
||||
this.props;
|
||||
|
||||
if (onLevelChange && isInteractive) {
|
||||
onLevelChange(conditionId, newLevel, activeLevel);
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const {
|
||||
name,
|
||||
activeLevel,
|
||||
levels,
|
||||
levelEffectLookup,
|
||||
levelOverrides,
|
||||
initiallyCollapsed,
|
||||
isInteractive,
|
||||
} = this.props;
|
||||
|
||||
let extraNode: React.ReactNode = (
|
||||
<div className="ct-vehicle-condition-tracker__summary">
|
||||
<span className="ct-vehicle-condition-tracker__summary-value">
|
||||
Level {activeLevel ? activeLevel : "--"}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
let headerCalloutNode: React.ReactNode = (
|
||||
<CollapsibleHeaderCallout extra={extraNode} value={null} />
|
||||
);
|
||||
let headerNode: React.ReactNode = (
|
||||
<CollapsibleHeaderContent heading={name} callout={headerCalloutNode} />
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="ct-vehicle-condition-tracker">
|
||||
<Collapsible
|
||||
header={headerNode}
|
||||
initiallyCollapsed={initiallyCollapsed}
|
||||
>
|
||||
<div className="ct-vehicle-condition-tracker__content">
|
||||
<ConditionLevelsTable
|
||||
conditionName={name}
|
||||
levelEffectLookup={levelEffectLookup}
|
||||
isInteractive={isInteractive}
|
||||
activeLevel={activeLevel}
|
||||
levels={levels}
|
||||
onLevelChange={this.handleConditionLevelChange}
|
||||
levelOverrides={levelOverrides}
|
||||
/>
|
||||
</div>
|
||||
</Collapsible>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import VehicleConditionsTrackerSpecial from "./VehicleConditionsTrackerSpecial";
|
||||
|
||||
export default VehicleConditionsTrackerSpecial;
|
||||
export { VehicleConditionsTrackerSpecial };
|
||||
@@ -0,0 +1,5 @@
|
||||
import VehicleConditionsTracker from "./VehicleConditionsTracker";
|
||||
import VehicleConditionsTrackerSpecial from "./VehicleConditionsTrackerSpecial";
|
||||
|
||||
export default VehicleConditionsTracker;
|
||||
export { VehicleConditionsTracker, VehicleConditionsTrackerSpecial };
|
||||
Reference in New Issue
Block a user