Skip to content

Commit 26645b4

Browse files
committed
Merge branch 'Archipelago' of https://github.com/Z11Coding/Mixtape-Engine-Rework into Archipelago
2 parents 9a973d0 + 633f71f commit 26645b4

23 files changed

+343
-20
lines changed

source/Main.hx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ class Main extends Sprite
125125
Toolkit.theme = 'dark'; // don't be cringe
126126
backend.Cursor.registerHaxeUICursors();
127127

128+
if (cmdArgs.indexOf('check') != -1)
129+
{
130+
// kill any running instances of the game
131+
Sys.command("taskkill /f /im MixEngine.exe");
132+
}
133+
128134
// yutautil.save.MixSaveWrapperBeta.testFunctionSave();
129135

130136
#if LUA_ALLOWED

source/archipelago/APEntryState.hx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package archipelago;
33
import lime.app.Application;
44
import haxe.io.Bytes;
55
import substates.RankingSubstate;
6-
import states.FreeplayState;
76
import yutautil.modules.SyncUtils;
87
import backend.FileDialogHandler;
98
#if sys

source/backend/AudioSwitchFix.hx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package backend;
2+
3+
import lime.media.AudioManager;
4+
import flixel.sound.FlxSound;
5+
import flixel.FlxState;
6+
import backend.util.NativeAPI;
7+
8+
/**
9+
* if youre stealing this keep this comment at least please lol
10+
*
11+
* hi gray itsa me yoshicrafter29 i fixed it hehe
12+
*/
13+
@:dox(hide)
14+
class AudioSwitchFix {
15+
@:noCompletion
16+
private static function onStateSwitch(state:FlxState):Void {
17+
#if windows
18+
if (Main.audioDisconnected) {
19+
20+
var playingList:Array<PlayingSound> = [];
21+
for(e in FlxG.sound.list) {
22+
if (e.playing) {
23+
playingList.push({
24+
sound: e,
25+
time: e.time
26+
});
27+
e.stop();
28+
}
29+
}
30+
if (FlxG.sound.music != null)
31+
FlxG.sound.music.stop();
32+
33+
AudioManager.shutdown();
34+
AudioManager.init();
35+
// #if !lime_doc_gen
36+
// if (AudioManager.context.type == OPENAL)
37+
// {
38+
// var alc = AudioManager.context.openal;
39+
40+
// var device = alc.openDevice();
41+
// var ctx = alc.createContext(device);
42+
// alc.makeContextCurrent(ctx);
43+
// alc.processContext(ctx);
44+
// }
45+
// #end
46+
Main.changeID++;
47+
48+
for(e in playingList) {
49+
e.sound.play(e.time);
50+
}
51+
52+
Main.audioDisconnected = false;
53+
}
54+
#end
55+
}
56+
57+
public static function init() {
58+
#if windows
59+
NativeAPI.registerAudio();
60+
FlxG.signals.preStateCreate.add(onStateSwitch);
61+
#end
62+
}
63+
}
64+
65+
typedef PlayingSound = {
66+
var sound:FlxSound;
67+
var time:Float;
68+
}

source/backend/ClientPrefs.hx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ import states.TitleState;
163163
public var iconBounce:String = 'Mixtape';
164164
public var pauseBPM:Int = 102;
165165
public var aprilFools:Bool = true;
166+
public var freeplayMenu:String = 'Mixtape';
166167
}
167168

168169
class ClientPrefs {

source/backend/ModsHelper.hx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package backend;
2+
3+
import openfl.filters.BitmapFilter;
4+
import flixel.system.FlxSound;
5+
import flixel.util.FlxSort;
6+
import flixel.graphics.FlxGraphic;
7+
import openfl.display.BitmapData;
8+
import haxe.io.Path;
9+
10+
using states.freeplay.basegame.backend.custom.ArrayTools;
11+
12+
class ModsHelper {
13+
public inline static function isModDirEnabled(directory:String) {
14+
return Mods.parseList().enabled.contains(directory);
15+
}
16+
public inline static function loadModDir(directory:String) {
17+
Mods.currentModDirectory = directory;
18+
}
19+
public inline static function getActiveMod():String {
20+
return Mods.currentModDirectory;
21+
}
22+
public static function getModsWithPlayersRegistry():Array<String> {
23+
#if MODS_ALLOWED
24+
return Mods.parseList().enabled.filter(s ->FileSystem.exists(Paths.mods(s)+'/registry/players'));
25+
#else
26+
return [];
27+
#end
28+
}
29+
public inline static function loadabsoluteGraphic(path:String):FlxGraphic {
30+
if(!Paths.currentTrackedAssets.exists(path)) {
31+
Paths.cacheBitmap(path,null,BitmapData.fromFile(path));
32+
}
33+
return Paths.currentTrackedAssets.get(path);
34+
}
35+
public inline static function getSoundChannel(sound:FlxSound){
36+
@:privateAccess
37+
return sound._channel.__audioSource;
38+
}
39+
public inline static function setFiltersOnCam(camera:FlxCamera,value:Array<BitmapFilter>){
40+
camera.filters = value;
41+
camera.filtersEnabled = true;
42+
}
43+
#if sys
44+
public inline static function collectVideos():String{
45+
var dirsToList = new Array<String>();
46+
dirsToList.push('assets/videos/commercials/');
47+
if(FileSystem.exists('mods/videos/commercials'))dirsToList.push('mods/videos/commercials/');
48+
Mods.loadTopMod();
49+
var modsToSearch = Mods.getGlobalMods();
50+
modsToSearch.pushUnique(Mods.currentModDirectory);
51+
modsToSearch = modsToSearch.filter(s -> FileSystem.exists('mods/$s/videos/commercials')).map(s -> 'mods/$s/videos/commercials');
52+
53+
dirsToList = dirsToList.concat(modsToSearch);
54+
var commercialsToSelect = new Array<String>();
55+
for(potencialComercials in dirsToList){
56+
for (file in FileSystem.readDirectory(potencialComercials).filter(s -> s.endsWith(".mp4"))) {
57+
commercialsToSelect.push(potencialComercials + '/'+file);
58+
}
59+
}
60+
return FlxG.random.getObject(commercialsToSelect);
61+
}
62+
#end
63+
}

source/backend/MusicBeatState.hx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ class MusicBeatState extends FlxState
130130

131131
override function update(elapsed:Float)
132132
{
133+
if (Main.audioDisconnected && getState() == PlayState.instance)
134+
{
135+
//Save your progress and THEN reset it (I knew there was a common use for this)
136+
//Doesn't save your exact spot, nor does it save anything but the place of your song, but i can work on that later
137+
PlayState.instance.triggerEvent('Save Song Posititon', null, null);
138+
FlxG.resetState();
139+
}
140+
else if (Main.audioDisconnected) FlxG.resetState();
141+
133142
// everyStep();
134143
var oldStep:Int = curStep;
135144
timePassedOnState += elapsed;

source/backend/Paths.hx

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,27 @@ class Paths
182182
}
183183
}
184184

185+
public static function clearStoredWithoutStickers() {
186+
@:privateAccess
187+
var cache = FlxG.bitmap._cache;
188+
Paths.currentTrackedAssets.clear();
189+
for (key => val in cache){
190+
if( key.toLowerCase().contains("transitionswag") ||
191+
key.contains("bg_graphic_") ||
192+
key == "images/justBf.png"
193+
) Paths.currentTrackedAssets.set(key,val);
194+
else cache.remove(key);
195+
}
196+
Paths.clearStoredMemory();
197+
}
198+
199+
// The "If All Else Fails" option
185200
public static function nukeMemory(){
186201
freeGraphicsFromMemory();
187202
clearUnusedMemory();
188203
clearStoredMemory();
189204
currentTrackedSounds.clear();
205+
backend.util.MemoryUtilBase.collect(true);
190206
}
191207

192208
/** returns a FlxRuntimeShader but with file names lol **/
@@ -967,4 +983,45 @@ class Paths
967983
return false;
968984
return OpenFlAssets.exists(path, AssetType.IMAGE);
969985
}
986+
987+
public static inline function getContent(path:String) {
988+
#if sys
989+
return (FileSystem.exists(path)) ? File.getContent(path) : null;
990+
#else
991+
return (OpenFlAssets.exists(path, TEXT)) ? Assets.getText(path) : null;
992+
#end
993+
}
994+
995+
public static function readDirectory(directory:String):Array<String>
996+
{
997+
#if MODS_ALLOWED
998+
return FileSystem.readDirectory(directory);
999+
#else
1000+
var dirs:Array<String> = [];
1001+
for(dir in Assets.list().filter(folder -> folder.startsWith(directory)))
1002+
{
1003+
@:privateAccess
1004+
for(library in lime.utils.Assets.libraries.keys())
1005+
{
1006+
if(library != 'default' && Assets.exists('$library:$dir') && (!dirs.contains('$library:$dir') || !dirs.contains(dir)))
1007+
dirs.push('$library:$dir');
1008+
else if(Assets.exists(dir) && !dirs.contains(dir))
1009+
dirs.push(dir);
1010+
}
1011+
}
1012+
return dirs;
1013+
#end
1014+
}
1015+
1016+
public inline static function loadabsoluteGraphic(path:String):FlxGraphic {
1017+
if(!Paths.currentTrackedAssets.exists(path)) {
1018+
Paths.cacheBitmap(path,null,BitmapData.fromFile(path));
1019+
}
1020+
return Paths.currentTrackedAssets.get(path);
1021+
}
1022+
1023+
public inline static function getSoundChannel(sound:FlxSound){
1024+
@:privateAccess
1025+
return sound._channel.__audioSource;
1026+
}
9701027
}

source/backend/modules/MemoryGCPlugin.hx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class MemoryGCPlugin extends FlxBasic
2727
var perfStart:Float = TimerUtil.start();
2828
backend.util.MemoryUtilBase.collect(true);
2929
trace('Memory GC took: ${TimerUtil.seconds(perfStart)}');
30+
} else if (FlxG.keys.pressed.SHIFT && FlxG.keys.justPressed.INSERT) {
31+
var perfStart:Float = TimerUtil.start();
32+
Paths.nukeMemory();
33+
trace('Memory GC took: ${TimerUtil.seconds(perfStart)}');
3034
}
3135
}
3236

source/cache/old/CacheState.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ class CacheState extends MusicBeatState
617617
public static var newDest:FlxState;
618618
override function create()
619619
{
620-
Paths.clearStoredMemory();
620+
Paths.clearStoredWithoutStickers();
621621
Main.dumpCache();
622622

623623
#if LUA_ALLOWED

source/options/MixtapeSettingsSubState.hx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ class MixtapeSettingsSubState extends BaseOptionsMenu
9090
LABEL);
9191
addOption(option);
9292

93+
var option:Option = new Option('Freeplay Menu:',
94+
"Which freeplay menu do you prefer?\n(This has no effect on Archipelago Mode)\nDOES NOTHING FOR NOW!",
95+
'freeplayMenu',
96+
STRING,
97+
['Mixtape', 'Base Game']);
98+
addOption(option);
99+
option.displayFormat = '< %v >';
100+
//option.onChange = onChangeFreeplayMenu;
101+
93102
var option:Option = new Option('Menu Music:',
94103
"What song do you prefer for the Main Menu?\n(And like 90% of every other menu as well)",
95104
'menuSong',
@@ -150,6 +159,8 @@ class MixtapeSettingsSubState extends BaseOptionsMenu
150159
super();
151160
}
152161

162+
//function onChangeFreeplayMenu() GlobalFreeplay.setFreeplayMenu(ClientPrefs.data.freeplayMenu);
163+
153164
var changedMusic:Bool = false;
154165
var indeed:Int = 0;
155166
function onChangePauseMusic()

0 commit comments

Comments
 (0)