Skip to content

Commit 15b06ce

Browse files
authored
Merge branch 'master' into csg
2 parents e682332 + 5b3b516 commit 15b06ce

File tree

21 files changed

+2633
-62
lines changed

21 files changed

+2633
-62
lines changed

modules.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,17 @@
8686
"remote_execution": {
8787
"tabs": []
8888
},
89+
"wasm": {
90+
"tabs": []
91+
},
92+
"arcade_2d": {
93+
"tabs": [
94+
"ArcadeTwod"
95+
]
96+
},
8997
"physics_2d": {
9098
"tabs": [
9199
"physics_2d"
92100
]
93101
}
94-
}
102+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"console-table-printer": "^2.11.1",
6161
"copyfiles": "^2.4.1",
6262
"cross-env": "^7.0.3",
63-
"esbuild": "0.17.11",
63+
"esbuild": "^0.17.19",
6464
"eslint": "^8.21.0",
6565
"eslint-config-airbnb": "^19.0.4",
6666
"eslint-config-airbnb-typescript": "^17.0.0",

scripts/bin/templates/utilities.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
const snakeCaseRegex = /\b[a-z]+(?:_[a-z]+)*\b/u;
1+
// Snake case regex has been changed from `/\b[a-z]+(?:_[a-z]+)*\b/u` to `/\b[a-z0-9]+(?:_[a-z0-9]+)*\b/u`
2+
// to be consistent with the naming of the `arcade_2d` and `physics_2d` modules.
3+
// This change should not affect other modules, since the set of possible names is only expanded.
4+
const snakeCaseRegex = /\b[a-z0-9]+(?:_[a-z0-9]+)*\b/u;
25
const pascalCaseRegex = /^[A-Z][a-z]+(?:[A-Z][a-z]+)*$/u;
36
export function isSnakeCase(string) {
47
return snakeCaseRegex.test(string);

scripts/src/templates/utilities.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
const snakeCaseRegex = /\b[a-z]+(?:_[a-z]+)*\b/u;
1+
// Snake case regex has been changed from `/\b[a-z]+(?:_[a-z]+)*\b/u` to `/\b[a-z0-9]+(?:_[a-z0-9]+)*\b/u`
2+
// to be consistent with the naming of the `arcade_2d` and `physics_2d` modules.
3+
// This change should not affect other modules, since the set of possible names is only expanded.
4+
const snakeCaseRegex = /\b[a-z0-9]+(?:_[a-z0-9]+)*\b/u;
25
const pascalCaseRegex = /^[A-Z][a-z]+(?:[A-Z][a-z]+)*$/u;
36

47
export function isSnakeCase(string: string) {

src/bundles/arcade_2d/audio.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* This file contains Arcade2D's representation of audio clips and sound.
3+
*/
4+
5+
/**
6+
* Encapsulates the representation of AudioClips.
7+
* AudioClips are unique - there are no AudioClips with the same URL.
8+
*/
9+
export class AudioClip {
10+
private static audioClipCount: number = 0;
11+
// Stores AudioClip index with the URL as a unique key.
12+
private static audioClipsIndexMap: Map<string, number> = new Map<string, number>();
13+
// Stores all the created AudioClips
14+
private static audioClipsArray: Array<AudioClip> = [];
15+
public readonly id: number;
16+
17+
private isUpdated: boolean = false;
18+
private shouldPlay: boolean = false;
19+
private shouldLoop: boolean = false;
20+
21+
private constructor(
22+
private url: string,
23+
private volumeLevel: number,
24+
) {
25+
this.id = AudioClip.audioClipCount++;
26+
AudioClip.audioClipsIndexMap.set(url, this.id);
27+
AudioClip.audioClipsArray.push(this);
28+
}
29+
30+
/**
31+
* Factory method to create new AudioClip if unique URL provided.
32+
* Otherwise returns the previously created AudioClip.
33+
*/
34+
public static of(url: string, volumeLevel: number): AudioClip {
35+
if (url === '') {
36+
throw new Error('AudioClip URL cannot be empty');
37+
}
38+
if (AudioClip.audioClipsIndexMap.has(url)) {
39+
return AudioClip.audioClipsArray[AudioClip.audioClipsIndexMap.get(url) as number];
40+
}
41+
return new AudioClip(url, volumeLevel);
42+
}
43+
public getUrl() {
44+
return this.url;
45+
}
46+
public getVolumeLevel() {
47+
return this.volumeLevel;
48+
}
49+
public shouldAudioClipLoop() {
50+
return this.shouldLoop;
51+
}
52+
public shouldAudioClipPlay() {
53+
return this.shouldPlay;
54+
}
55+
public setShouldAudioClipLoop(loop: boolean) {
56+
if (this.shouldLoop !== loop) {
57+
this.shouldLoop = loop;
58+
this.isUpdated = false;
59+
}
60+
}
61+
/**
62+
* Updates the play/pause state.
63+
* @param play When true, the Audio Clip has a playing state.
64+
*/
65+
public setShouldAudioClipPlay(play: boolean) {
66+
this.shouldPlay = play;
67+
this.isUpdated = false;
68+
}
69+
/**
70+
* Checks if the Audio Clip needs to update. Updates the flag if true.
71+
*/
72+
public hasAudioClipUpdates() {
73+
const prevValue = !this.isUpdated;
74+
this.setAudioClipUpdated();
75+
return prevValue;
76+
}
77+
public setAudioClipUpdated() {
78+
this.isUpdated = true;
79+
}
80+
public static getAudioClipsArray() {
81+
return AudioClip.audioClipsArray;
82+
}
83+
84+
public toReplString = () => '<AudioClip>';
85+
86+
/** @override */
87+
public toString = () => this.toReplString();
88+
}

src/bundles/arcade_2d/constants.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This file contains the default values of the game canvas and GameObjects.
2+
3+
import { type InteractableProps, type RenderProps, type TransformProps } from './types';
4+
5+
// Default values of game
6+
export const DEFAULT_WIDTH: number = 600;
7+
export const DEFAULT_HEIGHT: number = 600;
8+
export const DEFAULT_SCALE: number = 1;
9+
export const DEFAULT_FPS: number = 30;
10+
export const DEFAULT_VOLUME: number = 0.5; // Unused
11+
12+
// Interval of allowed values of game
13+
export const MAX_HEIGHT: number = 1000;
14+
export const MIN_HEIGHT: number = 100;
15+
export const MAX_WIDTH: number = 1000;
16+
export const MIN_WIDTH: number = 100;
17+
export const MAX_SCALE: number = 10;
18+
export const MIN_SCALE: number = 0.1;
19+
export const MAX_FPS: number = 120;
20+
export const MIN_FPS: number = 1;
21+
export const MAX_VOLUME: number = 1;
22+
export const MIN_VOLUME: number = 0;
23+
24+
// A mode where the hitboxes is shown in the canvas for debugging purposes,
25+
// and debug log information
26+
export const DEFAULT_DEBUG_STATE: boolean = false;
27+
28+
// Default values for GameObject properties
29+
export const DEFAULT_TRANSFORM_PROPS: TransformProps = {
30+
position: [0, 0],
31+
scale: [1, 1],
32+
rotation: 0,
33+
};
34+
35+
export const DEFAULT_RENDER_PROPS: RenderProps = {
36+
color: [255, 255, 255, 255],
37+
flip: [false, false],
38+
isVisible: true,
39+
};
40+
41+
export const DEFAULT_INTERACTABLE_PROPS: InteractableProps = {
42+
isHitboxActive: true,
43+
};
44+
45+
// Default values of Phaser scene
46+
export const DEFAULT_PATH_PREFIX: string = 'https://source-academy-assets.s3-ap-southeast-1.amazonaws.com/';

0 commit comments

Comments
 (0)