@quenty/randomutils 2.2.0 → 2.2.1-canary.402.a911cda.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/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.2.1-canary.402.a911cda.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/randomutils@2.2.0...@quenty/randomutils@2.2.1-canary.402.a911cda.0) (2023-08-23)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Use table.clone() ([28f311b](https://github.com/Quenty/NevermoreEngine/commit/28f311b9c2534fa7b2056265db05c1447dc43a8a))
12
+
13
+
14
+ ### Features
15
+
16
+ * Add RandomSampler object to RandomUtils ([5ca48d9](https://github.com/Quenty/NevermoreEngine/commit/5ca48d91697ee0b20ec1df8dda91a0e9f9ceb0a3))
17
+
18
+
19
+
20
+
21
+
6
22
  # [2.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/randomutils@2.1.1...@quenty/randomutils@2.2.0) (2022-03-27)
7
23
 
8
24
  **Note:** Version bump only for package @quenty/randomutils
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2014-2021 Quenty
3
+ Copyright (c) 2014-2023 James Onnen (Quenty)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/randomutils",
3
- "version": "2.2.0",
3
+ "version": "2.2.1-canary.402.a911cda.0",
4
4
  "description": "Quenty's RandomUtils, utility functions for Roblox",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -28,5 +28,8 @@
28
28
  "publishConfig": {
29
29
  "access": "public"
30
30
  },
31
- "gitHead": "501844bd6c3d3f765fd3032b997d8030bc963a1f"
31
+ "dependencies": {
32
+ "@quenty/loader": "6.2.2-canary.402.a911cda.0"
33
+ },
34
+ "gitHead": "a911cdaf4f1039b599528cec17b027f4660e4fd8"
32
35
  }
@@ -0,0 +1,62 @@
1
+ --[=[
2
+ @class RandomSampler
3
+ ]=]
4
+
5
+ local require = require(script.Parent.loader).load(script)
6
+
7
+ local RandomUtils = require("RandomUtils")
8
+
9
+ local RandomSampler = {}
10
+ RandomSampler.ClassName = "RandomSampler"
11
+ RandomSampler.__index = RandomSampler
12
+
13
+ function RandomSampler.new(samples)
14
+ local self = setmetatable({}, RandomSampler)
15
+
16
+ self._optionsList = {}
17
+ self._shuffledAvailableList = {}
18
+
19
+ if samples then
20
+ self:SetSamples(samples)
21
+ end
22
+
23
+ return self
24
+ end
25
+
26
+ function RandomSampler:SetSamples(samples)
27
+ assert(type(samples) == "table", "Bad samples")
28
+
29
+ if self._optionsList ~= samples then
30
+ self._optionsList = samples
31
+
32
+ -- TODO: Smarter refill
33
+ self:Refill()
34
+ end
35
+ end
36
+
37
+ function RandomSampler:Sample()
38
+ if #self._shuffledAvailableList == 0 then
39
+ self:Refill()
40
+ end
41
+
42
+ local selection = table.remove(self._shuffledAvailableList)
43
+ self._lastSelection = selection
44
+
45
+ return selection
46
+ end
47
+
48
+ function RandomSampler:Refill()
49
+ local newList = RandomUtils.shuffledCopy(self._optionsList)
50
+
51
+ if #newList > 1 then
52
+ -- prevent repeat on restart
53
+ if newList[#newList] == self._lastSelection then
54
+ newList[1], newList[#newList] = newList[#newList], newList[1]
55
+ end
56
+ end
57
+
58
+ self._shuffledAvailableList = newList
59
+ end
60
+
61
+
62
+ return RandomSampler
@@ -64,10 +64,7 @@ end
64
64
  @return { T }
65
65
  ]=]
66
66
  function RandomUtils.shuffledCopy(list, random)
67
- local copy = {}
68
- for i=1, #list do
69
- copy[i] = list[i]
70
- end
67
+ local copy = table.clone(list)
71
68
 
72
69
  RandomUtils.shuffle(copy, random)
73
70
 
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "node_modules",
3
+ "globIgnorePaths": [ "**/.package-lock.json" ],
4
+ "tree": {
5
+ "$path": { "optional": "../node_modules" }
6
+ }
7
+ }