Skip to content

Commit

Permalink
change kinklist from { [k: string]: kink[] } to [string, kink[]][]
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelcmtd committed Jul 16, 2024
1 parent 64462cd commit 8c68365
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 57 deletions.
53 changes: 25 additions & 28 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ export const ratings: [string, string][] = [

export type positions = [string, string] | [""];
export type kink = [string, positions, number] | [string, positions, number, string];
export type kinklist = { [k: string]: kink[] };
export type kinklist = [string, kink[]][];
export type template_revision = { kinks: kinklist };

export const kinks: kinklist = {
"General": [
export const kinks: kinklist = [
["General", [
["Fellatio/Blowjobs", ["receive", "give"], 0],
["Cunnilingus", ["receive", "give"], 1, "giver licks receiver's vagina"],
["Face-Fucking", ["give", "receive"], 2],
["Face-Sitting", ["top", "bottom"], 3, "top sits on bottom's face"],
["Handjobs", ["give", "receive"], 4],
["Vaginal Penetration", ["top", "bottom"], 98],
["Vaginal Penetration", ["top", "bottom"], 97],
["Vaginal Fingering", ["give", "receive"], 5],
["Vaginal Fisting", ["give", "receive"], 6],
["Rough Sex", [""], 7],
Expand All @@ -32,8 +32,8 @@ export const kinks: kinklist = {
["Anal Fisting", ["top", "bottom"], 14],
["Pegging", ["top", "bottom"], 15, "top anally penetrates bottom with a strap-on"],
["Anilingus/Rimming", ["receive", "give"], 16, "bottom licks top's asshole"],
],
"BDSM": [
]],
["BDSM", [
["Little/Daddy*Mommy", ["dom", "sub"], 17],
["Slave/Master*Mistress", ["dom", "sub"], 18],
["Pet/Owner", ["dom", "sub"], 19],
Expand All @@ -60,8 +60,8 @@ export const kinks: kinklist = {
["Teasing", ["dom", "sub"], 42],
["Sounding/Urethral Insertion", ["dom", "sub"], 43],
["Worship", ["dom", "sub"], 44],
],
"Kinks": [
]],
["Kinks", [
["Incest", ["cousins", "siblings"], 45],
["Incest (any age)", ["parents", "children"], 46],
["Impregnation/Pregnancy", ["top", "bottom"], 47],
Expand All @@ -83,8 +83,8 @@ export const kinks: kinklist = {
["Titfuck", ["top", "bottom"], 62],
["Footjob", ["give", "receive"], 63],
["Armpit Sex", ["top", "bottom"], 64],
],
"Pain": [
]],
["Pain", [
["Physical Pain", ["give", "receive"], 65],
["Nipple Clamps", ["give", "receive"], 66],
["Hard Spanking", ["give", "receive"], 67],
Expand All @@ -97,8 +97,8 @@ export const kinks: kinklist = {
["Vagina Slapping", ["give", "receive"], 74],
["Clothespins", ["give", "receive"], 75],
["Needles", ["give", "receive"], 76],
],
"Clothing": [
]],
["Clothing", [
["Clothed Sex", [""], 77],
["Collars", ["dom", "sub"], 78, "sub wears a collar, which might have a leash for dom to pull on"],
["Latex", [""], 79],
Expand All @@ -111,8 +111,8 @@ export const kinks: kinklist = {
["Uniforms", [""], 86],
["Cosplay", [""], 87],
["Furry", [""], 88],
],
"Extreme": [
]],
["Extreme", [
["Scat", [""], 89],
["Cutting", ["give", "receive"], 90],
["Raceplay", ["dom", "sub"], 91],
Expand All @@ -123,18 +123,14 @@ export const kinks: kinklist = {
["Cannibalism", ["dom", "sub"], 95],
["Torture", ["dom", "sub"], 20],
["Genital Mutilation", ["give", "receive"], 21],
],
};
]],
];

const valueForAllKinks = <T>(kinks: kinklist, x: T) => Object.fromEntries(
Object.entries(kinks).map<[string, T[][]]>(
([cat, kinks]) => [cat, kinks.map((k) => k[1].map(() => x))])
);
const valueForAllKinks = <T>(kinks: kinklist, x: T) =>
kinks.map<T[][]>((c) => c[1].map((k) => k[1].map(() => x)));

export type ratings = { [k: string]: number[][] };
export type ratings = number[][][];
export const defaultRatings = (kinks: kinklist): ratings => valueForAllKinks(kinks, 0);
export type checklist = { [k: string]: boolean[][] };
export const defaultChecklist = (kinks: kinklist): checklist => valueForAllKinks(kinks, false);
export type kinkcheck = { ratings: ratings };
export const defaultKinkcheck = (kinks: kinklist): kinkcheck => ({ ratings: defaultRatings(kinks) });

Expand All @@ -146,17 +142,18 @@ function packIndexedValues<T>(indexedValues: [number, T][]): T[] {
}

export function encodeKinkCheck({ kinks }: { kinks: kinklist }, { ratings }: kinkcheck): string {
const r = packIndexedValues(Object.entries(ratings)
.flatMap(([cat, rats]) => kinks[cat].map<[number, number[]]>(([, , id], i) => [id, rats[i]])));
const r = packIndexedValues(ratings.flatMap((_, cat) =>
kinks[cat][1].map<[number, number[]]>(([, , id], i) => [id, ratings[cat][i]])));
return JSON.stringify({ ratings: r });
}

export function decodeKinkCheck({ kinks }: { kinks: kinklist }, s: string): kinkcheck {
const ratings = defaultRatings(kinks);
JSON.parse(s).ratings.forEach((rat: number[], id: number) => {
Object.keys(ratings).forEach((cat) => {
JSON.parse(s).ratings.forEach((rat: number[] | undefined, id: number) => {
if (!rat) return;
ratings.forEach((_, cat) => {
ratings[cat].forEach((_, i) => {
if (kinks[cat][i][2] === id) {
if (kinks[cat][1][i][2] === id) {
ratings[cat][i] = rat;
}
});
Expand Down
13 changes: 5 additions & 8 deletions src/components/KinkCheck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,17 @@ export function Category({ cat, kinks, ratings, setRating }: {

export default function KinkCheck(meta: template_revision) {
const [ratings, setRatings] = useState(defaultRatings(meta.kinks));
const setRating = (cat: string) => (kink: number) => (pos: number) => (rat: number) => {
const c = ratings[cat];
const p = c[kink];
p[pos] = rat;
c[kink] = p;
const r = { ...ratings, [cat]: c };
const setRating = (cat: number) => (kink: number) => (pos: number) => (rat: number) => {
const r = [...ratings!];
r[cat][kink][pos] = rat;
setRatings(r);
console.log(encodeKinkCheck(meta, { ratings: r }));
};
// TODO: add a name field
return <main class={styles.catcontainer}>
{
Object.entries(meta.kinks).map(([cat, kinks]) => (
<Category cat={cat} kinks={kinks} ratings={ratings[cat]} setRating={setRating(cat)} />
meta.kinks.map(([cat, kinks], i) => (
<Category cat={cat} kinks={kinks} ratings={ratings[i]} setRating={setRating(i)} />
))
}
</main>;
Expand Down
12 changes: 5 additions & 7 deletions src/components/Matcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ function matchRating(a: number, b: number): number {
}

export function match(a: ratings, b: ratings): ratings {
if (!Object.keys(a).every((k) => Object.keys(b).includes(k))) throw "incompatible ratings";
return Object.fromEntries(Object.entries(a).map(
([cat, rA]) => [cat, rA.map((rsA, kink) => rsA.map((ratA, pos) => matchRating(ratA, b[cat][kink][pos])))]
));
// if (!Object.keys(a).every((k) => Object.keys(b).includes(k))) throw "incompatible ratings";
return a.map((rA, cat) => rA.map((rsA, kink) => rsA.map((ratA, pos) => matchRating(ratA, b[cat][kink][pos]))));
}

export default function Matcher(meta: template_revision) {
Expand All @@ -25,7 +23,7 @@ export default function Matcher(meta: template_revision) {
let errorA, errorB;
try { kcA = decodeKinkCheck(meta, partnerA.trim()); } catch(e: any) { errorA = e.toString(); }
try { kcB = decodeKinkCheck(meta, partnerB.trim()); } catch(e: any) { errorB = e.toString(); }
kcB.ratings = Object.fromEntries(Object.entries(kcB.ratings).map(([k, r]) => [k, r.map(rs => rs.toReversed())]));
kcB.ratings = kcB.ratings.map(ks => ks.map(rs => rs.toReversed()));
const matched = match(kcA.ratings, kcB.ratings);
return <main>
<div class={styles.matcherfrontmatter + " " + kc.catcontainer}>
Expand All @@ -35,8 +33,8 @@ export default function Matcher(meta: template_revision) {
</div>
<div class={kc.catcontainer}>
{
Object.entries(kinks).map(([cat, kinks]) => (
<Category cat={cat} kinks={kinks} ratings={matched[cat]} />
kinks.map(([cat, kinks], i) => (
<Category cat={cat} kinks={kinks} ratings={matched[i]} />
))
}
</div>
Expand Down
28 changes: 14 additions & 14 deletions test/serialization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@ import { expect, test } from "vitest";
import { decodeKinkCheck, encodeKinkCheck, type kinklist } from "../src/base";

const exampleMeta1 = {
kinks: {
"Category 1": [
kinks: [
["Category 1", [
["Kink A", ["top", "bottom"], 0],
["Kink B", ["dom", "sub"], 1],
],
"Category 2": [
]],
["Category 2", [
["Kink C", [""], 2],
],
} as kinklist,
]],
] as kinklist,
};

const exampleMeta2 = {
kinks: {
"Category 1": [
kinks: [
["Category 1", [
["Kink B", ["give", "receive"], 1],
],
"Category 2": [
]],
["Category 2", [
["Kink C", [""], 2],
],
"Category 3": [
]],
["Category 3", [
["Kink A'", ["top", "bottom"], 0],
],
} as kinklist,
]],
] as kinklist,
};

const exampleCheck = { ratings: [[1, 2], [3, 4], [1.5]] };
Expand Down

0 comments on commit 8c68365

Please sign in to comment.