Skip to content

Commit a2fe455

Browse files
committed
Stuff.
1 parent b8b1047 commit a2fe455

File tree

4 files changed

+195
-4
lines changed

4 files changed

+195
-4
lines changed

source/states/MainMenuState.hx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ class MainMenuState extends MusicBeatState
7878

7979
var yScroll:Float = 0.25;
8080
var bg:FlxSprite = new FlxSprite(-80).loadGraphic(Paths.image('menuBG'));
81+
// Simple rainbow effect for Pride Month
82+
83+
if (yutautil.ExtendedDate.global().isPrideMonth())
84+
{
85+
trace("Happy Pride Month!");
86+
var oldBGColor = bg.color;
87+
var updateRainbowBG:Void->Void;
88+
updateRainbowBG = function() {
89+
var now = Date.now();
90+
var t = now.getSeconds() + (now.getTime() % 1000) / 1000;
91+
bg.color = FlxColor.fromHSB((t * 60) % 360, 1, 1);
92+
if (!yutautil.ExtendedDate.instance.isPrideMonth())
93+
{
94+
bg.color = oldBGColor; // Reset to original color if not Pride Month
95+
FlxG.signals.postUpdate.remove(updateRainbowBG);
96+
}
97+
};
98+
bg.color = FlxColor.fromHSB((Date.now().getSeconds() * 6) % 360, 1, 1);
99+
FlxG.signals.postUpdate.add(updateRainbowBG);
100+
}
81101
bg.antialiasing = ClientPrefs.data.antialiasing;
82102
bg.scrollFactor.set(0, yScroll);
83103
bg.setGraphicSize(Std.int(bg.width * 1.175));

source/yutautil/ExtendedDate.hx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ class ExtendedDate extends FlxBasic {
239239
return this.getMonth() == 10 && this.getDay() == 4 && this.getWeekOfMonth() == 4;
240240
}
241241

242+
public function isPrideMonth():Bool {
243+
// Pride Month is June
244+
return this.getMonth() == 5;
245+
}
246+
242247
public function isBirthday(birthInfo:BirthInfo):Bool {
243248
var todayMonth = this.getMonth();
244249
var todayDay = this.getDate();

source/yutautil/GenericObject.hx

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,67 @@ abstract DefinedField<T>(TypedField<T>) from TypedField<T> to T {
5555

5656
class GenericObject {
5757
private var fields:DynamicAccess<Dynamic>;
58-
public var onFieldSet:FieldCallback = null;
59-
public var onFieldGet:(field:String) -> Void = null;
60-
public var onFieldRemove:(field:String) -> Void = null;
61-
public var onFieldCreate:FieldCallback = null;
58+
// Private backing fields
59+
private var _onFieldSet:FieldCallback = null;
60+
private var _onFieldGet:(field:String) -> Void = null;
61+
private var _onFieldRemove:(field:String) -> Void = null;
62+
private var _onFieldCreate:FieldCallback = null;
63+
64+
// Property for onFieldSet
65+
public var onFieldSet(get, set):FieldCallback;
66+
function get_onFieldSet():FieldCallback return _onFieldSet;
67+
function set_onFieldSet(cb:FieldCallback):FieldCallback {
68+
if (cb == null) {
69+
_onFieldSet = null;
70+
} else {
71+
_onFieldSet = function(field:String, value:Dynamic) {
72+
try cb(field, value) catch (e:Dynamic) {};
73+
}
74+
}
75+
return cb;
76+
}
77+
78+
// Property for onFieldGet
79+
public var onFieldGet(get, set):(field:String) -> Void;
80+
function get_onFieldGet() return _onFieldGet;
81+
function set_onFieldGet(cb:(field:String) -> Void):(field:String) -> Void {
82+
if (cb == null) {
83+
_onFieldGet = null;
84+
} else {
85+
_onFieldGet = function(field:String) {
86+
try cb(field) catch (e:Dynamic) {};
87+
}
88+
}
89+
return cb;
90+
}
91+
92+
// Property for onFieldRemove
93+
public var onFieldRemove(get, set):(field:String) -> Void;
94+
function get_onFieldRemove() return _onFieldRemove;
95+
function set_onFieldRemove(cb:(field:String) -> Void):(field:String) -> Void {
96+
if (cb == null) {
97+
_onFieldRemove = null;
98+
} else {
99+
_onFieldRemove = function(field:String) {
100+
try cb(field) catch (e:Dynamic) {};
101+
}
102+
}
103+
return cb;
104+
}
105+
106+
// Property for onFieldCreate
107+
public var onFieldCreate(get, set):FieldCallback;
108+
function get_onFieldCreate():FieldCallback return _onFieldCreate;
109+
function set_onFieldCreate(cb:FieldCallback):FieldCallback {
110+
if (cb == null) {
111+
_onFieldCreate = null;
112+
} else {
113+
_onFieldCreate = function(field:String, value:Dynamic) {
114+
try cb(field, value) catch (e:Dynamic) {};
115+
}
116+
}
117+
return cb;
118+
}
62119
public var autoRemoveNull:Bool = false;
63120
public var giveNullOnUndefined:Bool = true;
64121
public var allowNullAccess:Bool = true;

source/yutautil/KonamiTracker.hx

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package yutautil;
2+
3+
import flixel.FlxG;
4+
import flixel.input.keyboard.FlxKey;
5+
import flixel.FlxBasic;
6+
7+
typedef CheatCallback = Void->Void;
8+
9+
typedef Cheat = {
10+
var code:Array<FlxKey>;
11+
var callback:CheatCallback;
12+
}
13+
14+
class KonamiTracker extends FlxBasic {
15+
public static final KONAMI_CODE_1:Array<FlxKey> = [
16+
UP, UP, DOWN, DOWN, LEFT, RIGHT, LEFT, RIGHT, B, A
17+
];
18+
public static final KONAMI_CODE_2:Array<FlxKey> = [
19+
UP, UP, DOWN, DOWN, LEFT, RIGHT, LEFT, RIGHT, B, A, ENTER
20+
];
21+
22+
var cheats:Array<Cheat>;
23+
var inputBuffer:Array<FlxKey> = [];
24+
var maxLength:Int = 0;
25+
26+
public function new(?cheatTable:KeyIndexedArray<Array<FlxKey>, CheatCallback>) {
27+
super();
28+
cheats = [];
29+
addCheat(KONAMI_CODE_1, function() {});
30+
addCheat(KONAMI_CODE_2, function() {});
31+
if (cheatTable != null) {
32+
for (entry in cheatTable) {
33+
addCheat(entry.key, entry.value);
34+
}
35+
}
36+
}
37+
38+
public function addCheat(code:Array<FlxKey>, callback:CheatCallback):Void {
39+
cheats.push({ code: code, callback: callback });
40+
if (code.length > maxLength) maxLength = code.length;
41+
}
42+
43+
override public function update(elapsed:Float):Void {
44+
super.update(elapsed);
45+
var pressed:FlxKey = getPressedKey();
46+
if (pressed != null) {
47+
inputBuffer.push(pressed);
48+
if (inputBuffer.length > maxLength)
49+
inputBuffer.shift();
50+
checkCheats();
51+
}
52+
}
53+
54+
function checkCheats():Void {
55+
var matched = false;
56+
for (cheat in cheats) {
57+
if (matches(cheat.code)) {
58+
cheat.callback();
59+
inputBuffer = [];
60+
matched = true;
61+
break;
62+
}
63+
}
64+
if (!matched && !anyPartialMatch()) {
65+
inputBuffer = [];
66+
}
67+
}
68+
69+
function matches(code:Array<FlxKey>):Bool {
70+
if (inputBuffer.length < code.length) return false;
71+
for (i in 0...code.length) {
72+
if (inputBuffer[inputBuffer.length - code.length + i] != code[i])
73+
return false;
74+
}
75+
return true;
76+
}
77+
78+
function anyPartialMatch():Bool {
79+
for (cheat in cheats) {
80+
if (partialMatch(cheat.code)) return true;
81+
}
82+
return false;
83+
}
84+
85+
function partialMatch(code:Array<FlxKey>):Bool {
86+
var len = inputBuffer.length;
87+
if (len == 0 || len > code.length) return false;
88+
for (i in 0...len) {
89+
if (inputBuffer[i] != code[i]) return false;
90+
}
91+
return true;
92+
}
93+
94+
public var allowAllKeys:Bool = false;
95+
96+
function getPressedKey():Null<FlxKey> {
97+
if (allowAllKeys) {
98+
// Check all keys if allowed
99+
for (key in FlxKey.createAll()) {
100+
if (FlxG.keys.justPressed.check(key)) return key;
101+
}
102+
} else {
103+
for (key in [FlxKey.UP, FlxKey.DOWN, FlxKey.LEFT, FlxKey.RIGHT, FlxKey.A, FlxKey.B, FlxKey.C, FlxKey.X, FlxKey.Y, FlxKey.Z, FlxKey.ENTER, FlxKey.SPACE]) {
104+
if (FlxG.keys.justPressed.check(key)) return key;
105+
}
106+
}
107+
return null;
108+
}
109+
}

0 commit comments

Comments
 (0)