aboutsummaryrefslogtreecommitdiff
path: root/defaults/src/main/java/shcm/shsupercm/util
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2022-01-21 15:50:24 +0200
committerSHsuperCM <shsupercm@gmail.com>2022-01-21 17:43:35 +0200
commitc48e23a8949eaa89d06908201357b53fa7eaedbe (patch)
treeadd591602e2e2b93b702ed7e5c8e9fb3ea95e091 /defaults/src/main/java/shcm/shsupercm/util
parent897172bde9128da47181a6db6c1ff4885081ba8d (diff)
downloadCITResewn-c48e23a8949eaa89d06908201357b53fa7eaedbe.tar.gz
CITResewn-c48e23a8949eaa89d06908201357b53fa7eaedbe.tar.bz2
CITResewn-c48e23a8949eaa89d06908201357b53fa7eaedbe.zip
Added config/screen for defaults
Diffstat (limited to 'defaults/src/main/java/shcm/shsupercm/util')
-rw-r--r--defaults/src/main/java/shcm/shsupercm/util/logic/Loops.java60
1 files changed, 60 insertions, 0 deletions
diff --git a/defaults/src/main/java/shcm/shsupercm/util/logic/Loops.java b/defaults/src/main/java/shcm/shsupercm/util/logic/Loops.java
new file mode 100644
index 0000000..6c18244
--- /dev/null
+++ b/defaults/src/main/java/shcm/shsupercm/util/logic/Loops.java
@@ -0,0 +1,60 @@
+package shcm.shsupercm.util.logic;
+
+import java.util.*;
+
+/**
+ * This class(or class portion) is a part of SHCM's utilities. Feel free to use without credit.
+ */
+public class Loops {
+ /**
+ * Creates a loop of T with linked intensities allowing for fading between the elements.
+ * @param items list of items and pause durations(in time units) ordered as they are in the loop
+ * @param fade time in units to fade between each item
+ * @param ticks positive raising counter
+ * @param tpu the amount of ticks per time unit
+ * @param <T> element type
+ * @return map of elements and their respective intensities(between 0.0f and 1.0f)
+ */
+ public static <T> Map<T, Float> statelessFadingLoop(List<Map.Entry<T, Float>> items, float fade, int ticks, int tpu) {
+ Map<T, Float> itemValues = new HashMap<>();
+
+ if (items == null || items.size() == 0)
+ return itemValues;
+
+ if (items.size() == 1) {
+ itemValues.put(items.get(0).getKey(), 1f);
+ return itemValues;
+ }
+
+ float totalUnitsInLoop = 0f;
+ for (Map.Entry<T, Float> item : items) {
+ itemValues.put(item.getKey(), 0f);
+ totalUnitsInLoop += item.getValue() + fade;
+ }
+
+ float unitInLoop = (ticks % (tpu * totalUnitsInLoop)) / tpu;
+
+ for (int i = 0; i < items.size(); i++) {
+ Map.Entry<T, Float> item = items.get(i);
+ if (unitInLoop < item.getValue()) {
+ itemValues.put(item.getKey(), 1f);
+ break;
+ } else
+ unitInLoop -= item.getValue();
+
+ if (unitInLoop < fade) {
+ Map.Entry<T, Float> nextItem = items.get(i + 1 >= items.size() ? 0 : i + 1);
+
+ unitInLoop /= fade;
+
+ itemValues.put(item.getKey(), 1f - unitInLoop);
+ itemValues.put(nextItem.getKey(), unitInLoop);
+
+ break;
+ } else
+ unitInLoop -= fade;
+ }
+
+ return itemValues;
+ }
+} \ No newline at end of file