@slot-engine/core 0.0.10 → 0.1.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/README.md +0 -3
- package/dist/index.d.mts +26 -7
- package/dist/index.d.ts +26 -7
- package/dist/index.js +63 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -598,7 +598,11 @@ var Board = class {
|
|
|
598
598
|
for (const [r, stopPos] of Object.entries(opts.forcedStops)) {
|
|
599
599
|
const reelIdx = Number(r);
|
|
600
600
|
const symCount = symbolsPerReel[reelIdx];
|
|
601
|
-
|
|
601
|
+
if (opts.forcedStopsOffset !== false) {
|
|
602
|
+
finalReelStops[reelIdx] = stopPos - Math.round(opts.ctx.services.rng.randomFloat(0, symCount - 1));
|
|
603
|
+
} else {
|
|
604
|
+
finalReelStops[reelIdx] = stopPos;
|
|
605
|
+
}
|
|
602
606
|
if (finalReelStops[reelIdx] < 0) {
|
|
603
607
|
finalReelStops[reelIdx] = opts.reels[reelIdx].length + finalReelStops[reelIdx];
|
|
604
608
|
}
|
|
@@ -641,15 +645,22 @@ var Board = class {
|
|
|
641
645
|
);
|
|
642
646
|
}
|
|
643
647
|
const reels = this.lastUsedReels;
|
|
644
|
-
opts.symbolsToDelete.
|
|
648
|
+
const sortedDeletions = [...opts.symbolsToDelete].sort((a, b) => b.rowIdx - a.rowIdx);
|
|
649
|
+
sortedDeletions.forEach(({ reelIdx, rowIdx }) => {
|
|
645
650
|
this.reels[reelIdx].splice(rowIdx, 1);
|
|
646
651
|
});
|
|
647
652
|
const newFirstSymbolPositions = {};
|
|
653
|
+
const newBoardSymbols = {};
|
|
654
|
+
const newPaddingTopSymbols = {};
|
|
648
655
|
for (let ridx = 0; ridx < reelsAmount; ridx++) {
|
|
649
656
|
while (this.reels[ridx].length < symbolsPerReel[ridx]) {
|
|
650
657
|
const padSymbol = this.paddingTop[ridx].pop();
|
|
651
658
|
if (padSymbol) {
|
|
652
659
|
this.reels[ridx].unshift(padSymbol);
|
|
660
|
+
if (!newBoardSymbols[ridx]) {
|
|
661
|
+
newBoardSymbols[ridx] = [];
|
|
662
|
+
}
|
|
663
|
+
newBoardSymbols[ridx].unshift(padSymbol);
|
|
653
664
|
} else {
|
|
654
665
|
break;
|
|
655
666
|
}
|
|
@@ -663,17 +674,30 @@ var Board = class {
|
|
|
663
674
|
assert3(newSymbol, "Failed to get new symbol for tumbling.");
|
|
664
675
|
this.reels[ridx].unshift(newSymbol);
|
|
665
676
|
newFirstSymbolPositions[ridx] = symbolPos;
|
|
677
|
+
if (!newBoardSymbols[ridx]) {
|
|
678
|
+
newBoardSymbols[ridx] = [];
|
|
679
|
+
}
|
|
680
|
+
newBoardSymbols[ridx].unshift(newSymbol);
|
|
666
681
|
}
|
|
667
682
|
}
|
|
668
683
|
for (let ridx = 0; ridx < reelsAmount; ridx++) {
|
|
669
684
|
const firstSymbolPos = newFirstSymbolPositions[ridx];
|
|
685
|
+
if (firstSymbolPos === void 0) continue;
|
|
670
686
|
for (let p = 1; p <= padSymbols; p++) {
|
|
671
687
|
const topPos = (firstSymbolPos - p + reels[ridx].length) % reels[ridx].length;
|
|
672
688
|
const padSymbol = reels[ridx][topPos];
|
|
673
689
|
assert3(padSymbol, "Failed to get new padding symbol for tumbling.");
|
|
674
690
|
this.paddingTop[ridx].unshift(padSymbol);
|
|
691
|
+
if (!newPaddingTopSymbols[ridx]) {
|
|
692
|
+
newPaddingTopSymbols[ridx] = [];
|
|
693
|
+
}
|
|
694
|
+
newPaddingTopSymbols[ridx].unshift(padSymbol);
|
|
675
695
|
}
|
|
676
696
|
}
|
|
697
|
+
return {
|
|
698
|
+
newBoardSymbols,
|
|
699
|
+
newPaddingTopSymbols
|
|
700
|
+
};
|
|
677
701
|
}
|
|
678
702
|
};
|
|
679
703
|
|
|
@@ -793,8 +817,8 @@ var BoardService = class extends AbstractService {
|
|
|
793
817
|
/**
|
|
794
818
|
* Draws a board using specified reel stops.
|
|
795
819
|
*/
|
|
796
|
-
drawBoardWithForcedStops(
|
|
797
|
-
this.drawBoardMixed(reels, forcedStops);
|
|
820
|
+
drawBoardWithForcedStops(opts) {
|
|
821
|
+
this.drawBoardMixed(opts.reels, opts.forcedStops, opts.randomOffset);
|
|
798
822
|
}
|
|
799
823
|
/**
|
|
800
824
|
* Draws a board using random reel stops.
|
|
@@ -802,18 +826,19 @@ var BoardService = class extends AbstractService {
|
|
|
802
826
|
drawBoardWithRandomStops(reels) {
|
|
803
827
|
this.drawBoardMixed(reels);
|
|
804
828
|
}
|
|
805
|
-
drawBoardMixed(reels, forcedStops) {
|
|
829
|
+
drawBoardMixed(reels, forcedStops, forcedStopsOffset) {
|
|
806
830
|
this.board.drawBoardMixed({
|
|
807
831
|
ctx: this.ctx(),
|
|
808
832
|
reels,
|
|
809
|
-
forcedStops
|
|
833
|
+
forcedStops,
|
|
834
|
+
forcedStopsOffset
|
|
810
835
|
});
|
|
811
836
|
}
|
|
812
837
|
/**
|
|
813
838
|
* Tumbles the board. All given symbols will be deleted and new symbols will fall from the top.
|
|
814
839
|
*/
|
|
815
840
|
tumbleBoard(symbolsToDelete) {
|
|
816
|
-
this.board.tumbleBoard({
|
|
841
|
+
return this.board.tumbleBoard({
|
|
817
842
|
ctx: this.ctx(),
|
|
818
843
|
symbolsToDelete
|
|
819
844
|
});
|
|
@@ -906,6 +931,25 @@ var GameService = class extends AbstractService {
|
|
|
906
931
|
constructor(ctx) {
|
|
907
932
|
super(ctx);
|
|
908
933
|
}
|
|
934
|
+
/**
|
|
935
|
+
* Intended for internal use only.\
|
|
936
|
+
* Generates reels for all reel sets in the game configuration.
|
|
937
|
+
*/
|
|
938
|
+
_generateReels() {
|
|
939
|
+
const config = this.ctx().config;
|
|
940
|
+
for (const mode of Object.values(config.gameModes)) {
|
|
941
|
+
if (mode.reelSets && mode.reelSets.length > 0) {
|
|
942
|
+
for (const reelSet of Object.values(mode.reelSets)) {
|
|
943
|
+
reelSet.associatedGameModeName = mode.name;
|
|
944
|
+
reelSet.generateReels(config);
|
|
945
|
+
}
|
|
946
|
+
} else {
|
|
947
|
+
throw new Error(
|
|
948
|
+
`Game mode "${mode.name}" has no reel sets defined. Cannot generate reelset files.`
|
|
949
|
+
);
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
}
|
|
909
953
|
/**
|
|
910
954
|
* Retrieves a reel set by its ID within a specific game mode.
|
|
911
955
|
*/
|
|
@@ -1787,7 +1831,7 @@ Simulating game mode: ${mode}`);
|
|
|
1787
1831
|
if (mode.reelSets && mode.reelSets.length > 0) {
|
|
1788
1832
|
for (const reelSet of Object.values(mode.reelSets)) {
|
|
1789
1833
|
reelSet.associatedGameModeName = mode.name;
|
|
1790
|
-
reelSet.generateReels(this);
|
|
1834
|
+
reelSet.generateReels(this.gameConfig);
|
|
1791
1835
|
}
|
|
1792
1836
|
} else {
|
|
1793
1837
|
throw new Error(
|
|
@@ -2961,7 +3005,7 @@ var ReelSet = class {
|
|
|
2961
3005
|
this.rng = new RandomNumberGenerator();
|
|
2962
3006
|
this.rng.setSeed(opts.seed ?? 0);
|
|
2963
3007
|
}
|
|
2964
|
-
generateReels(
|
|
3008
|
+
generateReels(config) {
|
|
2965
3009
|
throw new Error("Not implemented");
|
|
2966
3010
|
}
|
|
2967
3011
|
/**
|
|
@@ -3133,7 +3177,7 @@ var GeneratedReelSet = class extends ReelSet {
|
|
|
3133
3177
|
}
|
|
3134
3178
|
return false;
|
|
3135
3179
|
}
|
|
3136
|
-
generateReels(
|
|
3180
|
+
generateReels(config) {
|
|
3137
3181
|
this.validateConfig(config);
|
|
3138
3182
|
const gameMode = config.gameModes[this.associatedGameModeName];
|
|
3139
3183
|
if (!gameMode) {
|
|
@@ -3148,7 +3192,7 @@ var GeneratedReelSet = class extends ReelSet {
|
|
|
3148
3192
|
const exists = fs5.existsSync(filePath);
|
|
3149
3193
|
if (exists && !this.overrideExisting) {
|
|
3150
3194
|
this.reels = this.parseReelsetCSV(filePath, config);
|
|
3151
|
-
return;
|
|
3195
|
+
return this;
|
|
3152
3196
|
}
|
|
3153
3197
|
if (!exists && this.symbolWeights.size === 0) {
|
|
3154
3198
|
throw new Error(
|
|
@@ -3295,6 +3339,7 @@ var GeneratedReelSet = class extends ReelSet {
|
|
|
3295
3339
|
`Generated reelset ${this.id} for game mode ${this.associatedGameModeName}`
|
|
3296
3340
|
);
|
|
3297
3341
|
}
|
|
3342
|
+
return this;
|
|
3298
3343
|
}
|
|
3299
3344
|
};
|
|
3300
3345
|
|
|
@@ -3330,7 +3375,7 @@ var StaticReelSet = class extends ReelSet {
|
|
|
3330
3375
|
);
|
|
3331
3376
|
}
|
|
3332
3377
|
}
|
|
3333
|
-
generateReels(
|
|
3378
|
+
generateReels(config) {
|
|
3334
3379
|
this.validateConfig(config);
|
|
3335
3380
|
if (this._strReels.length > 0) {
|
|
3336
3381
|
this.reels = this._strReels.map((reel) => {
|
|
@@ -3348,6 +3393,7 @@ var StaticReelSet = class extends ReelSet {
|
|
|
3348
3393
|
if (this.csvPath) {
|
|
3349
3394
|
this.reels = this.parseReelsetCSV(this.csvPath, config);
|
|
3350
3395
|
}
|
|
3396
|
+
return this;
|
|
3351
3397
|
}
|
|
3352
3398
|
};
|
|
3353
3399
|
|
|
@@ -3472,8 +3518,8 @@ var StandaloneBoard = class {
|
|
|
3472
3518
|
/**
|
|
3473
3519
|
* Draws a board using specified reel stops.
|
|
3474
3520
|
*/
|
|
3475
|
-
drawBoardWithForcedStops(
|
|
3476
|
-
this.drawBoardMixed(reels, forcedStops);
|
|
3521
|
+
drawBoardWithForcedStops(opts) {
|
|
3522
|
+
this.drawBoardMixed(opts.reels, opts.forcedStops, opts.randomOffset);
|
|
3477
3523
|
}
|
|
3478
3524
|
/**
|
|
3479
3525
|
* Draws a board using random reel stops.
|
|
@@ -3481,11 +3527,12 @@ var StandaloneBoard = class {
|
|
|
3481
3527
|
drawBoardWithRandomStops(reels) {
|
|
3482
3528
|
this.drawBoardMixed(reels);
|
|
3483
3529
|
}
|
|
3484
|
-
drawBoardMixed(reels, forcedStops) {
|
|
3530
|
+
drawBoardMixed(reels, forcedStops, forcedStopsOffset) {
|
|
3485
3531
|
this.board.drawBoardMixed({
|
|
3486
3532
|
ctx: this.ctx,
|
|
3487
3533
|
reels,
|
|
3488
3534
|
forcedStops,
|
|
3535
|
+
forcedStopsOffset,
|
|
3489
3536
|
reelsAmount: this.reelsAmount,
|
|
3490
3537
|
symbolsPerReel: this.symbolsPerReel,
|
|
3491
3538
|
padSymbols: this.padSymbols
|
|
@@ -3495,7 +3542,7 @@ var StandaloneBoard = class {
|
|
|
3495
3542
|
* Tumbles the board. All given symbols will be deleted and new symbols will fall from the top.
|
|
3496
3543
|
*/
|
|
3497
3544
|
tumbleBoard(symbolsToDelete) {
|
|
3498
|
-
this.board.tumbleBoard({
|
|
3545
|
+
return this.board.tumbleBoard({
|
|
3499
3546
|
ctx: this.ctx,
|
|
3500
3547
|
symbolsToDelete,
|
|
3501
3548
|
reelsAmount: this.reelsAmount,
|