@whaletech/pet 0.2.2 → 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.
Files changed (2) hide show
  1. package/dist/main.js +43 -59
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  // src/main.tsx
3
3
  import { useState as useState10, useCallback as useCallback2 } from "react";
4
+ import { createRequire } from "node:module";
4
5
  import { render } from "ink";
5
6
 
6
7
  // src/storage.ts
@@ -163,6 +164,11 @@ function migrateState(raw) {
163
164
  if (needs["bond"] === undefined) {
164
165
  needs["bond"] = 60;
165
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
+ }
166
172
  return state;
167
173
  }
168
174
  async function loadState() {
@@ -395,6 +401,18 @@ function hatchCompanion(userId, soul, hatchedAt = Date.now()) {
395
401
  const { bones } = roll(userId);
396
402
  return { ...soul, hatchedAt, ...bones };
397
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
+ }
398
416
  function getCompanionFromStored(userId, stored) {
399
417
  if (!stored)
400
418
  return;
@@ -1126,8 +1144,6 @@ function renderFace(bones) {
1126
1144
  var TICK_MS = 500;
1127
1145
  var BUBBLE_SHOW_TICKS = 20;
1128
1146
  var FADE_WINDOW_TICKS = 6;
1129
- var MIN_COLS_FOR_FULL_SPRITE = 100;
1130
- var NARROW_QUIP_CAP = 24;
1131
1147
  var IDLE_SEQUENCE = [0, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 2, 0, 0, 0];
1132
1148
  function isCJK(ch) {
1133
1149
  const code = ch.codePointAt(0) ?? 0;
@@ -1165,11 +1181,6 @@ function wrapSpeech(text, width) {
1165
1181
  }
1166
1182
  return result;
1167
1183
  }
1168
- function truncateReaction(reaction, cap = NARROW_QUIP_CAP) {
1169
- if (!reaction || reaction.length <= cap)
1170
- return reaction;
1171
- return `${reaction.slice(0, cap - 1)}…`;
1172
- }
1173
1184
  var FEED_OVERLAYS = [" *nom* ", " ~munch~ ", " *nom* ", " *chomp* "];
1174
1185
  var PET_OVERLAYS = [" ♥ ♥ ", " ♥ ♥ ♥ ", " ♥ ♥ ♥ ", " ♥ ♥ ♥ "];
1175
1186
  var SLEEP_OVERLAYS = [" z z z ", " z z ", " z z z ", " z z "];
@@ -1178,7 +1189,6 @@ var SHINY_BELOW = [" ⋆ ✧ ", " ✦ ⋆ ", " ✧ ✦ "
1178
1189
  function getSpriteViewModel(input) {
1179
1190
  const {
1180
1191
  companion,
1181
- columns,
1182
1192
  tick,
1183
1193
  focused = false,
1184
1194
  reaction,
@@ -1188,19 +1198,6 @@ function getSpriteViewModel(input) {
1188
1198
  bubbleShowDuration = BUBBLE_SHOW_TICKS
1189
1199
  } = input;
1190
1200
  const fading = reaction !== undefined && bubbleAgeTicks >= bubbleShowDuration - FADE_WINDOW_TICKS;
1191
- if (columns < MIN_COLS_FOR_FULL_SPRITE) {
1192
- const quip = truncateReaction(reaction);
1193
- const label = quip ? `"${quip}"` : focused ? ` ${companion.name} ` : companion.name;
1194
- return {
1195
- face: renderFace(companion),
1196
- lines: [],
1197
- overlayAbove: [],
1198
- overlayBelow: [],
1199
- label,
1200
- fading,
1201
- narrow: true
1202
- };
1203
- }
1204
1201
  const frameCount = spriteFrameCount(companion.species);
1205
1202
  let spriteFrame = 0;
1206
1203
  let blink = false;
@@ -1240,8 +1237,7 @@ function getSpriteViewModel(input) {
1240
1237
  overlayAbove,
1241
1238
  overlayBelow,
1242
1239
  label: focused ? ` ${companion.name} ` : companion.name,
1243
- fading,
1244
- narrow: false
1240
+ fading
1245
1241
  };
1246
1242
  }
1247
1243
 
@@ -4054,7 +4050,7 @@ function pickIdleQuip(mood, locale) {
4054
4050
  }
4055
4051
 
4056
4052
  // src/app.tsx
4057
- import { jsxDEV as jsxDEV8, Fragment as Fragment7 } from "react/jsx-dev-runtime";
4053
+ import { jsxDEV as jsxDEV8 } from "react/jsx-dev-runtime";
4058
4054
  var MOOD_EMOJI = {
4059
4055
  sleepy: "\uD83D\uDCA4",
4060
4056
  calm: "\uD83D\uDE0C",
@@ -4310,7 +4306,6 @@ function App({ companion, initialState, userId, initialQuota, connected: initial
4310
4306
  const stars = RARITY_STARS[companion.rarity];
4311
4307
  const vm = getSpriteViewModel({
4312
4308
  companion,
4313
- columns,
4314
4309
  tick,
4315
4310
  reaction: reaction ?? undefined,
4316
4311
  bubbleAgeTicks: bubbleAge,
@@ -4319,7 +4314,7 @@ function App({ companion, initialState, userId, initialQuota, connected: initial
4319
4314
  });
4320
4315
  const bubbleLines = [];
4321
4316
  if (reaction) {
4322
- const maxWidth = Math.min(40, columns - 20);
4317
+ const maxWidth = Math.max(10, Math.min(40, columns - 20));
4323
4318
  const wrapped = wrapSpeech(reaction, maxWidth);
4324
4319
  if (wrapped.length === 1) {
4325
4320
  bubbleLines.push(`「${wrapped[0]}」`);
@@ -4469,28 +4464,20 @@ function App({ companion, initialState, userId, initialQuota, connected: initial
4469
4464
  /* @__PURE__ */ jsxDEV8(Box8, {
4470
4465
  flexDirection: "column",
4471
4466
  marginLeft: 2,
4472
- children: vm.narrow ? /* @__PURE__ */ jsxDEV8(Text8, {
4473
- children: [
4474
- vm.face,
4475
- " ",
4476
- vm.label
4477
- ]
4478
- }, undefined, true, undefined, this) : /* @__PURE__ */ jsxDEV8(Fragment7, {
4479
- children: [
4480
- vm.overlayAbove.map((line, i) => /* @__PURE__ */ jsxDEV8(Text8, {
4481
- color: "magenta",
4482
- children: line
4483
- }, `a${i}`, false, undefined, this)),
4484
- vm.lines.map((line, i) => /* @__PURE__ */ jsxDEV8(Text8, {
4485
- children: line
4486
- }, i, false, undefined, this)),
4487
- vm.overlayBelow.map((line, i) => /* @__PURE__ */ jsxDEV8(Text8, {
4488
- color: "yellow",
4489
- children: line
4490
- }, `b${i}`, false, undefined, this))
4491
- ]
4492
- }, undefined, true, undefined, this)
4493
- }, 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),
4494
4481
  bubbleLines.length > 0 && /* @__PURE__ */ jsxDEV8(Box8, {
4495
4482
  flexDirection: "column",
4496
4483
  marginLeft: 2,
@@ -4606,7 +4593,7 @@ function App({ companion, initialState, userId, initialQuota, connected: initial
4606
4593
  import { useState as useState9, useEffect as useEffect8 } from "react";
4607
4594
  import { Box as Box9, Text as Text9 } from "ink";
4608
4595
  import TextInput2 from "ink-text-input";
4609
- import { jsxDEV as jsxDEV9, Fragment as Fragment8 } from "react/jsx-dev-runtime";
4596
+ import { jsxDEV as jsxDEV9, Fragment as Fragment7 } from "react/jsx-dev-runtime";
4610
4597
  var EGG_FRAMES = [
4611
4598
  [" ", " .--. ", " / \\ ", "| |", " \\ / ", " '--' "],
4612
4599
  [" ", " .--. ", " / .. \\ ", "| |", " \\ / ", " '--' "],
@@ -4687,7 +4674,7 @@ function Hatch({ userId, onComplete }) {
4687
4674
  alignItems: "center",
4688
4675
  marginTop: 2,
4689
4676
  children: [
4690
- phase === "egg" && /* @__PURE__ */ jsxDEV9(Fragment8, {
4677
+ phase === "egg" && /* @__PURE__ */ jsxDEV9(Fragment7, {
4691
4678
  children: [
4692
4679
  /* @__PURE__ */ jsxDEV9(Text9, {
4693
4680
  bold: true,
@@ -4703,7 +4690,7 @@ function Hatch({ userId, onComplete }) {
4703
4690
  }, undefined, false, undefined, this)
4704
4691
  ]
4705
4692
  }, undefined, true, undefined, this),
4706
- phase === "rolling" && /* @__PURE__ */ jsxDEV9(Fragment8, {
4693
+ phase === "rolling" && /* @__PURE__ */ jsxDEV9(Fragment7, {
4707
4694
  children: [
4708
4695
  /* @__PURE__ */ jsxDEV9(Text9, {
4709
4696
  bold: true,
@@ -4730,7 +4717,7 @@ function Hatch({ userId, onComplete }) {
4730
4717
  }, undefined, true, undefined, this)
4731
4718
  ]
4732
4719
  }, undefined, true, undefined, this),
4733
- phase === "naming" && /* @__PURE__ */ jsxDEV9(Fragment8, {
4720
+ phase === "naming" && /* @__PURE__ */ jsxDEV9(Fragment7, {
4734
4721
  children: [
4735
4722
  /* @__PURE__ */ jsxDEV9(Box9, {
4736
4723
  marginTop: 1,
@@ -4764,7 +4751,7 @@ function Hatch({ userId, onComplete }) {
4764
4751
  }, undefined, true, undefined, this)
4765
4752
  ]
4766
4753
  }, undefined, true, undefined, this),
4767
- phase === "reveal" && soul && /* @__PURE__ */ jsxDEV9(Fragment8, {
4754
+ phase === "reveal" && soul && /* @__PURE__ */ jsxDEV9(Fragment7, {
4768
4755
  children: [
4769
4756
  /* @__PURE__ */ jsxDEV9(Box9, {
4770
4757
  marginTop: 1,
@@ -4805,7 +4792,8 @@ function Hatch({ userId, onComplete }) {
4805
4792
 
4806
4793
  // src/main.tsx
4807
4794
  import { jsxDEV as jsxDEV10 } from "react/jsx-dev-runtime";
4808
- var VERSION = "0.2.0";
4795
+ var require2 = createRequire(import.meta.url);
4796
+ var { version: VERSION } = require2("../package.json");
4809
4797
  async function checkUpdate() {
4810
4798
  try {
4811
4799
  const res = await fetch("https://registry.npmjs.org/@whaletech%2fpet/latest", {
@@ -4823,11 +4811,7 @@ function Root({ userId, initialCompanion, initialState, initialQuota, connected,
4823
4811
  setCompanion(newCompanion);
4824
4812
  const stateWithCompanion = {
4825
4813
  ...state,
4826
- companion: {
4827
- name: newCompanion.name,
4828
- personality: newCompanion.personality,
4829
- hatchedAt: newCompanion.hatchedAt
4830
- }
4814
+ companion: toStoredCompanion(newCompanion)
4831
4815
  };
4832
4816
  setState(stateWithCompanion);
4833
4817
  await persistState(userId, stateWithCompanion, initialQuota);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whaletech/pet",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Terminal pet companion — hatch, feed, and chat with your ASCII whale",
5
5
  "type": "module",
6
6
  "license": "MIT",