Skip to content
This repository was archived by the owner on Nov 13, 2023. It is now read-only.

Commit c729d20

Browse files
Merge branch feature/level-cookies into main (#96)
* Cookie Management started * Implement level cookies - Implement cookie for solving level 1 - Implement cookie for solving level 2 - Implement cookie for solving level 3 - Implement cookie for solving level 4 - Implement usage of cookies in LevelOverview scene - Adapted element classes --------- Co-authored-by: Quadral1403 <[email protected]>
1 parent 1ef1dd6 commit c729d20

File tree

11 files changed

+233
-78
lines changed

11 files changed

+233
-78
lines changed

src/ts/engine/scene/element.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,31 @@ class Element extends Rectangle {
1212
return this._background;
1313
}
1414

15-
protected set background(value: string | CanvasGradient | CanvasPattern) {
15+
public set background(value: string | CanvasGradient | CanvasPattern) {
1616
this._background = value;
1717
}
1818

1919
public get border(): string | CanvasGradient | CanvasPattern {
2020
return this._border;
2121
}
2222

23-
protected set border(value: string | CanvasGradient | CanvasPattern) {
23+
public set border(value: string | CanvasGradient | CanvasPattern) {
2424
this._border = value;
2525
}
2626

2727
public get borderSize(): number {
2828
return this._borderSize;
2929
}
3030

31-
protected set borderSize(value: number) {
31+
public set borderSize(value: number) {
3232
this._borderSize = value;
3333
}
3434

3535
public get visible(): boolean {
3636
return this._visible;
3737
}
3838

39-
protected set visible(value: boolean) {
39+
public set visible(value: boolean) {
4040
this._visible = value;
4141
}
4242

src/ts/engine/scene/elements/button.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Button extends Label {
1919
return this._backgroundUnhovered;
2020
}
2121

22-
protected set backgroundUnhovered(
22+
public set backgroundUnhovered(
2323
value: string | CanvasGradient | CanvasPattern
2424
) {
2525
this._backgroundUnhovered = value;
@@ -29,17 +29,15 @@ class Button extends Label {
2929
return this._backgroundHover;
3030
}
3131

32-
protected set backgroundHover(
33-
value: string | CanvasGradient | CanvasPattern
34-
) {
32+
public set backgroundHover(value: string | CanvasGradient | CanvasPattern) {
3533
this._backgroundHover = value;
3634
}
3735

3836
public get foregroundUnhovered(): string | CanvasGradient | CanvasPattern {
3937
return this._foregroundUnhovered;
4038
}
4139

42-
protected set foregroundUnhovered(
40+
public set foregroundUnhovered(
4341
value: string | CanvasGradient | CanvasPattern
4442
) {
4543
this._foregroundUnhovered = value;
@@ -49,27 +47,23 @@ class Button extends Label {
4947
return this._foregroundHover;
5048
}
5149

52-
protected set foregroundHover(
53-
value: string | CanvasGradient | CanvasPattern
54-
) {
50+
public set foregroundHover(value: string | CanvasGradient | CanvasPattern) {
5551
this._foregroundHover = value;
5652
}
5753

5854
public get borderUnhovered(): string | CanvasGradient | CanvasPattern {
5955
return this._borderUnhovered;
6056
}
6157

62-
protected set borderUnhovered(
63-
value: string | CanvasGradient | CanvasPattern
64-
) {
58+
public set borderUnhovered(value: string | CanvasGradient | CanvasPattern) {
6559
this._borderUnhovered = value;
6660
}
6761

6862
public get borderHover(): string | CanvasGradient | CanvasPattern {
6963
return this._borderHover;
7064
}
7165

72-
protected set borderHover(value: string | CanvasGradient | CanvasPattern) {
66+
public set borderHover(value: string | CanvasGradient | CanvasPattern) {
7367
this._borderHover = value;
7468
}
7569

src/ts/engine/scene/elements/checkbox.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CheckBox extends Button {
3535
return this._checked;
3636
}
3737

38-
protected set checked(value: boolean) {
38+
public set checked(value: boolean) {
3939
this._checked = value;
4040
}
4141

@@ -46,7 +46,7 @@ class CheckBox extends Button {
4646
return this._backgroundUnhoveredUnchecked;
4747
}
4848

49-
protected set backgroundUnhoveredUnchecked(
49+
public set backgroundUnhoveredUnchecked(
5050
value: string | CanvasGradient | CanvasPattern
5151
) {
5252
this._backgroundUnhoveredUnchecked = value;
@@ -59,7 +59,7 @@ class CheckBox extends Button {
5959
return this._backgroundUnhoveredChecked;
6060
}
6161

62-
protected set backgroundUnhoveredChecked(
62+
public set backgroundUnhoveredChecked(
6363
value: string | CanvasGradient | CanvasPattern
6464
) {
6565
this._backgroundUnhoveredChecked = value;
@@ -72,7 +72,7 @@ class CheckBox extends Button {
7272
return this._backgroundHoverUnchecked;
7373
}
7474

75-
protected set backgroundHoverUnchecked(
75+
public set backgroundHoverUnchecked(
7676
value: string | CanvasGradient | CanvasPattern
7777
) {
7878
this._backgroundHoverUnchecked = value;
@@ -82,7 +82,7 @@ class CheckBox extends Button {
8282
return this._backgroundHoverChecked;
8383
}
8484

85-
protected set backgroundHoverChecked(
85+
public set backgroundHoverChecked(
8686
value: string | CanvasGradient | CanvasPattern
8787
) {
8888
this._backgroundHoverChecked = value;
@@ -95,7 +95,7 @@ class CheckBox extends Button {
9595
return this._foregroundUnhoveredUnchecked;
9696
}
9797

98-
protected set foregroundUnhoveredUnchecked(
98+
public set foregroundUnhoveredUnchecked(
9999
value: string | CanvasGradient | CanvasPattern
100100
) {
101101
this._foregroundUnhoveredUnchecked = value;
@@ -108,7 +108,7 @@ class CheckBox extends Button {
108108
return this._foregroundUnhoveredChecked;
109109
}
110110

111-
protected set foregroundUnhoveredChecked(
111+
public set foregroundUnhoveredChecked(
112112
value: string | CanvasGradient | CanvasPattern
113113
) {
114114
this._foregroundUnhoveredChecked = value;
@@ -121,7 +121,7 @@ class CheckBox extends Button {
121121
return this._foregroundHoverUnchecked;
122122
}
123123

124-
protected set foregroundHoverUnchecked(
124+
public set foregroundHoverUnchecked(
125125
value: string | CanvasGradient | CanvasPattern
126126
) {
127127
this._foregroundHoverUnchecked = value;
@@ -131,7 +131,7 @@ class CheckBox extends Button {
131131
return this._foregroundHoverChecked;
132132
}
133133

134-
protected set foregroundHoverChecked(
134+
public set foregroundHoverChecked(
135135
value: string | CanvasGradient | CanvasPattern
136136
) {
137137
this._foregroundHoverChecked = value;
@@ -144,7 +144,7 @@ class CheckBox extends Button {
144144
return this._borderUnhoveredUnchecked;
145145
}
146146

147-
protected set borderUnhoveredUnchecked(
147+
public set borderUnhoveredUnchecked(
148148
value: string | CanvasGradient | CanvasPattern
149149
) {
150150
this._borderUnhoveredUnchecked = value;
@@ -154,7 +154,7 @@ class CheckBox extends Button {
154154
return this._borderUnhoveredChecked;
155155
}
156156

157-
protected set borderUnhoveredChecked(
157+
public set borderUnhoveredChecked(
158158
value: string | CanvasGradient | CanvasPattern
159159
) {
160160
this._borderUnhoveredChecked = value;
@@ -164,7 +164,7 @@ class CheckBox extends Button {
164164
return this._borderHoverUnchecked;
165165
}
166166

167-
protected set borderHoverUnchecked(
167+
public set borderHoverUnchecked(
168168
value: string | CanvasGradient | CanvasPattern
169169
) {
170170
this._borderHoverUnchecked = value;
@@ -174,7 +174,7 @@ class CheckBox extends Button {
174174
return this._borderHoverChecked;
175175
}
176176

177-
protected set borderHoverChecked(
177+
public set borderHoverChecked(
178178
value: string | CanvasGradient | CanvasPattern
179179
) {
180180
this._borderHoverChecked = value;
@@ -184,15 +184,15 @@ class CheckBox extends Button {
184184
return this._textUnchecked;
185185
}
186186

187-
protected set textUnchecked(value: string) {
187+
public set textUnchecked(value: string) {
188188
this._textUnchecked = value;
189189
}
190190

191191
public get textChecked(): string {
192192
return this._textChecked;
193193
}
194194

195-
protected set textChecked(value: string) {
195+
public set textChecked(value: string) {
196196
this._textChecked = value;
197197
}
198198

src/ts/engine/scene/elements/label.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,39 @@ class Label extends Element {
1111
return this._foreground;
1212
}
1313

14-
protected set foreground(value: string | CanvasGradient | CanvasPattern) {
14+
public set foreground(value: string | CanvasGradient | CanvasPattern) {
1515
this._foreground = value;
1616
}
1717

1818
public get font(): string {
1919
return this._font;
2020
}
2121

22-
protected set font(value: string) {
22+
public set font(value: string) {
2323
this._font = value;
2424
}
2525

2626
public get textAlign(): CanvasTextAlign {
2727
return this._textAlign;
2828
}
2929

30-
protected set textAlign(value: CanvasTextAlign) {
30+
public set textAlign(value: CanvasTextAlign) {
3131
this._textAlign = value;
3232
}
3333

3434
public get textBaseline(): CanvasTextBaseline {
3535
return this._textBaseline;
3636
}
3737

38-
protected set textBaseline(value: CanvasTextBaseline) {
38+
public set textBaseline(value: CanvasTextBaseline) {
3939
this._textBaseline = value;
4040
}
4141

4242
public get text(): string {
4343
return this._text;
4444
}
4545

46-
protected set text(value: string) {
46+
public set text(value: string) {
4747
this._text = value;
4848
}
4949

src/ts/engine/settings/simplesetting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Setting from "./setting";
1+
import Setting from "./setting.js";
22

33
class SimpleSetting<T> extends Setting<T> {
44
private _value: T;

src/ts/engine/time/dateutils.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
function addYears(date: Date, years: number): Date {
2+
const newDate = new Date(date);
3+
newDate.setFullYear(newDate.getFullYear() + years);
4+
return newDate;
5+
}
6+
7+
function addMonths(date: Date, months: number): Date {
8+
const newDate = new Date(date);
9+
newDate.setMonth(newDate.getMonth() + months);
10+
return newDate;
11+
}
12+
13+
function addDays(date: Date, days: number): Date {
14+
const newDate = new Date(date);
15+
newDate.setDate(newDate.getDate() + days);
16+
return newDate;
17+
}
18+
19+
function addHours(date: Date, hours: number): Date {
20+
const newDate = new Date(date);
21+
newDate.setHours(newDate.getHours() + hours);
22+
return newDate;
23+
}
24+
25+
function addMinutes(date: Date, minutes: number): Date {
26+
const newDate = new Date(date);
27+
newDate.setMinutes(newDate.getMinutes() + minutes);
28+
return newDate;
29+
}
30+
31+
function addSeconds(date: Date, seconds: number): Date {
32+
const newDate = new Date(date);
33+
newDate.setSeconds(newDate.getSeconds() + seconds);
34+
return newDate;
35+
}
36+
37+
function addMilliseconds(date: Date, milliseconds: number): Date {
38+
const newDate = new Date(date);
39+
newDate.setMilliseconds(newDate.getMilliseconds() + milliseconds);
40+
return newDate;
41+
}
42+
43+
export {
44+
addYears,
45+
addMonths,
46+
addDays,
47+
addHours,
48+
addMinutes,
49+
addSeconds,
50+
addMilliseconds,
51+
};

src/ts/game/levels/level1.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ import PortalType from "../entities/portaltype.js";
2222
import Vector2D from "../../engine/math/vector2d.js";
2323
import LevelManager from "../../engine/level/levelmanager.js";
2424
import SceneManager from "../../engine/scene/scenemanager.js";
25+
import CookieManager from "../../engine/cookies/cookiemanager.js";
26+
import Cookie from "../../engine/cookies/cookie.js";
27+
import { addYears } from "../../engine/time/dateutils.js";
2528

2629
class Level1 implements Level {
2730
private _entityManager: EntityManager;
2831
private _assetManager: AssetManager;
32+
private _cookieManager: CookieManager;
2933

3034
private _buttonGround!: ButtonGround;
3135
private _buttonStanding!: ButtonStanding;
@@ -37,6 +41,7 @@ class Level1 implements Level {
3741
constructor() {
3842
this._entityManager = Services.resolve<EntityManager>("EntityManager");
3943
this._assetManager = Services.resolve<AssetManager>("AssetManager");
44+
this._cookieManager = Services.resolve<CookieManager>("CookieManager");
4045
}
4146

4247
public getEntities(): Entity[] {
@@ -176,6 +181,12 @@ class Level1 implements Level {
176181
);
177182

178183
this._goal.onTouch.subscribe((engineEvent: EngineEvent<Goal>) => {
184+
this._cookieManager.set(
185+
"level1.solved",
186+
new Cookie("true", addYears(new Date(), 1), "Strict", false)
187+
);
188+
this._cookieManager.save();
189+
179190
Services.resolve<SceneManager>("SceneManager").switch("level2Scene");
180191
let levelManager: LevelManager =
181192
Services.resolve<LevelManager>("LevelManager");

0 commit comments

Comments
 (0)