@whaletech/pet 0.2.3 → 0.2.4
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/dist/main.js +40 -58
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -164,6 +164,11 @@ function migrateState(raw) {
|
|
|
164
164
|
if (needs["bond"] === undefined) {
|
|
165
165
|
needs["bond"] = 60;
|
|
166
166
|
}
|
|
167
|
+
const validNeedsKeys = ["belly", "energy", "affinity", "bond"];
|
|
168
|
+
for (const key of Object.keys(needs)) {
|
|
169
|
+
if (!validNeedsKeys.includes(key))
|
|
170
|
+
delete needs[key];
|
|
171
|
+
}
|
|
167
172
|
return state;
|
|
168
173
|
}
|
|
169
174
|
async function loadState() {
|
|
@@ -396,6 +401,18 @@ function hatchCompanion(userId, soul, hatchedAt = Date.now()) {
|
|
|
396
401
|
const { bones } = roll(userId);
|
|
397
402
|
return { ...soul, hatchedAt, ...bones };
|
|
398
403
|
}
|
|
404
|
+
function toStoredCompanion(companion) {
|
|
405
|
+
return {
|
|
406
|
+
name: companion.name,
|
|
407
|
+
personality: companion.personality,
|
|
408
|
+
hatchedAt: companion.hatchedAt,
|
|
409
|
+
speciesOverride: companion.species,
|
|
410
|
+
eyeOverride: companion.eye,
|
|
411
|
+
hatOverride: companion.hat,
|
|
412
|
+
rarityOverride: companion.rarity,
|
|
413
|
+
shinyOverride: companion.shiny
|
|
414
|
+
};
|
|
415
|
+
}
|
|
399
416
|
function getCompanionFromStored(userId, stored) {
|
|
400
417
|
if (!stored)
|
|
401
418
|
return;
|
|
@@ -1127,8 +1144,6 @@ function renderFace(bones) {
|
|
|
1127
1144
|
var TICK_MS = 500;
|
|
1128
1145
|
var BUBBLE_SHOW_TICKS = 20;
|
|
1129
1146
|
var FADE_WINDOW_TICKS = 6;
|
|
1130
|
-
var MIN_COLS_FOR_FULL_SPRITE = 100;
|
|
1131
|
-
var NARROW_QUIP_CAP = 24;
|
|
1132
1147
|
var IDLE_SEQUENCE = [0, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 2, 0, 0, 0];
|
|
1133
1148
|
function isCJK(ch) {
|
|
1134
1149
|
const code = ch.codePointAt(0) ?? 0;
|
|
@@ -1166,11 +1181,6 @@ function wrapSpeech(text, width) {
|
|
|
1166
1181
|
}
|
|
1167
1182
|
return result;
|
|
1168
1183
|
}
|
|
1169
|
-
function truncateReaction(reaction, cap = NARROW_QUIP_CAP) {
|
|
1170
|
-
if (!reaction || reaction.length <= cap)
|
|
1171
|
-
return reaction;
|
|
1172
|
-
return `${reaction.slice(0, cap - 1)}…`;
|
|
1173
|
-
}
|
|
1174
1184
|
var FEED_OVERLAYS = [" *nom* ", " ~munch~ ", " *nom* ", " *chomp* "];
|
|
1175
1185
|
var PET_OVERLAYS = [" ♥ ♥ ", " ♥ ♥ ♥ ", " ♥ ♥ ♥ ", " ♥ ♥ ♥ "];
|
|
1176
1186
|
var SLEEP_OVERLAYS = [" z z z ", " z z ", " z z z ", " z z "];
|
|
@@ -1179,7 +1189,6 @@ var SHINY_BELOW = [" ⋆ ✧ ", " ✦ ⋆ ", " ✧ ✦ "
|
|
|
1179
1189
|
function getSpriteViewModel(input) {
|
|
1180
1190
|
const {
|
|
1181
1191
|
companion,
|
|
1182
|
-
columns,
|
|
1183
1192
|
tick,
|
|
1184
1193
|
focused = false,
|
|
1185
1194
|
reaction,
|
|
@@ -1189,19 +1198,6 @@ function getSpriteViewModel(input) {
|
|
|
1189
1198
|
bubbleShowDuration = BUBBLE_SHOW_TICKS
|
|
1190
1199
|
} = input;
|
|
1191
1200
|
const fading = reaction !== undefined && bubbleAgeTicks >= bubbleShowDuration - FADE_WINDOW_TICKS;
|
|
1192
|
-
if (columns < MIN_COLS_FOR_FULL_SPRITE) {
|
|
1193
|
-
const quip = truncateReaction(reaction);
|
|
1194
|
-
const label = quip ? `"${quip}"` : focused ? ` ${companion.name} ` : companion.name;
|
|
1195
|
-
return {
|
|
1196
|
-
face: renderFace(companion),
|
|
1197
|
-
lines: [],
|
|
1198
|
-
overlayAbove: [],
|
|
1199
|
-
overlayBelow: [],
|
|
1200
|
-
label,
|
|
1201
|
-
fading,
|
|
1202
|
-
narrow: true
|
|
1203
|
-
};
|
|
1204
|
-
}
|
|
1205
1201
|
const frameCount = spriteFrameCount(companion.species);
|
|
1206
1202
|
let spriteFrame = 0;
|
|
1207
1203
|
let blink = false;
|
|
@@ -1241,8 +1237,7 @@ function getSpriteViewModel(input) {
|
|
|
1241
1237
|
overlayAbove,
|
|
1242
1238
|
overlayBelow,
|
|
1243
1239
|
label: focused ? ` ${companion.name} ` : companion.name,
|
|
1244
|
-
fading
|
|
1245
|
-
narrow: false
|
|
1240
|
+
fading
|
|
1246
1241
|
};
|
|
1247
1242
|
}
|
|
1248
1243
|
|
|
@@ -4055,7 +4050,7 @@ function pickIdleQuip(mood, locale) {
|
|
|
4055
4050
|
}
|
|
4056
4051
|
|
|
4057
4052
|
// src/app.tsx
|
|
4058
|
-
import { jsxDEV as jsxDEV8
|
|
4053
|
+
import { jsxDEV as jsxDEV8 } from "react/jsx-dev-runtime";
|
|
4059
4054
|
var MOOD_EMOJI = {
|
|
4060
4055
|
sleepy: "\uD83D\uDCA4",
|
|
4061
4056
|
calm: "\uD83D\uDE0C",
|
|
@@ -4311,7 +4306,6 @@ function App({ companion, initialState, userId, initialQuota, connected: initial
|
|
|
4311
4306
|
const stars = RARITY_STARS[companion.rarity];
|
|
4312
4307
|
const vm = getSpriteViewModel({
|
|
4313
4308
|
companion,
|
|
4314
|
-
columns,
|
|
4315
4309
|
tick,
|
|
4316
4310
|
reaction: reaction ?? undefined,
|
|
4317
4311
|
bubbleAgeTicks: bubbleAge,
|
|
@@ -4320,7 +4314,7 @@ function App({ companion, initialState, userId, initialQuota, connected: initial
|
|
|
4320
4314
|
});
|
|
4321
4315
|
const bubbleLines = [];
|
|
4322
4316
|
if (reaction) {
|
|
4323
|
-
const maxWidth = Math.min(40, columns - 20);
|
|
4317
|
+
const maxWidth = Math.max(10, Math.min(40, columns - 20));
|
|
4324
4318
|
const wrapped = wrapSpeech(reaction, maxWidth);
|
|
4325
4319
|
if (wrapped.length === 1) {
|
|
4326
4320
|
bubbleLines.push(`「${wrapped[0]}」`);
|
|
@@ -4470,28 +4464,20 @@ function App({ companion, initialState, userId, initialQuota, connected: initial
|
|
|
4470
4464
|
/* @__PURE__ */ jsxDEV8(Box8, {
|
|
4471
4465
|
flexDirection: "column",
|
|
4472
4466
|
marginLeft: 2,
|
|
4473
|
-
children:
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
}, i, false, undefined, this)),
|
|
4488
|
-
vm.overlayBelow.map((line, i) => /* @__PURE__ */ jsxDEV8(Text8, {
|
|
4489
|
-
color: "yellow",
|
|
4490
|
-
children: line
|
|
4491
|
-
}, `b${i}`, false, undefined, this))
|
|
4492
|
-
]
|
|
4493
|
-
}, undefined, true, undefined, this)
|
|
4494
|
-
}, undefined, false, undefined, this),
|
|
4467
|
+
children: [
|
|
4468
|
+
vm.overlayAbove.map((line, i) => /* @__PURE__ */ jsxDEV8(Text8, {
|
|
4469
|
+
color: "magenta",
|
|
4470
|
+
children: line
|
|
4471
|
+
}, `a${i}`, false, undefined, this)),
|
|
4472
|
+
vm.lines.map((line, i) => /* @__PURE__ */ jsxDEV8(Text8, {
|
|
4473
|
+
children: line
|
|
4474
|
+
}, i, false, undefined, this)),
|
|
4475
|
+
vm.overlayBelow.map((line, i) => /* @__PURE__ */ jsxDEV8(Text8, {
|
|
4476
|
+
color: "yellow",
|
|
4477
|
+
children: line
|
|
4478
|
+
}, `b${i}`, false, undefined, this))
|
|
4479
|
+
]
|
|
4480
|
+
}, undefined, true, undefined, this),
|
|
4495
4481
|
bubbleLines.length > 0 && /* @__PURE__ */ jsxDEV8(Box8, {
|
|
4496
4482
|
flexDirection: "column",
|
|
4497
4483
|
marginLeft: 2,
|
|
@@ -4607,7 +4593,7 @@ function App({ companion, initialState, userId, initialQuota, connected: initial
|
|
|
4607
4593
|
import { useState as useState9, useEffect as useEffect8 } from "react";
|
|
4608
4594
|
import { Box as Box9, Text as Text9 } from "ink";
|
|
4609
4595
|
import TextInput2 from "ink-text-input";
|
|
4610
|
-
import { jsxDEV as jsxDEV9, Fragment as
|
|
4596
|
+
import { jsxDEV as jsxDEV9, Fragment as Fragment7 } from "react/jsx-dev-runtime";
|
|
4611
4597
|
var EGG_FRAMES = [
|
|
4612
4598
|
[" ", " .--. ", " / \\ ", "| |", " \\ / ", " '--' "],
|
|
4613
4599
|
[" ", " .--. ", " / .. \\ ", "| |", " \\ / ", " '--' "],
|
|
@@ -4688,7 +4674,7 @@ function Hatch({ userId, onComplete }) {
|
|
|
4688
4674
|
alignItems: "center",
|
|
4689
4675
|
marginTop: 2,
|
|
4690
4676
|
children: [
|
|
4691
|
-
phase === "egg" && /* @__PURE__ */ jsxDEV9(
|
|
4677
|
+
phase === "egg" && /* @__PURE__ */ jsxDEV9(Fragment7, {
|
|
4692
4678
|
children: [
|
|
4693
4679
|
/* @__PURE__ */ jsxDEV9(Text9, {
|
|
4694
4680
|
bold: true,
|
|
@@ -4704,7 +4690,7 @@ function Hatch({ userId, onComplete }) {
|
|
|
4704
4690
|
}, undefined, false, undefined, this)
|
|
4705
4691
|
]
|
|
4706
4692
|
}, undefined, true, undefined, this),
|
|
4707
|
-
phase === "rolling" && /* @__PURE__ */ jsxDEV9(
|
|
4693
|
+
phase === "rolling" && /* @__PURE__ */ jsxDEV9(Fragment7, {
|
|
4708
4694
|
children: [
|
|
4709
4695
|
/* @__PURE__ */ jsxDEV9(Text9, {
|
|
4710
4696
|
bold: true,
|
|
@@ -4731,7 +4717,7 @@ function Hatch({ userId, onComplete }) {
|
|
|
4731
4717
|
}, undefined, true, undefined, this)
|
|
4732
4718
|
]
|
|
4733
4719
|
}, undefined, true, undefined, this),
|
|
4734
|
-
phase === "naming" && /* @__PURE__ */ jsxDEV9(
|
|
4720
|
+
phase === "naming" && /* @__PURE__ */ jsxDEV9(Fragment7, {
|
|
4735
4721
|
children: [
|
|
4736
4722
|
/* @__PURE__ */ jsxDEV9(Box9, {
|
|
4737
4723
|
marginTop: 1,
|
|
@@ -4765,7 +4751,7 @@ function Hatch({ userId, onComplete }) {
|
|
|
4765
4751
|
}, undefined, true, undefined, this)
|
|
4766
4752
|
]
|
|
4767
4753
|
}, undefined, true, undefined, this),
|
|
4768
|
-
phase === "reveal" && soul && /* @__PURE__ */ jsxDEV9(
|
|
4754
|
+
phase === "reveal" && soul && /* @__PURE__ */ jsxDEV9(Fragment7, {
|
|
4769
4755
|
children: [
|
|
4770
4756
|
/* @__PURE__ */ jsxDEV9(Box9, {
|
|
4771
4757
|
marginTop: 1,
|
|
@@ -4825,11 +4811,7 @@ function Root({ userId, initialCompanion, initialState, initialQuota, connected,
|
|
|
4825
4811
|
setCompanion(newCompanion);
|
|
4826
4812
|
const stateWithCompanion = {
|
|
4827
4813
|
...state,
|
|
4828
|
-
companion:
|
|
4829
|
-
name: newCompanion.name,
|
|
4830
|
-
personality: newCompanion.personality,
|
|
4831
|
-
hatchedAt: newCompanion.hatchedAt
|
|
4832
|
-
}
|
|
4814
|
+
companion: toStoredCompanion(newCompanion)
|
|
4833
4815
|
};
|
|
4834
4816
|
setState(stateWithCompanion);
|
|
4835
4817
|
await persistState(userId, stateWithCompanion, initialQuota);
|