@dreamboard-games/sdk 0.5.0-alpha.5 → 0.5.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -6
- package/dist/{chunk-7RGMPJQG.js → chunk-HZPKKBEG.js} +81 -5
- package/dist/chunk-HZPKKBEG.js.map +1 -0
- package/dist/index.d.ts +121 -4
- package/dist/index.js +189 -8
- package/dist/index.js.map +1 -1
- package/dist/{model-BCl8WsB6.d.ts → model-D2Z9j0Yi.d.ts} +18 -3
- package/dist/react.d.ts +43 -28
- package/dist/react.js +333 -133
- package/dist/react.js.map +1 -1
- package/dist/reducer.js +4 -0
- package/dist/reducer.js.map +1 -1
- package/package.json +1 -4
- package/dist/chunk-7RGMPJQG.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AmbiguousTargetError,
|
|
3
|
+
GESTURE_THRESHOLDS,
|
|
3
4
|
createGameInstance,
|
|
5
|
+
createGestureRecognizer,
|
|
6
|
+
isSameDropTarget,
|
|
4
7
|
runtimeFeatures
|
|
5
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-HZPKKBEG.js";
|
|
6
9
|
import {
|
|
7
10
|
BoardStaticProjectionSchema,
|
|
8
11
|
CancelInteractionCommandSchema,
|
|
@@ -52,12 +55,11 @@ import {
|
|
|
52
55
|
encodeCanonicalPluginRuntimeJson
|
|
53
56
|
} from "./chunk-K75F5UIJ.js";
|
|
54
57
|
import {
|
|
55
|
-
inputValueKey,
|
|
56
58
|
requireLookup
|
|
57
59
|
} from "./chunk-3JXUL4VN.js";
|
|
58
60
|
|
|
59
61
|
// src/package-set.ts
|
|
60
|
-
var DREAMBOARD_SDK_VERSION = true ? "0.5.0-alpha.
|
|
62
|
+
var DREAMBOARD_SDK_VERSION = true ? "0.5.0-alpha.7" : "0.0.0-development";
|
|
61
63
|
var DREAMBOARD_SDK_PACKAGES = {
|
|
62
64
|
"@dreamboard-games/sdk": DREAMBOARD_SDK_VERSION
|
|
63
65
|
};
|
|
@@ -751,6 +753,14 @@ function createRuntimeDragFeature(context) {
|
|
|
751
753
|
const cardInputs = inputs.filter(
|
|
752
754
|
(input) => input.getDomain().type === "cardTarget" && (!options?.input || input.key === options.input) && input.getIsEligible(cardId)
|
|
753
755
|
);
|
|
756
|
+
if (!inputs.some((input) => input.getDomain().type === "boardTarget"))
|
|
757
|
+
return cardInputs.map(
|
|
758
|
+
(cardInput) => Object.freeze({
|
|
759
|
+
kind: "interaction",
|
|
760
|
+
interactionKey: candidate.key,
|
|
761
|
+
cardInputKey: cardInput.key
|
|
762
|
+
})
|
|
763
|
+
);
|
|
754
764
|
return cardInputs.flatMap(
|
|
755
765
|
(cardInput) => inputs.flatMap((input) => {
|
|
756
766
|
const domain = input.getDomain();
|
|
@@ -784,9 +794,6 @@ function createRuntimeDragFeature(context) {
|
|
|
784
794
|
);
|
|
785
795
|
return resolved;
|
|
786
796
|
}
|
|
787
|
-
function sameTarget(left, right) {
|
|
788
|
-
return left.kind === right.kind && left.valueKind === right.valueKind && inputValueKey(left.value) === inputValueKey(right.value) && (left.valueKind !== "board-id" || right.valueKind === "board-id" && left.boardId === right.boardId) && left.interactionKey === right.interactionKey && left.cardInputKey === right.cardInputKey && left.inputKey === right.inputKey;
|
|
789
|
-
}
|
|
790
797
|
function cancel() {
|
|
791
798
|
if (active) update(null);
|
|
792
799
|
}
|
|
@@ -805,7 +812,7 @@ function createRuntimeDragFeature(context) {
|
|
|
805
812
|
getDropTargets: () => dropTargets,
|
|
806
813
|
setDropTarget(target) {
|
|
807
814
|
if (!active || disposed) return;
|
|
808
|
-
if (target && !targets().some((candidate) =>
|
|
815
|
+
if (target && !targets().some((candidate) => isSameDropTarget(candidate, target))) {
|
|
809
816
|
update({ ...active, target: null });
|
|
810
817
|
return;
|
|
811
818
|
}
|
|
@@ -813,7 +820,9 @@ function createRuntimeDragFeature(context) {
|
|
|
813
820
|
},
|
|
814
821
|
drop() {
|
|
815
822
|
const finished = active;
|
|
816
|
-
const eligible = finished?.target && targets().some(
|
|
823
|
+
const eligible = finished?.target && targets().some(
|
|
824
|
+
(target) => isSameDropTarget(target, finished.target)
|
|
825
|
+
);
|
|
817
826
|
cancel();
|
|
818
827
|
if (!disposed && finished?.target && eligible)
|
|
819
828
|
context.routeCardDrop(finished.cardId, finished.target);
|
|
@@ -1036,6 +1045,173 @@ function panZoomFeature(game, context, options = {}) {
|
|
|
1036
1045
|
}
|
|
1037
1046
|
};
|
|
1038
1047
|
}
|
|
1048
|
+
|
|
1049
|
+
// src/headless/features/origins.ts
|
|
1050
|
+
var isHidden = (cardId) => cardId.startsWith("hidden:");
|
|
1051
|
+
var hiddenCount = (zones, zone) => zones[zone]?.cardIds.filter(isHidden).length ?? 0;
|
|
1052
|
+
function singleOrigin(departures, count) {
|
|
1053
|
+
const origin = departures[0];
|
|
1054
|
+
return origin && departures.length >= count && departures.every(
|
|
1055
|
+
(card) => card.zone === origin.zone && card.hidden === origin.hidden
|
|
1056
|
+
) ? Object.freeze(origin) : null;
|
|
1057
|
+
}
|
|
1058
|
+
function findCardOrigins(previous, next, mover) {
|
|
1059
|
+
const shownBefore = /* @__PURE__ */ new Map();
|
|
1060
|
+
for (const [zone, { cardIds }] of Object.entries(previous))
|
|
1061
|
+
for (const cardId of cardIds)
|
|
1062
|
+
if (!isHidden(cardId)) shownBefore.set(cardId, zone);
|
|
1063
|
+
const shownNow = new Set(
|
|
1064
|
+
Object.values(next).flatMap(
|
|
1065
|
+
({ cardIds }) => cardIds.filter((cardId) => !isHidden(cardId))
|
|
1066
|
+
)
|
|
1067
|
+
);
|
|
1068
|
+
let left = Object.entries(previous).flatMap(([zone, { cardIds }]) => [
|
|
1069
|
+
...cardIds.filter((cardId) => !isHidden(cardId) && !shownNow.has(cardId)).map(() => ({ zone, hidden: false })),
|
|
1070
|
+
...Array.from(
|
|
1071
|
+
{
|
|
1072
|
+
length: Math.max(
|
|
1073
|
+
0,
|
|
1074
|
+
hiddenCount(previous, zone) - hiddenCount(next, zone)
|
|
1075
|
+
)
|
|
1076
|
+
},
|
|
1077
|
+
() => ({ zone, hidden: true })
|
|
1078
|
+
)
|
|
1079
|
+
]);
|
|
1080
|
+
const origins = /* @__PURE__ */ new Map();
|
|
1081
|
+
const shownArrivals = [];
|
|
1082
|
+
const hiddenArrivals = [];
|
|
1083
|
+
for (const [zone, { cardIds }] of Object.entries(next)) {
|
|
1084
|
+
for (const cardId of cardIds) {
|
|
1085
|
+
if (isHidden(cardId)) continue;
|
|
1086
|
+
const from = shownBefore.get(cardId);
|
|
1087
|
+
if (from === void 0) shownArrivals.push(cardId);
|
|
1088
|
+
else if (from !== zone)
|
|
1089
|
+
origins.set(cardId, Object.freeze({ zone: from, hidden: false }));
|
|
1090
|
+
}
|
|
1091
|
+
const hidden = cardIds.filter(isHidden);
|
|
1092
|
+
const before = hiddenCount(previous, zone);
|
|
1093
|
+
hiddenArrivals.push(
|
|
1094
|
+
...Array.from(
|
|
1095
|
+
{ length: Math.max(0, hidden.length - before) },
|
|
1096
|
+
(_, index) => before === 0 ? hidden[index] : null
|
|
1097
|
+
)
|
|
1098
|
+
);
|
|
1099
|
+
}
|
|
1100
|
+
if (left.some(
|
|
1101
|
+
(card) => !card.hidden && hiddenCount(previous, card.zone) > 0 && hiddenCount(next, card.zone) > 0
|
|
1102
|
+
))
|
|
1103
|
+
return origins;
|
|
1104
|
+
const hiddenLeft = left.filter((card) => card.hidden);
|
|
1105
|
+
if (shownArrivals.length) {
|
|
1106
|
+
const origin = singleOrigin(hiddenLeft, shownArrivals.length);
|
|
1107
|
+
if (origin) {
|
|
1108
|
+
for (const cardId of shownArrivals) origins.set(cardId, origin);
|
|
1109
|
+
left = [
|
|
1110
|
+
...left.filter((card) => !card.hidden),
|
|
1111
|
+
...hiddenLeft.slice(shownArrivals.length)
|
|
1112
|
+
];
|
|
1113
|
+
} else if (hiddenLeft.length) {
|
|
1114
|
+
return origins;
|
|
1115
|
+
} else if (mover !== null) {
|
|
1116
|
+
const origin2 = Object.freeze({ player: mover, hidden: true });
|
|
1117
|
+
for (const cardId of shownArrivals) origins.set(cardId, origin2);
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
const hiddenOrigin = singleOrigin(left, hiddenArrivals.length) ?? (left.length === 0 && mover !== null ? Object.freeze({ player: mover, hidden: true }) : null);
|
|
1121
|
+
if (hiddenOrigin) {
|
|
1122
|
+
for (const cardId of hiddenArrivals)
|
|
1123
|
+
if (cardId !== null) origins.set(cardId, hiddenOrigin);
|
|
1124
|
+
}
|
|
1125
|
+
return origins;
|
|
1126
|
+
}
|
|
1127
|
+
function moverOf(snapshot) {
|
|
1128
|
+
const active = snapshot.frame.flow.activePlayers;
|
|
1129
|
+
return active.length === 1 && active[0] !== snapshot.me ? active[0] : null;
|
|
1130
|
+
}
|
|
1131
|
+
function originsFeature(game) {
|
|
1132
|
+
let frame = game.snapshot;
|
|
1133
|
+
let source = game.getOptions().source;
|
|
1134
|
+
let origins = /* @__PURE__ */ new Map();
|
|
1135
|
+
function sync() {
|
|
1136
|
+
const next = game.snapshot;
|
|
1137
|
+
const nextSource = game.getOptions().source;
|
|
1138
|
+
if (next?.version === frame?.version && next?.me === frame?.me && nextSource === source)
|
|
1139
|
+
return;
|
|
1140
|
+
origins = frame && next && next.me === frame.me && nextSource === source ? findCardOrigins(
|
|
1141
|
+
frame.frame.zones,
|
|
1142
|
+
next.frame.zones,
|
|
1143
|
+
next.version === frame.version + 1 ? moverOf(frame) : null
|
|
1144
|
+
) : /* @__PURE__ */ new Map();
|
|
1145
|
+
frame = next;
|
|
1146
|
+
source = nextSource;
|
|
1147
|
+
}
|
|
1148
|
+
const unsubscribe = game.subscribe(sync);
|
|
1149
|
+
return {
|
|
1150
|
+
card: {
|
|
1151
|
+
getOrigin() {
|
|
1152
|
+
sync();
|
|
1153
|
+
return origins.get(this.id) ?? null;
|
|
1154
|
+
}
|
|
1155
|
+
},
|
|
1156
|
+
dispose: unsubscribe
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
// src/headless/fan.ts
|
|
1161
|
+
var RADIANS = Math.PI / 180;
|
|
1162
|
+
function fanLayout({
|
|
1163
|
+
count,
|
|
1164
|
+
width,
|
|
1165
|
+
cardWidth,
|
|
1166
|
+
cardHeight,
|
|
1167
|
+
step = cardWidth * 0.6,
|
|
1168
|
+
minStep = cardWidth * 0.25,
|
|
1169
|
+
angle = 5,
|
|
1170
|
+
maxSpread = 30
|
|
1171
|
+
}) {
|
|
1172
|
+
if (count < 1) return { cards: [], width: 0, height: 0 };
|
|
1173
|
+
const gaps = count - 1;
|
|
1174
|
+
const delta = gaps ? Math.min(angle, maxSpread / gaps) * RADIANS : 0;
|
|
1175
|
+
const edge = gaps * delta / 2;
|
|
1176
|
+
const span = delta ? 2 * Math.sin(edge) / delta : gaps;
|
|
1177
|
+
const ends = cardWidth * Math.cos(edge) + cardHeight * Math.sin(edge);
|
|
1178
|
+
const spacing = span ? Math.max(minStep, Math.min(step, (width - ends) / span)) : 0;
|
|
1179
|
+
const radius = delta ? spacing / delta : 0;
|
|
1180
|
+
const centres = Array.from({ length: count }, (_, index) => {
|
|
1181
|
+
if (!delta) return { theta: 0, x: (index - gaps / 2) * spacing, y: 0 };
|
|
1182
|
+
const theta = (index - gaps / 2) * delta;
|
|
1183
|
+
return {
|
|
1184
|
+
theta,
|
|
1185
|
+
x: radius * Math.sin(theta),
|
|
1186
|
+
y: radius * (1 - Math.cos(theta))
|
|
1187
|
+
};
|
|
1188
|
+
});
|
|
1189
|
+
const halfHeight = (theta) => cardHeight / 2 * Math.cos(theta) + cardWidth / 2 * Math.abs(Math.sin(theta));
|
|
1190
|
+
const top = Math.min(
|
|
1191
|
+
...centres.map((card) => card.y - halfHeight(card.theta))
|
|
1192
|
+
);
|
|
1193
|
+
const bottom = Math.max(
|
|
1194
|
+
...centres.map((card) => card.y + halfHeight(card.theta))
|
|
1195
|
+
);
|
|
1196
|
+
const fanWidth = spacing * span + ends;
|
|
1197
|
+
return {
|
|
1198
|
+
cards: centres.map((card) => ({
|
|
1199
|
+
x: card.x + (fanWidth - cardWidth) / 2,
|
|
1200
|
+
y: card.y - top - cardHeight / 2,
|
|
1201
|
+
rotate: card.theta / RADIANS
|
|
1202
|
+
})),
|
|
1203
|
+
width: fanWidth,
|
|
1204
|
+
height: bottom - top
|
|
1205
|
+
};
|
|
1206
|
+
}
|
|
1207
|
+
function liftFanCard(card, distance) {
|
|
1208
|
+
const theta = card.rotate * RADIANS;
|
|
1209
|
+
return {
|
|
1210
|
+
x: card.x + distance * Math.sin(theta),
|
|
1211
|
+
y: card.y - distance * Math.cos(theta),
|
|
1212
|
+
rotate: card.rotate
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1039
1215
|
export {
|
|
1040
1216
|
AmbiguousTargetError,
|
|
1041
1217
|
AuthAcceptedFrameSchema,
|
|
@@ -1049,6 +1225,7 @@ export {
|
|
|
1049
1225
|
DREAMBOARD_SDK_PACKAGES,
|
|
1050
1226
|
DREAMBOARD_SDK_PACKAGE_SET,
|
|
1051
1227
|
DREAMBOARD_SDK_VERSION,
|
|
1228
|
+
GESTURE_THRESHOLDS,
|
|
1052
1229
|
GameEventDetailSchema,
|
|
1053
1230
|
GameEventSchema,
|
|
1054
1231
|
GameOutcomeSchema,
|
|
@@ -1085,16 +1262,20 @@ export {
|
|
|
1085
1262
|
canonicalizePluginRuntimeJson,
|
|
1086
1263
|
computePluginActionSetVersion,
|
|
1087
1264
|
createGameInstance,
|
|
1265
|
+
createGestureRecognizer,
|
|
1088
1266
|
createPluginProtocolEnvelopeSchema,
|
|
1089
1267
|
digestPluginCommandRequest,
|
|
1090
1268
|
digestPluginGameplayFrame,
|
|
1091
1269
|
digestPluginRuntimeJson,
|
|
1092
1270
|
dragFeature,
|
|
1093
1271
|
encodeCanonicalPluginRuntimeJson,
|
|
1272
|
+
fanLayout,
|
|
1094
1273
|
handFeature,
|
|
1095
1274
|
hostSource,
|
|
1096
1275
|
iframeSource,
|
|
1276
|
+
liftFanCard,
|
|
1097
1277
|
materializePluginGameplayFrame,
|
|
1278
|
+
originsFeature,
|
|
1098
1279
|
panZoomFeature,
|
|
1099
1280
|
parseHostToPluginEnvelope,
|
|
1100
1281
|
parsePluginGameplayFrame,
|