summaryrefslogtreecommitdiff
path: root/includes/bitset.inc
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-10-10 20:51:39 +0200
committerMinteck <contact@minteck.org>2022-10-10 20:51:39 +0200
commit108525534c28013cfe1897c30e4565f9893f3766 (patch)
treedd3e5132971f96ab5f05e7f3f8f6dbbf379a19bd /includes/bitset.inc
parent2162eaa06f7e4764eb3dcfe130ec2c711d0c62ab (diff)
downloadpluralconnect-108525534c28013cfe1897c30e4565f9893f3766.tar.gz
pluralconnect-108525534c28013cfe1897c30e4565f9893f3766.tar.bz2
pluralconnect-108525534c28013cfe1897c30e4565f9893f3766.zip
Update
Diffstat (limited to 'includes/bitset.inc')
-rw-r--r--includes/bitset.inc110
1 files changed, 110 insertions, 0 deletions
diff --git a/includes/bitset.inc b/includes/bitset.inc
new file mode 100644
index 0000000..1d026e5
--- /dev/null
+++ b/includes/bitset.inc
@@ -0,0 +1,110 @@
+<?php
+
+function parseBitset ($bitset) {
+ $bin = str_repeat("0", 48 - strlen(decbin($bitset))) . decbin($bitset);
+
+ $sharedMemory = bindec(substr($bin, 24, 2));
+ $median = substr($bin, 26, 1) !== "0";
+ $little = bindec(substr($bin, 27, 2));
+ $food = bindec(substr($bin, 16, 2));
+ $nonverbal = substr($bin, 15, 1) !== "0";
+ $lessFrequent = substr($bin, 14, 1) !== "0";
+ $sexuallyActive = substr($bin, 13, 1) !== "0";
+ $ageRegressor = substr($bin, 12, 1) !== "0";
+ $magic = bindec(substr($bin, 18, 3));
+ $sensitivity = bindec(substr($bin, 21, 3));
+ $protector = substr($bin, 29, 1) !== "0";
+ $fictive = substr($bin, 30, 1) !== "0";
+ $notTalking = substr($bin, 31, 1) !== "0";
+ $host = substr($bin, 32, 1) !== "0";
+ $robot = substr($bin, 45, 1) !== "0";
+ $plush = substr($bin, 46, 1) !== "0";
+ $age = substr($bin, 47, 1) !== "0";
+ $species1 = substr($bin, 33, 4);
+ $species2 = substr($bin, 37, 4);
+ $species3 = substr($bin, 41, 4);
+
+ $species1 = match ($species1) {
+ "0001" => "earth",
+ "0010" => "unicorn",
+ "0011" => "pegasus",
+ "0100" => "alicorn",
+ "0101" => "batpony",
+ "0110" => "crystal",
+ default => null,
+ };
+
+ $species2 = match ($species2) {
+ "0001" => "earth",
+ "0010" => "unicorn",
+ "0011" => "pegasus",
+ "0100" => "alicorn",
+ "0101" => "batpony",
+ "0110" => "crystal",
+ default => null,
+ };
+
+ $species3 = match ($species3) {
+ "0001" => "earth",
+ "0010" => "unicorn",
+ "0011" => "pegasus",
+ "0100" => "alicorn",
+ "0101" => "batpony",
+ "0110" => "crystal",
+ default => null,
+ };
+
+ if ($little === 1) {
+ $ageRegressor = true;
+ $little = 0;
+ }
+
+ return [
+ 'shared_memory' => $sharedMemory,
+ 'median' => $median,
+ 'protector' => $protector,
+ 'fictive' => $fictive,
+ 'little' => $little,
+ 'not_talking' => $notTalking,
+ 'host' => $host,
+ 'robot' => $robot,
+ 'magic' => $magic,
+ 'sensitivity' => $sensitivity,
+ 'food' => $food,
+ 'plush' => $plush,
+ 'nonverbal' => $nonverbal,
+ 'less_frequent' => $lessFrequent,
+ 'age_spells' => $age,
+ 'age_regressor' => $ageRegressor,
+ 'sexually_active' => $sexuallyActive,
+ 'species' => array_filter([
+ $species1,
+ $species2,
+ $species3
+ ], function ($i) {
+ return isset($i);
+ })
+ ];
+}
+
+function parseMetadata ($metadata) {
+ if (isset($metadata)) {
+ if ($metadata["bitset"]) {
+ $m = parseBitset($metadata["bitset"]);
+ $m["marefriends"] = $metadata["marefriends"] ?? [];
+ $m["bitset"] = $metadata["bitset"] ?? [];
+ $m["sisters"] = $metadata["sisters"] ?? [];
+ $m["regression"] = $metadata["regression"] ?? null;
+ $m["caretakers"] = $metadata["caretakers"] ?? [];
+ $m["median"] = $metadata["median"] ?? null;
+ $m["birth"] = $metadata["birth"] ?? null;
+ $m["heat"] = $metadata["heat"] ?? null;
+ } else {
+ $m = $metadata;
+ }
+
+ return $m;
+ } else {
+ return $metadata;
+ }
+} \ No newline at end of file