Skip to content

Commit f4d0eea

Browse files
author
Nic Bradley
committed
Add libUUID
1 parent a7cf2d8 commit f4d0eea

14 files changed

Lines changed: 3753 additions & 0 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.DS_Store
22
.idea
3+
**/node_modules

libUUID/.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodejs 22.12.0
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// APISmartAttributes v0.0.1 by GUD Team | APISmartAttributes provides an interface for managing beacon attributes in a slightly smarter way.
2+
var APISmartAttributes = (function () {
3+
'use strict';
4+
5+
async function getAttribute(characterId, name, type = "current") {
6+
// Try for legacy attribute first
7+
const legacyAttr = findObjs({
8+
_type: "attribute",
9+
_characterid: characterId,
10+
name: name,
11+
})[0];
12+
if (legacyAttr) {
13+
return legacyAttr.get(type);
14+
}
15+
// Then try for the beacon computed
16+
const beaconAttr = await getSheetItem(characterId, name);
17+
if (beaconAttr !== null && beaconAttr !== undefined) {
18+
return beaconAttr;
19+
}
20+
// Then try for the user attribute
21+
const userAttr = await getSheetItem(characterId, `user.${name}`);
22+
if (userAttr !== null && userAttr !== undefined) {
23+
return userAttr;
24+
}
25+
log(`Attribute ${name} not found on character ${characterId}`);
26+
return undefined;
27+
}
28+
async function setAttribute(characterId, name, value, type = "current") {
29+
// Try for legacy attribute first
30+
const legacyAttr = findObjs({
31+
_type: "attribute",
32+
_characterid: characterId,
33+
name: name,
34+
})[0];
35+
if (legacyAttr) {
36+
return legacyAttr.set({ [type]: value });
37+
}
38+
// Then try for the beacon computed
39+
const beaconAttr = await getSheetItem(characterId, name);
40+
if (beaconAttr !== null && beaconAttr !== undefined) {
41+
return setSheetItem(characterId, name, value);
42+
}
43+
// Then default to a user attribute
44+
return setSheetItem(characterId, `user.${name}`, value);
45+
}
46+
var index = {
47+
getAttribute,
48+
setAttribute,
49+
};
50+
51+
return index;
52+
53+
})();

libUUID/0.0.1/index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
type AttributeType = "current" | "max";
2+
declare function getAttribute(characterId: string, name: string, type?: AttributeType): Promise<string | undefined>;
3+
declare function setAttribute(characterId: string, name: string, value: unknown, type?: AttributeType): Promise<boolean | (Roll20Object<AttributeProperties> & {
4+
setWithWorker: (attributes: Partial<AttributeProperties>) => void;
5+
})>;
6+
declare const _default: {
7+
getAttribute: typeof getAttribute;
8+
setAttribute: typeof setAttribute;
9+
};
10+
export default _default;

libUUID/eslint.config.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { defineConfig } from "eslint/config"; // While not strictly necessary, it's good practice.
2+
import stylistic from "@stylistic/eslint-plugin";
3+
import jslint from "@eslint/js";
4+
import tslint from "typescript-eslint";
5+
6+
export default defineConfig(
7+
{
8+
ignores: ["**/[0-9]*.[0-9]*.[0-9]*/", "*.d.ts", "dist/**", "build/**", "node_modules/**"],
9+
},
10+
jslint.configs.recommended,
11+
...tslint.configs.recommended,
12+
{
13+
plugins: {
14+
"@stylistic": stylistic,
15+
},
16+
rules: {
17+
"@stylistic/quotes": ["error", "double"],
18+
"@stylistic/semi": ["error", "always"],
19+
"@stylistic/indent": ["error", 2],
20+
},
21+
},
22+
);

0 commit comments

Comments
 (0)