Skip to content

Commit c5e4f0f

Browse files
committed
feat: now versions doesn't lie
1 parent 99f078d commit c5e4f0f

File tree

8 files changed

+223
-103
lines changed

8 files changed

+223
-103
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Format: Major.Minor.Patch (D/M/Y)
44

5+
## [2.1.0] - 2025-01-15
6+
7+
### Changed
8+
9+
- Now version selector doesn't lie about the version!
10+
511
## 2.0.1 (3/11/2024)
612

713
- Renamed examples to demos

kaplay

scripts/examples.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33

44
import fs from "fs";
55
import path from "path";
6+
import type { Packument } from "query-registry";
7+
8+
async function getPackageInfo(name: string): Promise<Packument> {
9+
const endpoint = `https://registry.npmjs.org/${name}`;
10+
const res = await fetch(endpoint);
11+
const data = await res.json();
12+
return data;
13+
}
614

715
const defaultExamplesPath = path.join(
816
import.meta.dirname,
@@ -13,6 +21,11 @@ const defaultExamplesPath = path.join(
1321
const distPath = path.join(import.meta.dirname, "..", "src", "data");
1422

1523
export const generateExamples = async (examplesPath = defaultExamplesPath) => {
24+
const defaultVersion = Object.keys(
25+
(await getPackageInfo("kaplay")).versions,
26+
).reverse().find((v) => {
27+
return v.startsWith("3001");
28+
});
1629
let exampleCount = 0;
1730

1831
const examples = fs.readdirSync(examplesPath).map((file) => {
@@ -22,7 +35,12 @@ export const generateExamples = async (examplesPath = defaultExamplesPath) => {
2235
const code = fs.readFileSync(filePath, "utf-8");
2336
const name = file.replace(".js", "");
2437

25-
return { name, code, index: (exampleCount++).toString() };
38+
return {
39+
name,
40+
code,
41+
index: (exampleCount++).toString(),
42+
version: defaultVersion,
43+
};
2644
});
2745

2846
// Write a JSON file with the examples

src/components/Config/ConfigProject.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ export const ConfigProject = () => {
3737
<select
3838
id="version-selector"
3939
className="select select-bordered"
40+
defaultValue={"none"}
4041
>
42+
<option disabled value={"none"}>
43+
Select a version
44+
</option>
4145
{packageInfo
4246
&& Object.keys(packageInfo.versions).reverse().map((
4347
version,

src/config/common.ts

-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ export const VERSION = packageJson.version;
44
export const CHANGELOG =
55
"https://github.com/lajbel/kaplayground/blob/master/CHANGELOG.md";
66
export const REPO = "https://github.com/kaplayjs/kaplayground";
7-
export const DEFAULT_KAPLAY_VERSION = "3001.0.2";

src/data/exampleList.json

+178-89
Large diffs are not rendered by default.

src/data/examples.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { DEFAULT_KAPLAY_VERSION } from "../config/common";
21
import examplesList from "./exampleList.json";
32

43
export type Tag =
@@ -375,14 +374,16 @@ export const examplesMetaData: Record<string, Partial<Example>> = {
375374
},
376375
"platformBox": {
377376
formatedName: "Odd Uses of platformEffector()",
378-
description: "How to allow the player to decide whether they want to push something.",
377+
description:
378+
"How to allow the player to decide whether they want to push something.",
379379
tags: ["physics"],
380380
difficulty: "medium",
381381
version: VERSION_4000,
382382
},
383383
"platformEffector": {
384384
formatedName: "Jump-Through Platforms",
385-
description: "How to make platforms that the player can jump through going up and down at will.",
385+
description:
386+
"How to make platforms that the player can jump through going up and down at will.",
386387
tags: ["physics"],
387388
difficulty: "medium",
388389
version: VERSION_4000,
@@ -440,13 +441,15 @@ export const examplesMetaData: Record<string, Partial<Example>> = {
440441
},
441442
"raycastObject": {
442443
formatedName: "Raycasts objects",
443-
description: "How to shoot a raycast and make it bounce off the bounding boxes of objects.",
444+
description:
445+
"How to shoot a raycast and make it bounce off the bounding boxes of objects.",
444446
tags: ["math"],
445447
difficulty: "medium",
446448
},
447449
"raycastShape": {
448450
formatedName: "Raycasts shapes",
449-
description: "How to shoot a raycast and make it bounce off the actual shapes of objects.",
451+
description:
452+
"How to shoot a raycast and make it bounce off the actual shapes of objects.",
450453
tags: ["math"],
451454
difficulty: "medium",
452455
},
@@ -562,7 +565,8 @@ export const examplesMetaData: Record<string, Partial<Example>> = {
562565
},
563566
"weirdTextTags": {
564567
formatedName: "Weird text tags",
565-
description: "How to insert text with brackets without messing up formatting.",
568+
description:
569+
"How to insert text with brackets without messing up formatting.",
566570
tags: ["testing"],
567571
difficulty: "easy",
568572
},
@@ -579,6 +583,6 @@ export const examples = examplesList.filter((example) =>
579583
tags: examplesMetaData[example.name]?.tags ?? [],
580584
difficulty: examplesMetaData[example.name]?.difficulty ?? "medium",
581585
version: examplesMetaData[example.name]?.version
582-
?? DEFAULT_KAPLAY_VERSION,
586+
?? example.version,
583587
};
584588
});

src/stores/project.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { KAPLAYOpt } from "kaplay";
22
import { toast } from "react-toastify";
33
import type { StateCreator } from "zustand";
4-
import { DEFAULT_KAPLAY_VERSION } from "../config/common";
54
import { defaultExampleFile, defaultProject } from "../config/defaultProject";
5+
import examplesList from "../data/exampleList.json";
66
import { examples } from "../data/examples";
77
import { useConfig } from "../hooks/useConfig";
88
import { useEditor } from "../hooks/useEditor";
@@ -56,7 +56,7 @@ export const createProjectSlice: StateCreator<
5656
assets: new Map(),
5757
kaplayConfig: {},
5858
mode: "pj",
59-
kaplayVersion: DEFAULT_KAPLAY_VERSION,
59+
kaplayVersion: examplesList[0].version,
6060
id: `upj-Untitled`,
6161
},
6262
getProject: () => {
@@ -75,7 +75,7 @@ export const createProjectSlice: StateCreator<
7575
const assets = new Map<string, Asset>();
7676
const lastVersion = get().project.kaplayVersion;
7777

78-
let version = DEFAULT_KAPLAY_VERSION;
78+
let version = examplesList[0].version;
7979
let id = `u${filter}-Untitled`;
8080

8181
if (filter === "pj") {
@@ -252,7 +252,7 @@ export const createProjectSlice: StateCreator<
252252
mode: "ex",
253253
id: "ex-shared",
254254
kaplayConfig: {},
255-
kaplayVersion: DEFAULT_KAPLAY_VERSION,
255+
kaplayVersion: examplesList[0].version,
256256
name: "Shared Example",
257257
version: "2.0.0",
258258
isDefault: false,

0 commit comments

Comments
 (0)