@gbl-uzh/platform 0.2.13 → 0.3.0

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/LICENSE.md ADDED
@@ -0,0 +1,67 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+
6
+ Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
7
+
8
+ This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.
9
+
10
+ 0. Additional Definitions.
11
+
12
+ As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License.
13
+
14
+ “The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.
15
+
16
+ An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.
17
+
18
+ A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”.
19
+
20
+ The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.
21
+
22
+ The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.
23
+
24
+ 1. Exception to Section 3 of the GNU GPL.
25
+
26
+ You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.
27
+
28
+ 2. Conveying Modified Versions.
29
+
30
+ If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:
31
+
32
+ a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or
33
+ b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.
34
+
35
+ 3. Object Code Incorporating Material from Library Header Files.
36
+
37
+ The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:
38
+
39
+ a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.
40
+ b) Accompany the object code with a copy of the GNU GPL and this license document.
41
+
42
+ 4. Combined Works.
43
+
44
+ You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:
45
+
46
+ a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.
47
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license document.
48
+ c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document.
49
+ d) Do one of the following:
50
+ 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.
51
+ 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user’s computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.
52
+ e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)
53
+
54
+ 5. Combined Libraries.
55
+
56
+ You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:
57
+
58
+ a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.
59
+ b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
60
+
61
+ 6. Revised Versions of the GNU Lesser General Public License.
62
+
63
+ The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
64
+
65
+ Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.
66
+
67
+ If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy’s public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
package/dist/index.d.ts CHANGED
@@ -114,16 +114,16 @@ declare function publishUserNotification(ctx: {
114
114
  };
115
115
  }, events?: any): void;
116
116
 
117
- declare const EventService_receiveEvents: typeof receiveEvents;
118
- declare const EventService_receiveEvent: typeof receiveEvent;
119
117
  declare const EventService_publishGlobalNotification: typeof publishGlobalNotification;
120
118
  declare const EventService_publishUserNotification: typeof publishUserNotification;
119
+ declare const EventService_receiveEvent: typeof receiveEvent;
120
+ declare const EventService_receiveEvents: typeof receiveEvents;
121
121
  declare namespace EventService {
122
122
  export {
123
- EventService_receiveEvents as receiveEvents,
124
- EventService_receiveEvent as receiveEvent,
125
123
  EventService_publishGlobalNotification as publishGlobalNotification,
126
124
  EventService_publishUserNotification as publishUserNotification,
125
+ EventService_receiveEvent as receiveEvent,
126
+ EventService_receiveEvents as receiveEvents,
127
127
  };
128
128
  }
129
129
 
@@ -162,11 +162,25 @@ declare function addPeriodSegment<TFacts>({ gameId, periodIx, facts, learningEle
162
162
  interface ActivateNextPeriodArgs {
163
163
  gameId: number;
164
164
  }
165
- declare function activateNextPeriod({ gameId }: ActivateNextPeriodArgs, ctx: Context$1, { reducers }: CtxWithFacts<any, PrismaClient>): Promise<[_prisma_client.Game, _prisma_client.Period, ...any[]] | null>;
165
+ declare function activateNextPeriod({ gameId }: ActivateNextPeriodArgs, ctx: Context$1, { reducers }: CtxWithFacts<any, PrismaClient>): Promise<[_prisma_client.Game & {
166
+ periods: (_prisma_client.Period & {
167
+ segments: _prisma_client.PeriodSegment[];
168
+ })[];
169
+ }, _prisma_client.Period, ...any[]] | null>;
166
170
  interface ActivateSegmentArgs {
167
171
  gameId: number;
168
172
  }
169
- declare function activateNextSegment({ gameId }: ActivateSegmentArgs, ctx: Context$1, { reducers }: CtxWithFacts<any, PrismaClient>): Promise<[_prisma_client.Game, _prisma_client.Period, _prisma_client.PeriodSegment, ...any[]] | [_prisma_client.Game, _prisma_client.PeriodSegment & {
173
+ declare function activateNextSegment({ gameId }: ActivateSegmentArgs, ctx: Context$1, { reducers }: CtxWithFacts<any, PrismaClient>): Promise<[_prisma_client.Game & {
174
+ periods: (_prisma_client.Period & {
175
+ segments: _prisma_client.PeriodSegment[];
176
+ })[];
177
+ players: _prisma_client.Player[];
178
+ }, _prisma_client.Period, _prisma_client.PeriodSegment, ...any[]] | [_prisma_client.Game & {
179
+ periods: (_prisma_client.Period & {
180
+ segments: _prisma_client.PeriodSegment[];
181
+ })[];
182
+ players: _prisma_client.Player[];
183
+ }, _prisma_client.PeriodSegment & {
170
184
  results: _prisma_client.PlayerResult[];
171
185
  }, ...any[]] | null>;
172
186
  declare const PlayerFactsSchema: yup.ObjectSchema<{
@@ -250,38 +264,38 @@ declare function computeSegmentEndResults(game: any, ctx: any, { reducers }: {
250
264
  extras: any[];
251
265
  };
252
266
 
253
- declare const GameService_createGame: typeof createGame;
254
- declare const GameService_addGamePeriod: typeof addGamePeriod;
255
- declare const GameService_addPeriodSegment: typeof addPeriodSegment;
267
+ type GameService_PlayerFacts = PlayerFacts;
256
268
  declare const GameService_activateNextPeriod: typeof activateNextPeriod;
257
269
  declare const GameService_activateNextSegment: typeof activateNextSegment;
258
- type GameService_PlayerFacts = PlayerFacts;
259
- declare const GameService_updatePlayerData: typeof updatePlayerData;
260
- declare const GameService_getGames: typeof getGames;
270
+ declare const GameService_addGamePeriod: typeof addGamePeriod;
271
+ declare const GameService_addPeriodSegment: typeof addPeriodSegment;
272
+ declare const GameService_computePeriodEndResults: typeof computePeriodEndResults;
273
+ declare const GameService_computePeriodStartResults: typeof computePeriodStartResults;
274
+ declare const GameService_computeSegmentEndResults: typeof computeSegmentEndResults;
275
+ declare const GameService_computeSegmentStartResults: typeof computeSegmentStartResults;
276
+ declare const GameService_createGame: typeof createGame;
261
277
  declare const GameService_getGame: typeof getGame;
262
278
  declare const GameService_getGameFromContext: typeof getGameFromContext;
279
+ declare const GameService_getGames: typeof getGames;
263
280
  declare const GameService_getLearningElements: typeof getLearningElements;
264
- declare const GameService_computePeriodStartResults: typeof computePeriodStartResults;
265
- declare const GameService_computePeriodEndResults: typeof computePeriodEndResults;
266
- declare const GameService_computeSegmentStartResults: typeof computeSegmentStartResults;
267
- declare const GameService_computeSegmentEndResults: typeof computeSegmentEndResults;
281
+ declare const GameService_updatePlayerData: typeof updatePlayerData;
268
282
  declare namespace GameService {
269
283
  export {
270
- GameService_createGame as createGame,
271
- GameService_addGamePeriod as addGamePeriod,
272
- GameService_addPeriodSegment as addPeriodSegment,
284
+ GameService_PlayerFacts as PlayerFacts,
273
285
  GameService_activateNextPeriod as activateNextPeriod,
274
286
  GameService_activateNextSegment as activateNextSegment,
275
- GameService_PlayerFacts as PlayerFacts,
276
- GameService_updatePlayerData as updatePlayerData,
277
- GameService_getGames as getGames,
287
+ GameService_addGamePeriod as addGamePeriod,
288
+ GameService_addPeriodSegment as addPeriodSegment,
289
+ GameService_computePeriodEndResults as computePeriodEndResults,
290
+ GameService_computePeriodStartResults as computePeriodStartResults,
291
+ GameService_computeSegmentEndResults as computeSegmentEndResults,
292
+ GameService_computeSegmentStartResults as computeSegmentStartResults,
293
+ GameService_createGame as createGame,
278
294
  GameService_getGame as getGame,
279
295
  GameService_getGameFromContext as getGameFromContext,
296
+ GameService_getGames as getGames,
280
297
  GameService_getLearningElements as getLearningElements,
281
- GameService_computePeriodStartResults as computePeriodStartResults,
282
- GameService_computePeriodEndResults as computePeriodEndResults,
283
- GameService_computeSegmentStartResults as computeSegmentStartResults,
284
- GameService_computeSegmentEndResults as computeSegmentEndResults,
298
+ GameService_updatePlayerData as updatePlayerData,
285
299
  };
286
300
  }
287
301
 
@@ -402,29 +416,29 @@ declare function getPastResults(args: any, ctx: Context): Promise<(_prisma_clien
402
416
  })[] | null>;
403
417
  declare function updateReadyState(args: any, ctx: Context): Promise<_prisma_client.Player>;
404
418
 
405
- declare const PlayService_performAction: typeof performAction;
406
- declare const PlayService_saveDecisions: typeof saveDecisions;
407
- declare const PlayService_getPlayerResult: typeof getPlayerResult;
408
- declare const PlayService_getPlayerData: typeof getPlayerData;
409
- declare const PlayService_getLearningElement: typeof getLearningElement;
410
419
  declare const PlayService_attemptLearningElement: typeof attemptLearningElement;
411
- declare const PlayService_markStoryElement: typeof markStoryElement;
412
- declare const PlayService_getPlayerTransactions: typeof getPlayerTransactions;
413
- declare const PlayService_getPlayerResults: typeof getPlayerResults;
420
+ declare const PlayService_getLearningElement: typeof getLearningElement;
414
421
  declare const PlayService_getPastResults: typeof getPastResults;
422
+ declare const PlayService_getPlayerData: typeof getPlayerData;
423
+ declare const PlayService_getPlayerResult: typeof getPlayerResult;
424
+ declare const PlayService_getPlayerResults: typeof getPlayerResults;
425
+ declare const PlayService_getPlayerTransactions: typeof getPlayerTransactions;
426
+ declare const PlayService_markStoryElement: typeof markStoryElement;
427
+ declare const PlayService_performAction: typeof performAction;
428
+ declare const PlayService_saveDecisions: typeof saveDecisions;
415
429
  declare const PlayService_updateReadyState: typeof updateReadyState;
416
430
  declare namespace PlayService {
417
431
  export {
418
- PlayService_performAction as performAction,
419
- PlayService_saveDecisions as saveDecisions,
420
- PlayService_getPlayerResult as getPlayerResult,
421
- PlayService_getPlayerData as getPlayerData,
422
- PlayService_getLearningElement as getLearningElement,
423
432
  PlayService_attemptLearningElement as attemptLearningElement,
424
- PlayService_markStoryElement as markStoryElement,
425
- PlayService_getPlayerTransactions as getPlayerTransactions,
426
- PlayService_getPlayerResults as getPlayerResults,
433
+ PlayService_getLearningElement as getLearningElement,
427
434
  PlayService_getPastResults as getPastResults,
435
+ PlayService_getPlayerData as getPlayerData,
436
+ PlayService_getPlayerResult as getPlayerResult,
437
+ PlayService_getPlayerResults as getPlayerResults,
438
+ PlayService_getPlayerTransactions as getPlayerTransactions,
439
+ PlayService_markStoryElement as markStoryElement,
440
+ PlayService_performAction as performAction,
441
+ PlayService_saveDecisions as saveDecisions,
428
442
  PlayService_updateReadyState as updateReadyState,
429
443
  };
430
444
  }
package/dist/index.js CHANGED
@@ -667,6 +667,13 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
667
667
  where: {
668
668
  id: gameId
669
669
  },
670
+ include: {
671
+ periods: {
672
+ include: {
673
+ segments: true
674
+ }
675
+ }
676
+ },
670
677
  data: {
671
678
  status: "PREPARATION" /* Preparation */,
672
679
  activePeriodIx: nextPeriodIx,
@@ -718,6 +725,13 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
718
725
  data: {
719
726
  status: "CONSOLIDATION" /* Consolidation */
720
727
  },
728
+ include: {
729
+ periods: {
730
+ include: {
731
+ segments: true
732
+ }
733
+ }
734
+ },
721
735
  where: {
722
736
  id: gameId
723
737
  }
@@ -779,6 +793,13 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
779
793
  where: {
780
794
  id: gameId
781
795
  },
796
+ include: {
797
+ periods: {
798
+ include: {
799
+ segments: true
800
+ }
801
+ }
802
+ },
782
803
  data: {
783
804
  status: "RESULTS" /* Results */,
784
805
  activePeriodIx: nextPeriodIx,
@@ -832,6 +853,13 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
832
853
  where: {
833
854
  id: gameId
834
855
  },
856
+ include: {
857
+ periods: {
858
+ include: {
859
+ segments: true
860
+ }
861
+ }
862
+ },
835
863
  data: {
836
864
  status: "PREPARATION" /* Preparation */
837
865
  }
@@ -903,6 +931,14 @@ async function activateNextSegment({ gameId }, ctx, { reducers }) {
903
931
  where: {
904
932
  id: gameId
905
933
  },
934
+ include: {
935
+ periods: {
936
+ include: {
937
+ segments: true
938
+ }
939
+ },
940
+ players: true
941
+ },
906
942
  data: {
907
943
  status: "RUNNING" /* Running */
908
944
  }
@@ -969,6 +1005,14 @@ async function activateNextSegment({ gameId }, ctx, { reducers }) {
969
1005
  const result = await ctx.prisma.$transaction([
970
1006
  ctx.prisma.game.update({
971
1007
  where: { id: gameId },
1008
+ include: {
1009
+ periods: {
1010
+ include: {
1011
+ segments: true
1012
+ }
1013
+ },
1014
+ players: true
1015
+ },
972
1016
  data: {
973
1017
  status: "PAUSED" /* Paused */
974
1018
  }
@@ -1140,7 +1184,7 @@ function computePeriodStartResults({ results, players, activePeriodIx, gameId, p
1140
1184
  type: reducers.PeriodResult.ActionTypes.PERIOD_RESULTS_START,
1141
1185
  payload: {
1142
1186
  playerRole: result3.player.role ?? result3.player.connect.role,
1143
- initialCash: periodFacts.initialCash
1187
+ periodFacts
1144
1188
  }
1145
1189
  });
1146
1190
  const mapper = mapAction({
@@ -1180,7 +1224,7 @@ function computePeriodStartResults({ results, players, activePeriodIx, gameId, p
1180
1224
  type: reducers.PeriodResult.ActionTypes.PERIOD_RESULTS_INITIALIZE,
1181
1225
  payload: {
1182
1226
  playerRole: player.role,
1183
- initialCash: periodFacts.initialCash
1227
+ periodFacts
1184
1228
  }
1185
1229
  }
1186
1230
  );
@@ -1235,19 +1279,12 @@ async function computePeriodEndResults({
1235
1279
  } = reducers.PeriodResult.apply(result.facts, {
1236
1280
  type: reducers.PeriodResult.ActionTypes.PERIOD_RESULTS_END,
1237
1281
  payload: {
1238
- interestRate: periodFacts.interestRate,
1239
- spotPrice: segmentFacts.spotPrice,
1240
- futuresPrice: segmentFacts.futuresPrice,
1241
- randomSeed: periodFacts.randomSeed,
1242
- initialSpotPrice: periodFacts.initialSpotPrice,
1282
+ periodFacts,
1283
+ segmentFacts,
1243
1284
  playerRole: result.player.role,
1244
1285
  playerLevel: result.player.levelIx + 1,
1245
1286
  playerExperience: result.player.experience,
1246
- storageCostPerItem: periodFacts.storageCostPerItem,
1247
- trendE: periodFacts.trendE,
1248
- trendGap: periodFacts.trendGap,
1249
1287
  consolidationDecisions,
1250
- cashInflowTotal: segmentFacts.cashInflowTotal,
1251
1288
  periodIx: activePeriodIx
1252
1289
  }
1253
1290
  });
@@ -1312,12 +1349,10 @@ function computeSegmentStartResults(game, ctx, { reducers }) {
1312
1349
  type: reducers.SegmentResult.ActionTypes.SEGMENT_RESULTS_START,
1313
1350
  payload: {
1314
1351
  playerRole: result.player.role,
1315
- interestRate: game.activePeriod.facts.interestRate,
1316
- futuresPriceNext: game.activePeriod.activeSegment.nextSegment.facts.futuresPrice,
1317
- futuresPriceCurrent: game.activePeriod.activeSegment.facts.futuresPrice,
1318
- spotPriceNext: game.activePeriod.activeSegment.nextSegment.facts.spotPrice,
1319
- segmentIx: nextSegmentIx,
1320
- cashInflow: game.activePeriod.activeSegment.nextSegment.facts.cashInflow
1352
+ periodFacts: game.activePeriod.facts,
1353
+ segmentFacts: game.activePeriod.activeSegment.facts,
1354
+ nextSegmentFacts: game.activePeriod.activeSegment.nextSegment?.facts,
1355
+ segmentIx: nextSegmentIx
1321
1356
  }
1322
1357
  }
1323
1358
  );
@@ -1371,10 +1406,11 @@ function computeSegmentStartResults(game, ctx, { reducers }) {
1371
1406
  const { result: facts } = reducers.SegmentResult.apply(result.facts, {
1372
1407
  type: reducers.SegmentResult.ActionTypes.SEGMENT_RESULTS_INITIALIZE,
1373
1408
  payload: {
1374
- cashBalance: result.facts.cashBalance,
1375
- storageAmount: result.facts.storageAmount,
1376
- spotPrice: game.activePeriod.facts.initialSpotPrice,
1377
- playerRole: result.player.role
1409
+ playerRole: result.player.role,
1410
+ periodFacts: game.activePeriod.facts,
1411
+ segmentFacts: game.activePeriod.activeSegment?.facts,
1412
+ nextSegmentFacts: game.activePeriod.activeSegment?.nextSegment?.facts,
1413
+ segmentIx: nextSegmentIx
1378
1414
  }
1379
1415
  });
1380
1416
  const common = {
@@ -1422,7 +1458,9 @@ function computeSegmentEndResults(game, ctx, { reducers }) {
1422
1458
  {
1423
1459
  type: reducers.SegmentResult.ActionTypes.SEGMENT_RESULTS_END,
1424
1460
  payload: {
1425
- storageCostPerItem: game.activePeriod.facts.storageCostPerItem,
1461
+ playerRole: result.player.role,
1462
+ periodFacts: game.activePeriod.facts,
1463
+ segmentFacts: game.activePeriod.activeSegment.facts,
1426
1464
  segmentIx: game.activePeriod.activeSegmentIx
1427
1465
  }
1428
1466
  }
@@ -1,4 +1,9 @@
1
1
  declare function setDifference(a: any, b: any, filterNoId?: boolean): any;
2
2
  declare function setIntersection(a: any, b: any): any;
3
+ declare function debugLog(...args: any[]): void;
4
+ declare function diceRoll(seeds?: number[]): number;
5
+ declare function computeScenarioOutcome(trend: any, gap: any, diceRoll: any): any;
6
+ declare function computePercentChange(newValue: any, oldValue: any): number;
7
+ declare function withPercentChange(value: any, percentChange: any): number;
3
8
 
4
- export { setDifference, setIntersection };
9
+ export { computePercentChange, computeScenarioOutcome, debugLog, diceRoll, setDifference, setIntersection, withPercentChange };
package/dist/lib/util.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,15 +17,26 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
18
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
25
 
20
26
  // src/lib/util.ts
21
27
  var util_exports = {};
22
28
  __export(util_exports, {
29
+ computePercentChange: () => computePercentChange,
30
+ computeScenarioOutcome: () => computeScenarioOutcome,
31
+ debugLog: () => debugLog,
32
+ diceRoll: () => diceRoll,
23
33
  setDifference: () => setDifference,
24
- setIntersection: () => setIntersection
34
+ setIntersection: () => setIntersection,
35
+ withPercentChange: () => withPercentChange
25
36
  });
26
37
  module.exports = __toCommonJS(util_exports);
38
+ var import_random_js = require("random-js");
39
+ var import_util = __toESM(require("util"));
27
40
  function setDifference(a, b, filterNoId = false) {
28
41
  if (!b)
29
42
  return a;
@@ -37,8 +50,31 @@ function setIntersection(a, b) {
37
50
  const B = new Set(b.map((item) => item.id));
38
51
  return a.filter((item) => B.has(item.id) && item.id);
39
52
  }
53
+ function debugLog(...args) {
54
+ if (process.env.NODE_ENV === "development") {
55
+ console.log(import_util.default.inspect(args, { showHidden: false, depth: null }));
56
+ }
57
+ }
58
+ function diceRoll(seeds = []) {
59
+ const rng = import_random_js.MersenneTwister19937.seedWithArray(seeds);
60
+ return (0, import_random_js.integer)(1, 6)(rng);
61
+ }
62
+ function computeScenarioOutcome(trend, gap, diceRoll2) {
63
+ return trend + (diceRoll2 - 7) * gap;
64
+ }
65
+ function computePercentChange(newValue, oldValue) {
66
+ return (newValue - oldValue) / oldValue;
67
+ }
68
+ function withPercentChange(value, percentChange) {
69
+ return value * (1 + percentChange);
70
+ }
40
71
  // Annotate the CommonJS export names for ESM import in node:
41
72
  0 && (module.exports = {
73
+ computePercentChange,
74
+ computeScenarioOutcome,
75
+ debugLog,
76
+ diceRoll,
42
77
  setDifference,
43
- setIntersection
78
+ setIntersection,
79
+ withPercentChange
44
80
  });
package/dist/nexus.js CHANGED
@@ -953,6 +953,13 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
953
953
  where: {
954
954
  id: gameId
955
955
  },
956
+ include: {
957
+ periods: {
958
+ include: {
959
+ segments: true
960
+ }
961
+ }
962
+ },
956
963
  data: {
957
964
  status: "PREPARATION" /* Preparation */,
958
965
  activePeriodIx: nextPeriodIx,
@@ -1004,6 +1011,13 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
1004
1011
  data: {
1005
1012
  status: "CONSOLIDATION" /* Consolidation */
1006
1013
  },
1014
+ include: {
1015
+ periods: {
1016
+ include: {
1017
+ segments: true
1018
+ }
1019
+ }
1020
+ },
1007
1021
  where: {
1008
1022
  id: gameId
1009
1023
  }
@@ -1065,6 +1079,13 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
1065
1079
  where: {
1066
1080
  id: gameId
1067
1081
  },
1082
+ include: {
1083
+ periods: {
1084
+ include: {
1085
+ segments: true
1086
+ }
1087
+ }
1088
+ },
1068
1089
  data: {
1069
1090
  status: "RESULTS" /* Results */,
1070
1091
  activePeriodIx: nextPeriodIx,
@@ -1118,6 +1139,13 @@ async function activateNextPeriod({ gameId }, ctx, { reducers }) {
1118
1139
  where: {
1119
1140
  id: gameId
1120
1141
  },
1142
+ include: {
1143
+ periods: {
1144
+ include: {
1145
+ segments: true
1146
+ }
1147
+ }
1148
+ },
1121
1149
  data: {
1122
1150
  status: "PREPARATION" /* Preparation */
1123
1151
  }
@@ -1189,6 +1217,14 @@ async function activateNextSegment({ gameId }, ctx, { reducers }) {
1189
1217
  where: {
1190
1218
  id: gameId
1191
1219
  },
1220
+ include: {
1221
+ periods: {
1222
+ include: {
1223
+ segments: true
1224
+ }
1225
+ },
1226
+ players: true
1227
+ },
1192
1228
  data: {
1193
1229
  status: "RUNNING" /* Running */
1194
1230
  }
@@ -1255,6 +1291,14 @@ async function activateNextSegment({ gameId }, ctx, { reducers }) {
1255
1291
  const result = await ctx.prisma.$transaction([
1256
1292
  ctx.prisma.game.update({
1257
1293
  where: { id: gameId },
1294
+ include: {
1295
+ periods: {
1296
+ include: {
1297
+ segments: true
1298
+ }
1299
+ },
1300
+ players: true
1301
+ },
1258
1302
  data: {
1259
1303
  status: "PAUSED" /* Paused */
1260
1304
  }
@@ -1426,7 +1470,7 @@ function computePeriodStartResults({ results, players, activePeriodIx, gameId, p
1426
1470
  type: reducers.PeriodResult.ActionTypes.PERIOD_RESULTS_START,
1427
1471
  payload: {
1428
1472
  playerRole: result3.player.role ?? result3.player.connect.role,
1429
- initialCash: periodFacts.initialCash
1473
+ periodFacts
1430
1474
  }
1431
1475
  });
1432
1476
  const mapper = mapAction({
@@ -1466,7 +1510,7 @@ function computePeriodStartResults({ results, players, activePeriodIx, gameId, p
1466
1510
  type: reducers.PeriodResult.ActionTypes.PERIOD_RESULTS_INITIALIZE,
1467
1511
  payload: {
1468
1512
  playerRole: player.role,
1469
- initialCash: periodFacts.initialCash
1513
+ periodFacts
1470
1514
  }
1471
1515
  }
1472
1516
  );
@@ -1521,19 +1565,12 @@ async function computePeriodEndResults({
1521
1565
  } = reducers.PeriodResult.apply(result.facts, {
1522
1566
  type: reducers.PeriodResult.ActionTypes.PERIOD_RESULTS_END,
1523
1567
  payload: {
1524
- interestRate: periodFacts.interestRate,
1525
- spotPrice: segmentFacts.spotPrice,
1526
- futuresPrice: segmentFacts.futuresPrice,
1527
- randomSeed: periodFacts.randomSeed,
1528
- initialSpotPrice: periodFacts.initialSpotPrice,
1568
+ periodFacts,
1569
+ segmentFacts,
1529
1570
  playerRole: result.player.role,
1530
1571
  playerLevel: result.player.levelIx + 1,
1531
1572
  playerExperience: result.player.experience,
1532
- storageCostPerItem: periodFacts.storageCostPerItem,
1533
- trendE: periodFacts.trendE,
1534
- trendGap: periodFacts.trendGap,
1535
1573
  consolidationDecisions,
1536
- cashInflowTotal: segmentFacts.cashInflowTotal,
1537
1574
  periodIx: activePeriodIx
1538
1575
  }
1539
1576
  });
@@ -1598,12 +1635,10 @@ function computeSegmentStartResults(game, ctx, { reducers }) {
1598
1635
  type: reducers.SegmentResult.ActionTypes.SEGMENT_RESULTS_START,
1599
1636
  payload: {
1600
1637
  playerRole: result.player.role,
1601
- interestRate: game.activePeriod.facts.interestRate,
1602
- futuresPriceNext: game.activePeriod.activeSegment.nextSegment.facts.futuresPrice,
1603
- futuresPriceCurrent: game.activePeriod.activeSegment.facts.futuresPrice,
1604
- spotPriceNext: game.activePeriod.activeSegment.nextSegment.facts.spotPrice,
1605
- segmentIx: nextSegmentIx,
1606
- cashInflow: game.activePeriod.activeSegment.nextSegment.facts.cashInflow
1638
+ periodFacts: game.activePeriod.facts,
1639
+ segmentFacts: game.activePeriod.activeSegment.facts,
1640
+ nextSegmentFacts: game.activePeriod.activeSegment.nextSegment?.facts,
1641
+ segmentIx: nextSegmentIx
1607
1642
  }
1608
1643
  }
1609
1644
  );
@@ -1657,10 +1692,11 @@ function computeSegmentStartResults(game, ctx, { reducers }) {
1657
1692
  const { result: facts } = reducers.SegmentResult.apply(result.facts, {
1658
1693
  type: reducers.SegmentResult.ActionTypes.SEGMENT_RESULTS_INITIALIZE,
1659
1694
  payload: {
1660
- cashBalance: result.facts.cashBalance,
1661
- storageAmount: result.facts.storageAmount,
1662
- spotPrice: game.activePeriod.facts.initialSpotPrice,
1663
- playerRole: result.player.role
1695
+ playerRole: result.player.role,
1696
+ periodFacts: game.activePeriod.facts,
1697
+ segmentFacts: game.activePeriod.activeSegment?.facts,
1698
+ nextSegmentFacts: game.activePeriod.activeSegment?.nextSegment?.facts,
1699
+ segmentIx: nextSegmentIx
1664
1700
  }
1665
1701
  });
1666
1702
  const common = {
@@ -1708,7 +1744,9 @@ function computeSegmentEndResults(game, ctx, { reducers }) {
1708
1744
  {
1709
1745
  type: reducers.SegmentResult.ActionTypes.SEGMENT_RESULTS_END,
1710
1746
  payload: {
1711
- storageCostPerItem: game.activePeriod.facts.storageCostPerItem,
1747
+ playerRole: result.player.role,
1748
+ periodFacts: game.activePeriod.facts,
1749
+ segmentFacts: game.activePeriod.activeSegment.facts,
1712
1750
  segmentIx: game.activePeriod.activeSegmentIx
1713
1751
  }
1714
1752
  }
@@ -5,7 +5,20 @@ mutation ActivateNextPeriod($gameId: Int!) {
5
5
  activateNextPeriod(gameId: $gameId) {
6
6
  ...GameData
7
7
  periods {
8
- ...PeriodData
8
+ id
9
+
10
+ index
11
+ activeSegmentIx
12
+
13
+ facts
14
+
15
+ segments {
16
+ id
17
+
18
+ index
19
+
20
+ facts
21
+ }
9
22
  }
10
23
  }
11
24
  }
@@ -5,10 +5,37 @@ mutation ActivateNextSegment($gameId: Int!) {
5
5
  activateNextSegment(gameId: $gameId) {
6
6
  ...GameData
7
7
  periods {
8
- ...PeriodData
8
+ id
9
+
10
+ index
11
+ activeSegmentIx
12
+
13
+ facts
14
+
15
+ segments {
16
+ id
17
+
18
+ index
19
+
20
+ facts
21
+ }
9
22
  }
10
23
  players {
11
- ...PlayerData
24
+ id
25
+
26
+ isReady
27
+
28
+ role
29
+
30
+ name
31
+ avatar
32
+ location
33
+ color
34
+
35
+ facts
36
+
37
+ experience
38
+ experienceToNext
12
39
  }
13
40
  }
14
41
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gbl-uzh/platform",
3
- "version": "0.2.13",
4
- "license": "AGPL-3.0",
3
+ "version": "0.3.0",
4
+ "license": "LGPL-3.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
@@ -46,7 +46,7 @@
46
46
  "peerDependencies": {
47
47
  "@apollo/client": "^3.7.0",
48
48
  "@prisma/client": "^4.8.0",
49
- "@uzh-bf/design-system": "^0.0.79",
49
+ "@uzh-bf/design-system": "^1.0.0",
50
50
  "graphql": "^16.6.0",
51
51
  "graphql-scalars": "^1.19.0",
52
52
  "graphql-yoga": "^3.0.0",
@@ -60,5 +60,8 @@
60
60
  },
61
61
  "volta": {
62
62
  "extends": "../../package.json"
63
+ },
64
+ "dependencies": {
65
+ "random-js": "2.1.0"
63
66
  }
64
67
  }