Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hero Lab Shadowrun Character JSON class for Typescript
export interface Welcome {
actor: Actor;
}
export interface Actor {
actorAttr: ActorAttr;
containers: { [key: string]: Container };
picks: { [key: string]: Pick };
amendments: Amendment[];
actorSettings: { [key: string]: ActorSetting };
}
export interface ActorAttr {
actorID: number;
updateCount: number;
isDifferential: boolean;
name: string;
mode: string;
inheritsSettings: boolean;
actorPickID: number;
gameFolder: string;
gameVersion: string;
engineBuild: number;
combatState: number;
participant: boolean;
validations: Validation[];
}
export interface Validation {
report: string;
severity: string;
parentName: string;
pickName: string;
pickID: number;
}
export interface ActorSetting {
isSelected: boolean;
isUserSelectable: boolean;
}
export interface Amendment {
thing: string;
description: string;
name?: string;
library?: string;
}
export interface Container {
contAttr: ContAttr;
tags?: Tag[];
}
export interface ContAttr {
tablesNeeded: any[];
parPickID?: number;
}
export interface Tag {
group: string;
tag: string;
count: number;
}
export interface Pick {
pickAttr: PickAttr;
tags: Tag[];
fields: Field[];
}
export interface Field {
fID: FID;
val?: number | string;
minVal?: number;
final?: string;
maxVal?: number;
pick?: number;
thing?: string;
}
export enum FID {
ACBookID = "acBookId",
ACBookName = "acBookName",
ACCashCFG = "acCashCfg",
ACMonthUSR = "acMonthUsr",
ACRealm = "acRealm",
ACResExtra = "acResExtra",
ACType = "acType",
AbBuyOff = "abBuyOff",
AbUser = "abUser",
AbilAct2 = "abilAct2",
AbilActive = "abilActive",
ActUser = "actUser",
AdDisable = "adDisable",
AdjEnabled = "adjEnabled",
AdjIndex = "adjIndex",
AdjLasts = "adjLasts",
AdjSource = "adjSource",
AdjUser = "adjUser",
CMDamage = "cmDamage",
ConBlack = "conBlack",
ConChipMe = "conChipMe",
ConChipYou = "conChipYou",
ConConnect = "conConnect",
ConFamily = "conFamily",
ConLoyalty = "conLoyalty",
ConNotes = "conNotes",
ConType = "conType",
DOMDomain = "domDomain",
DcOrder = "dcOrder",
DvWireOn = "dvWireOn",
GearHeld = "gearHeld",
GearNet = "gearNet",
GearWeight = "gearWeight",
GrBindFoc = "grBindFoc",
GrHasWirel = "grHasWirel",
GrIsEquip = "grIsEquip",
GrOrder = "grOrder",
GrUser = "grUser",
IDNotes = "idNotes",
JrnAware = "jrnAware",
JrnCash = "jrnCash",
JrnCred = "jrnCred",
JrnDescr = "jrnDescr",
JrnEarnIn = "jrnEarnIn",
JrnGame = "jrnGame",
JrnNotor = "jrnNotor",
JrnReal = "jrnReal",
JrnReward = "jrnReward",
JrnTitle = "jrnTitle",
JrnXP = "jrnXP",
LIFGuest = "lifGuest",
LIFPerm = "lifPerm",
LIFShared = "lifShared",
Livename = "livename",
MinEnabled = "minEnabled",
MonUsedUp = "monUsedUp",
NotNotes = "notNotes",
PerAge = "perAge",
PerEthnic = "perEthnic",
PerEyes = "perEyes",
PerGenUser = "perGenUser",
PerGender = "perGender",
PerHair = "perHair",
PerHeight = "perHeight",
PerInfo = "perInfo",
PerSkin = "perSkin",
PerWeight = "perWeight",
PriOrder = "priOrder",
SPIBind = "spiBind",
SPIForce = "spiForce",
SPIService = "spiService",
SPNeedFET = "spNeedFet",
Shortname = "shortname",
SklKnowCat = "sklKnowCat",
SklNative = "sklNative",
SpcPromote = "spcPromote",
StackQty = "stackQty",
TactInit = "tactInit",
TactInit2 = "tactInit2",
TrkUser = "trkUser",
TrtBegin = "trtBegin",
TrtUser = "trtUser",
USRChosen1 = "usrChosen1",
USRChosen2 = "usrChosen2",
USRChosen3 = "usrChosen3",
USRIsCheck = "usrIsCheck",
USRSelect = "usrSelect",
UimgImage = "uimgImage",
UimgIndex = "uimgIndex",
UserCost = "UserCost",
UserName = "UserName",
Useredit = "useredit",
Username = "username",
WpEquip = "wpEquip",
WpUseAmmo = "wpUseAmmo",
}
export interface PickAttr {
parContID: number;
thingID: string;
name: string;
isValid: boolean;
appearsInTables: any[];
canUserName?: boolean;
gizmoContID?: number;
isHoldable?: boolean;
stackingID?: number;
isCustomizable?: boolean;
altContID?: number;
gearHolder?: number;
minion?: number;
}
// Converts JSON strings to/from your types
// and asserts the results of JSON.parse at runtime
export class Convert {
public static toWelcome(json: string): Welcome {
return cast(JSON.parse(json), r("Welcome"));
}
public static welcomeToJson(value: Welcome): string {
return JSON.stringify(uncast(value, r("Welcome")), null, 2);
}
}
function invalidValue(typ: any, val: any): never {
throw Error(`Invalid value ${JSON.stringify(val)} for type ${JSON.stringify(typ)}`);
}
function jsonToJSProps(typ: any): any {
if (typ.jsonToJS === undefined) {
var map: any = {};
typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ });
typ.jsonToJS = map;
}
return typ.jsonToJS;
}
function jsToJSONProps(typ: any): any {
if (typ.jsToJSON === undefined) {
var map: any = {};
typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ });
typ.jsToJSON = map;
}
return typ.jsToJSON;
}
function transform(val: any, typ: any, getProps: any): any {
function transformPrimitive(typ: string, val: any): any {
if (typeof typ === typeof val) return val;
return invalidValue(typ, val);
}
function transformUnion(typs: any[], val: any): any {
// val must validate against one typ in typs
var l = typs.length;
for (var i = 0; i < l; i++) {
var typ = typs[i];
try {
return transform(val, typ, getProps);
} catch (_) { }
}
return invalidValue(typs, val);
}
function transformEnum(cases: string[], val: any): any {
if (cases.indexOf(val) !== -1) return val;
return invalidValue(cases, val);
}
function transformArray(typ: any, val: any): any {
// val must be an array with no invalid elements
if (!Array.isArray(val)) return invalidValue("array", val);
return val.map(el => transform(el, typ, getProps));
}
function transformDate(typ: any, val: any): any {
if (val === null) {
return null;
}
const d = new Date(val);
if (isNaN(d.valueOf())) {
return invalidValue("Date", val);
}
return d;
}
function transformObject(props: { [k: string]: any }, additional: any, val: any): any {
if (val === null || typeof val !== "object" || Array.isArray(val)) {
return invalidValue("object", val);
}
var result: any = {};
Object.getOwnPropertyNames(props).forEach(key => {
const prop = props[key];
const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
result[prop.key] = transform(v, prop.typ, getProps);
});
Object.getOwnPropertyNames(val).forEach(key => {
if (!Object.prototype.hasOwnProperty.call(props, key)) {
result[key] = transform(val[key], additional, getProps);
}
});
return result;
}
if (typ === "any") return val;
if (typ === null) {
if (val === null) return val;
return invalidValue(typ, val);
}
if (typ === false) return invalidValue(typ, val);
while (typeof typ === "object" && typ.ref !== undefined) {
typ = typeMap[typ.ref];
}
if (Array.isArray(typ)) return transformEnum(typ, val);
if (typeof typ === "object") {
return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
: typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val)
: typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val)
: invalidValue(typ, val);
}
// Numbers can be parsed by Date but shouldn't be.
if (typ === Date && typeof val !== "number") return transformDate(typ, val);
return transformPrimitive(typ, val);
}
function cast<T>(val: any, typ: any): T {
return transform(val, typ, jsonToJSProps);
}
function uncast<T>(val: T, typ: any): any {
return transform(val, typ, jsToJSONProps);
}
function a(typ: any) {
return { arrayItems: typ };
}
function u(...typs: any[]) {
return { unionMembers: typs };
}
function o(props: any[], additional: any) {
return { props, additional };
}
function m(additional: any) {
return { props: [], additional };
}
function r(name: string) {
return { ref: name };
}
const typeMap: any = {
"Welcome": o([
{ json: "actor", js: "actor", typ: r("Actor") },
], false),
"Actor": o([
{ json: "actorAttr", js: "actorAttr", typ: r("ActorAttr") },
{ json: "containers", js: "containers", typ: m(r("Container")) },
{ json: "picks", js: "picks", typ: m(r("Pick")) },
{ json: "amendments", js: "amendments", typ: a(r("Amendment")) },
{ json: "actorSettings", js: "actorSettings", typ: m(r("ActorSetting")) },
], false),
"ActorAttr": o([
{ json: "actorId", js: "actorID", typ: 0 },
{ json: "updateCount", js: "updateCount", typ: 0 },
{ json: "isDifferential", js: "isDifferential", typ: true },
{ json: "name", js: "name", typ: "" },
{ json: "mode", js: "mode", typ: "" },
{ json: "inheritsSettings", js: "inheritsSettings", typ: true },
{ json: "actorPickId", js: "actorPickID", typ: 0 },
{ json: "gameFolder", js: "gameFolder", typ: "" },
{ json: "gameVersion", js: "gameVersion", typ: "" },
{ json: "engineBuild", js: "engineBuild", typ: 0 },
{ json: "combatState", js: "combatState", typ: 0 },
{ json: "participant", js: "participant", typ: true },
{ json: "validations", js: "validations", typ: a(r("Validation")) },
], false),
"Validation": o([
{ json: "report", js: "report", typ: "" },
{ json: "severity", js: "severity", typ: "" },
{ json: "parentName", js: "parentName", typ: "" },
{ json: "pickName", js: "pickName", typ: "" },
{ json: "pickId", js: "pickID", typ: 0 },
], false),
"ActorSetting": o([
{ json: "isSelected", js: "isSelected", typ: true },
{ json: "isUserSelectable", js: "isUserSelectable", typ: true },
], false),
"Amendment": o([
{ json: "thing", js: "thing", typ: "" },
{ json: "description", js: "description", typ: "" },
{ json: "name", js: "name", typ: u(undefined, "") },
{ json: "library", js: "library", typ: u(undefined, "") },
], false),
"Container": o([
{ json: "contAttr", js: "contAttr", typ: r("ContAttr") },
{ json: "tags", js: "tags", typ: u(undefined, a(r("Tag"))) },
], false),
"ContAttr": o([
{ json: "tablesNeeded", js: "tablesNeeded", typ: a("any") },
{ json: "parPickId", js: "parPickID", typ: u(undefined, 0) },
], false),
"Tag": o([
{ json: "group", js: "group", typ: "" },
{ json: "tag", js: "tag", typ: "" },
{ json: "count", js: "count", typ: 0 },
], false),
"Pick": o([
{ json: "pickAttr", js: "pickAttr", typ: r("PickAttr") },
{ json: "tags", js: "tags", typ: a(r("Tag")) },
{ json: "fields", js: "fields", typ: a(r("Field")) },
], false),
"Field": o([
{ json: "fId", js: "fID", typ: r("FID") },
{ json: "val", js: "val", typ: u(undefined, u(0, "")) },
{ json: "minVal", js: "minVal", typ: u(undefined, 0) },
{ json: "final", js: "final", typ: u(undefined, "") },
{ json: "maxVal", js: "maxVal", typ: u(undefined, 0) },
{ json: "pick", js: "pick", typ: u(undefined, 0) },
{ json: "thing", js: "thing", typ: u(undefined, "") },
{ json: "pick", js: "pick", typ: u(undefined, 0) },
], false),
"PickAttr": o([
{ json: "parContId", js: "parContID", typ: 0 },
{ json: "thingId", js: "thingID", typ: "" },
{ json: "name", js: "name", typ: "" },
{ json: "canUserName", js: "canUserName", typ: u(undefined, true) },
{ json: "isValid", js: "isValid", typ: true },
{ json: "appearsInTables", js: "appearsInTables", typ: a("any") },
{ json: "canUserName", js: "canUserName", typ: u(undefined, true) },
{ json: "altContId", js: "altContID", typ: u(undefined, 0) },
{ json: "gizmoContId", js: "gizmoContID", typ: u(undefined, 0) },
{ json: "isHoldable", js: "isHoldable", typ: u(undefined, true) },
{ json: "stackingId", js: "stackingID", typ: u(undefined, 0) },
{ json: "isCustomizable", js: "isCustomizable", typ: u(undefined, true) },
{ json: "altContId", js: "altContID", typ: u(undefined, 0) },
{ json: "gearHolder", js: "gearHolder", typ: u(undefined, 0) },
{ json: "minion", js: "minion", typ: u(undefined, 0) },
], false),
"FID": [
"acBookId",
"acBookName",
"acCashCfg",
"acMonthUsr",
"acRealm",
"acResExtra",
"acType",
"abBuyOff",
"abUser",
"abilAct2",
"abilActive",
"actUser",
"adDisable",
"adjEnabled",
"adjIndex",
"adjLasts",
"adjSource",
"adjUser",
"cmDamage",
"conBlack",
"conChipMe",
"conChipYou",
"conConnect",
"conFamily",
"conLoyalty",
"conNotes",
"conType",
"domDomain",
"dcOrder",
"dvWireOn",
"gearHeld",
"gearNet",
"gearWeight",
"grBindFoc",
"grHasWirel",
"grIsEquip",
"grOrder",
"grUser",
"idNotes",
"jrnAware",
"jrnCash",
"jrnCred",
"jrnDescr",
"jrnEarnIn",
"jrnGame",
"jrnNotor",
"jrnReal",
"jrnReward",
"jrnTitle",
"jrnXP",
"lifGuest",
"lifPerm",
"lifShared",
"livename",
"minEnabled",
"monUsedUp",
"notNotes",
"perAge",
"perEthnic",
"perEyes",
"perGenUser",
"perGender",
"perHair",
"perHeight",
"perInfo",
"perSkin",
"perWeight",
"priOrder",
"spiBind",
"spiForce",
"spiService",
"spNeedFet",
"shortname",
"sklKnowCat",
"sklNative",
"spcPromote",
"stackQty",
"tactInit",
"tactInit2",
"trkUser",
"trtBegin",
"trtUser",
"usrChosen1",
"usrChosen2",
"usrChosen3",
"usrIsCheck",
"usrSelect",
"uimgImage",
"uimgIndex",
"UserCost",
"UserName",
"useredit",
"username",
"wpEquip",
"wpUseAmmo",
],
};
@clevett

This comment has been minimized.

Copy link

@clevett clevett commented Jun 30, 2021

Did this feature get released? I want a Hero Lab Shadowrun JSON exporter soooo bad. :)

@manchuwook

This comment has been minimized.

Copy link
Owner Author

@manchuwook manchuwook commented Jul 23, 2021

I haven't messed with it in a very long time. Been working on our own RPG's web interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment