@adatechnology/game-fluids 0.3.6 → 0.4.1

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/index.d.ts CHANGED
@@ -194,6 +194,7 @@ type FluidEvent = {
194
194
  thirst: number;
195
195
  effects: string[];
196
196
  burn: boolean;
197
+ eaten?: boolean;
197
198
  } | {
198
199
  type: 'empty';
199
200
  container: string;
@@ -267,7 +268,10 @@ interface FluidWorld {
267
268
  /** Pour on purpose for `dt` seconds (tilts the flow out of the opening even when not tilted far). Returns litres out. */
268
269
  pour(id: string, dt: number, into?: string): number;
269
270
  /** Drink `liters` (sip ~0.03 l); returns the drink event or null when empty/closed. Too hot (> 65 °C) sets `burn`. */
270
- drink(id: string, liters: number): Extract<FluidEvent, {
271
+ /** Takes `liters` out of an open container into the mouth. `eaten`: it is the liquid packed with food, eaten with it (no drinking effects). */
272
+ drink(id: string, liters: number, options?: {
273
+ eaten?: boolean;
274
+ }): Extract<FluidEvent, {
271
275
  type: 'drink';
272
276
  }> | null;
273
277
  /** Punch a hole (local space) — call it from a damage model's `hole`/`leak` events. */
@@ -322,7 +326,8 @@ declare function createFluids(options?: FluidOptions): FluidWorld;
322
326
  */
323
327
  declare const LIQUIDS: LiquidDef[];
324
328
 
325
- /** Built-in scripted uses of a held item (data in `data/item-uses.json`): `sip`, `drink`, `chug`, `pour`, `pour_out`, `open`, `close`. */
329
+ /** Built-in scripted uses of a held item (data in `data/item-uses.json`): `sip`, `drink`, `chug`, `eat` (spoonfuls from an open tin), `pour`, `pour_out`, `open`, `close`,
330
+ * `unscrew` (the other hand turns a screw cap off, `turn` keys, before the `open` key). */
326
331
  declare const ITEM_USES: ItemUseDef[];
327
332
  /** World transform of the hand (or any holder) the item pose is relative to. */
328
333
  type HandTransform = () => {
@@ -330,7 +335,7 @@ type HandTransform = () => {
330
335
  rotation: Quat;
331
336
  };
332
337
  /**
333
- * Plays an item use on a container: interpolates the keys, applies `drink` (rate × dt litres) and `pour` (`world.pour`, `rate` multiplies the
338
+ * Plays an item use on a container: interpolates the keys, applies `drink` and `eat` (rate × dt litres) and `pour` (`world.pour`, `rate` multiplies the
334
339
  * time) while the current key has that action, and fires `open` / `close` once when their key is reached. When `getHandTransform` is given, the
335
340
  * container's world transform follows hand ∘ pose every update; otherwise the host animates the viewmodel from `pose()`.
336
341
  */
@@ -1522,7 +1522,7 @@ var GameFluids = (() => {
1522
1522
  settle(c);
1523
1523
  return out;
1524
1524
  },
1525
- drink(id, liters) {
1525
+ drink(id, liters, options2) {
1526
1526
  const c = containers.get(id);
1527
1527
  const def = c ? defOf(c) : null;
1528
1528
  if (!c || !def || c.closed || c.liters <= 1e-6 || !(liters > 0)) return null;
@@ -1535,8 +1535,9 @@ var GameFluids = (() => {
1535
1535
  liters: amount,
1536
1536
  temperature: c.temperature,
1537
1537
  thirst: (def.drink?.thirst ?? 0) * amount,
1538
- effects: [...def.drink?.effects ?? []],
1539
- burn: c.temperature > 65
1538
+ effects: options2?.eaten ? [] : [...def.drink?.effects ?? []],
1539
+ burn: c.temperature > 65,
1540
+ ...options2?.eaten ? { eaten: true } : {}
1540
1541
  };
1541
1542
  emit(event);
1542
1543
  refreshLevel(c);
@@ -1884,6 +1885,128 @@ var GameFluids = (() => {
1884
1885
  }
1885
1886
  ]
1886
1887
  },
1888
+ {
1889
+ id: "eat",
1890
+ duration: 3.6,
1891
+ keys: [
1892
+ {
1893
+ t: 0,
1894
+ position: [
1895
+ 0.22,
1896
+ -0.2,
1897
+ -0.4
1898
+ ],
1899
+ rotation: [
1900
+ 0,
1901
+ 0,
1902
+ 0
1903
+ ],
1904
+ action: "none"
1905
+ },
1906
+ {
1907
+ t: 0.4,
1908
+ position: [
1909
+ 0.04,
1910
+ -0.12,
1911
+ -0.28
1912
+ ],
1913
+ rotation: [
1914
+ -0.35,
1915
+ 0,
1916
+ 0
1917
+ ],
1918
+ action: "none"
1919
+ },
1920
+ {
1921
+ t: 0.6,
1922
+ position: [
1923
+ 0.04,
1924
+ -0.1,
1925
+ -0.26
1926
+ ],
1927
+ rotation: [
1928
+ -0.45,
1929
+ 0,
1930
+ 0
1931
+ ],
1932
+ action: "eat",
1933
+ rate: 0.06
1934
+ },
1935
+ {
1936
+ t: 1.3,
1937
+ position: [
1938
+ 0.04,
1939
+ -0.12,
1940
+ -0.28
1941
+ ],
1942
+ rotation: [
1943
+ -0.35,
1944
+ 0,
1945
+ 0
1946
+ ],
1947
+ action: "eat",
1948
+ rate: 0.06
1949
+ },
1950
+ {
1951
+ t: 2,
1952
+ position: [
1953
+ 0.04,
1954
+ -0.1,
1955
+ -0.26
1956
+ ],
1957
+ rotation: [
1958
+ -0.45,
1959
+ 0,
1960
+ 0
1961
+ ],
1962
+ action: "eat",
1963
+ rate: 0.06
1964
+ },
1965
+ {
1966
+ t: 2.7,
1967
+ position: [
1968
+ 0.04,
1969
+ -0.12,
1970
+ -0.28
1971
+ ],
1972
+ rotation: [
1973
+ -0.35,
1974
+ 0,
1975
+ 0
1976
+ ],
1977
+ action: "eat",
1978
+ rate: 0.06
1979
+ },
1980
+ {
1981
+ t: 3.1,
1982
+ position: [
1983
+ 0.04,
1984
+ -0.12,
1985
+ -0.28
1986
+ ],
1987
+ rotation: [
1988
+ -0.35,
1989
+ 0,
1990
+ 0
1991
+ ],
1992
+ action: "none"
1993
+ },
1994
+ {
1995
+ t: 3.6,
1996
+ position: [
1997
+ 0.22,
1998
+ -0.2,
1999
+ -0.4
2000
+ ],
2001
+ rotation: [
2002
+ 0,
2003
+ 0,
2004
+ 0
2005
+ ],
2006
+ action: "none"
2007
+ }
2008
+ ]
2009
+ },
1887
2010
  {
1888
2011
  id: "pour",
1889
2012
  duration: 3,
@@ -2161,6 +2284,82 @@ var GameFluids = (() => {
2161
2284
  action: "none"
2162
2285
  }
2163
2286
  ]
2287
+ },
2288
+ {
2289
+ id: "unscrew",
2290
+ duration: 2.6,
2291
+ keys: [
2292
+ {
2293
+ t: 0,
2294
+ position: [
2295
+ 0.22,
2296
+ -0.2,
2297
+ -0.4
2298
+ ],
2299
+ rotation: [
2300
+ 0,
2301
+ 0,
2302
+ 0
2303
+ ],
2304
+ action: "none"
2305
+ },
2306
+ {
2307
+ t: 0.35,
2308
+ position: [
2309
+ 0.06,
2310
+ -0.09,
2311
+ -0.34
2312
+ ],
2313
+ rotation: [
2314
+ 0,
2315
+ 0,
2316
+ 0
2317
+ ],
2318
+ action: "turn"
2319
+ },
2320
+ {
2321
+ t: 1.95,
2322
+ position: [
2323
+ 0.06,
2324
+ -0.09,
2325
+ -0.34
2326
+ ],
2327
+ rotation: [
2328
+ 0,
2329
+ 0,
2330
+ 0
2331
+ ],
2332
+ action: "none"
2333
+ },
2334
+ {
2335
+ t: 2.2,
2336
+ position: [
2337
+ 0.06,
2338
+ -0.09,
2339
+ -0.34
2340
+ ],
2341
+ rotation: [
2342
+ 0,
2343
+ 0,
2344
+ 0
2345
+ ],
2346
+ action: "open"
2347
+ },
2348
+ {
2349
+ t: 2.6,
2350
+ position: [
2351
+ 0.22,
2352
+ -0.2,
2353
+ -0.4
2354
+ ],
2355
+ rotation: [
2356
+ 0,
2357
+ 0,
2358
+ 0
2359
+ ],
2360
+ action: "none"
2361
+ }
2362
+ ]
2164
2363
  }
2165
2364
  ];
2166
2365
 
@@ -2233,8 +2432,8 @@ var GameFluids = (() => {
2233
2432
  }
2234
2433
  const overlap = Math.min(end, spanEnd) - Math.max(start, spanStart);
2235
2434
  if (overlap <= 0) continue;
2236
- if (key.action === "drink") {
2237
- const ev = world.drink(containerId, (key.rate ?? DEFAULT_DRINK_RATE) * overlap);
2435
+ if (key.action === "drink" || key.action === "eat") {
2436
+ const ev = world.drink(containerId, (key.rate ?? DEFAULT_DRINK_RATE) * overlap, key.action === "eat" ? { eaten: true } : void 0);
2238
2437
  const left = world.container(containerId);
2239
2438
  if (!ev || !left || left.liters <= 1e-6) {
2240
2439
  time = def.duration;