Skip to content

Commit c20136c

Browse files
authored
Merge pull request corecathx#12 from MobilePorting/master
2 parents 660e228 + 70c1aba commit c20136c

File tree

8 files changed

+125
-6
lines changed

8 files changed

+125
-6
lines changed

Project.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
<!--CDEV Engine's define names-->
5252
<define name="ALLOW_MODS"/><!-- if="desktop"-->
53-
<define name="CRASH_HANDLER" if="windows || android"/>
53+
<define name="CRASH_HANDLER" if="windows || mobile"/>
5454
<define name="USE_VIDEOS" if="cpp"/>
5555
<define name="DARK_MODE_WINDOW"/>
5656

@@ -112,7 +112,7 @@
112112
<assets path='example_mods' rename='cdev-mods' embed='false' if="desktop"/>
113113

114114
<assets path='crash_handler/cdev-crash_handler.exe' rename='cdev-crash_handler.exe' embed='false' if="windows"/>
115-
<assets path='art/readme.txt' rename='do NOT readme.txt' />
115+
<assets path='art/readme.txt' rename='do NOT readme.txt' unless="mobile" />
116116

117117
<!-- NOTE FOR FUTURE SELF SINCE FONTS ARE ALWAYS FUCKY
118118
TO FIX ONE OF THEM, I CONVERTED IT TO OTF. DUNNO IF YOU NEED TO

source/game/cdev/CDevConfig.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class CDevConfig
4949
{
5050
#if windows
5151
savePath = Sys.getEnv("AppData") + saveFolder;
52-
#else #if android
52+
#else #if mobile
5353
savePath = Path.normalize(Sys.getCwd()+saveFolder);
5454
#end #end
5555

source/game/system/FunkinMain.hx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import game.cdev.engineutils.CDevInfoTxt;
77
import flixel.input.android.FlxAndroidKey;
88
import android.content.Context;
99
import game.system.native.Android;
10+
#elseif ios
11+
import game.system.native.IOS;
1012
#end
1113

1214
import haxe.io.Path;
@@ -82,6 +84,8 @@ class FunkinMain extends Sprite
8284
#if android
8385
Sys.setCwd(Path.addTrailingSlash(Context.getExternalFilesDir()));
8486
Application.current.window.alert("We detected that CDEV Engine is running on Android target, expect things to crash & unstable.", "Warning");
87+
#elseif ios
88+
Sys.setCwd(LimeSystem.documentsDirectory);
8589
#end
8690

8791
if (stage != null)
@@ -245,6 +249,8 @@ class FunkinMain extends Sprite
245249
else
246250
#elseif android
247251
Android.onCrash(reportClassic, "CDEV-Engine_" + dateNow + ".txt");
252+
#elseif ios
253+
IOS.onCrash(reportClassic, "CDEV-Engine_" + dateNow + ".txt");
248254
#end
249255
{
250256
// gotta call a simple message box thingie

source/game/system/native/Android.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import android.widget.Toast;
1111
#end
1212
import flash.system.System;
1313
import openfl.Lib;
14-
#if (sys && !ios)
14+
#if sys
1515
import sys.FileSystem;
1616
import sys.io.File;
1717
#end

source/game/system/native/IOS.hx

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package game.system.native;
2+
3+
import flash.system.System;
4+
import openfl.Lib;
5+
import flixel.input.touch.FlxTouch;
6+
#if sys
7+
import sys.FileSystem;
8+
import sys.io.File;
9+
#end
10+
11+
class IOS
12+
{
13+
public static function initialize()
14+
{
15+
#if ios
16+
var foldersToCreate:Array<String> = ["cdev-mods", "crash", "savedata"];
17+
if (!FileSystem.exists(Sys.getCwd()))
18+
FileSystem.createDirectory(Sys.getCwd());
19+
20+
for (flr in foldersToCreate)
21+
{
22+
var intendedPath:String = Sys.getCwd() + '/${flr}/';
23+
if (!FileSystem.exists(intendedPath))
24+
FileSystem.createDirectory(intendedPath);
25+
trace("created: " + flr);
26+
}
27+
#end
28+
}
29+
30+
/**
31+
* Crash Handler, for iOS.
32+
* @param crashMessage Message that will be shown.
33+
* @param fileName File Name for the crash log.
34+
*/
35+
public static function onCrash(crashMessage:String, fileName:String)
36+
{
37+
#if ios
38+
try
39+
{
40+
var crashPath:String = Sys.getCwd() + "/crash/";
41+
if (!FileSystem.exists(crashPath))
42+
FileSystem.createDirectory(crashPath);
43+
44+
File.saveContent(crashPath + fileName, crashMessage);
45+
}
46+
catch (e)
47+
{
48+
trace("Failed to save crash log, reason: " + e);
49+
}
50+
51+
Lib.application.window.alert(crashMessage, 'Error!');
52+
System.exit(1);
53+
#end
54+
}
55+
56+
/**
57+
* Returns FlxTouch, shortcut to `FlxG.touches.getFirst()`.
58+
* @return FlxTouch
59+
*/
60+
public static function touch():FlxTouch
61+
{
62+
return (FlxG.touches.getFirst());
63+
}
64+
65+
/**
66+
* Touch checker for `spr`, then runs `onTouch` function
67+
* @param spr Sprite that will be checked
68+
* @param onTouch Function that will be runned if Touch = true
69+
*/
70+
public static function touchJustPressed(spr:FlxSprite, onTouch:Void->Void)
71+
{
72+
if (IOS.touch() != null)
73+
{
74+
var sprPos = spr.getScreenPosition(FlxG.camera);
75+
var touchX = IOS.touch().screenX;
76+
var touchY = IOS.touch().screenY;
77+
var overlap:Bool = (touchX >= sprPos.x && touchX <= sprPos.x + spr.frameWidth && touchY >= sprPos.y && touchY <= sprPos.y + spr.frameHeight);
78+
if (overlap && IOS.touch().justPressed)
79+
{
80+
onTouch();
81+
}
82+
}
83+
}
84+
}

source/meta/modding/cvcxvcvx.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
package meta.modding; import meta.states.TitleState; import flixel.tweens.FlxTween; import game.cdev.CDevConfig; import sys.io.File; import haxe.Json; import game.cdev.CDevMods.ModFile; import sys.FileSystem; import openfl.Lib; import game.Controls.Control; import flash.text.TextField; import flixel.FlxG; import flixel.FlxSprite; import flixel.addons.display.FlxGridOverlay; import flixel.group.FlxGroup.FlxTypedGroup; import flixel.input.keyboard.FlxKey; import flixel.math.FlxMath; import flixel.text.FlxText; import flixel.util.FlxColor; import lime.utils.Assets; #if desktop import game.cdev.engineutils.Discord.DiscordClient; #end import game.objects.Alphabet; import game.*; using StringTools; class ElWawa extends meta.states.MusicBeatState { var curSelected:Int = 0; var modShits:Array<ModFile> = []; var grpOptions:FlxTypedGroup<Alphabet>; var menuBG:FlxSprite; var modBG:FlxSprite; var descArray:Array<FlxText> = []; var noMods:Bool = false; var iconArray:Array<ModIcon> = []; var usingCustomBG:Bool = false; override function create() { #if desktop if (Main.discordRPC) DiscordClient.changePresence("Installing a mod.", null); #end FlxG.sound.muteKeys = [ZERO, NUMPADZERO]; FlxG.sound.volumeDownKeys = [MINUS, NUMPADMINUS]; FlxG.sound.volumeUpKeys = [PLUS, NUMPADPLUS]; var shit:Array<String> = FileSystem.readDirectory('cdev-mods/'); shit.remove('readme.txt'); for (i in 0...shit.length) { if (FileSystem.isDirectory('cdev-mods/' + shit[i])) { var crapJSON = null; #if ALLOW_MODS var file:String = Paths.cdModsFile(shit[i]); if (FileSystem.exists(file)) crapJSON = File.getContent(file); #end if (crapJSON == null) continue; var json:ModFile = cast Json.parse(crapJSON); if (crapJSON != null) modShits.push(json); } } if (shit.length == 0) { var sad:ModFile = { modName: 'No Mods Found', modDesc: 'Please check your cdev-mods folder.', modVer: CDevConfig.engineVersion, restart_required: false, disable_base_game: false, window_title: "Friday Night Funkin' CDEV Engine", window_icon: "", mod_difficulties: [] }; modShits.push(sad); noMods = true; } menuBG = new FlxSprite().loadGraphic(Paths.image('aboutMenu')); menuBG.color = CDevConfig.utils.CDEV_ENGINE_BLUE; menuBG.setGraphicSize(Std.int(menuBG.width * 1.1)); menuBG.updateHitbox(); menuBG.screenCenter(); menuBG.alpha = 0.5; menuBG.antialiasing = CDevConfig.saveData.antialiasing; add(menuBG); modBG = new FlxSprite().loadGraphic(Paths.image('menuDesat')); modBG.setGraphicSize(FlxG.width, FlxG.height); modBG.updateHitbox(); modBG.screenCenter(); modBG.alpha = 0; modBG.antialiasing = CDevConfig.saveData.antialiasing; add(modBG); grpOptions = new FlxTypedGroup<Alphabet>(); add(grpOptions); for (i in 0...modShits.length) { var optionText:Alphabet = new Alphabet(0, (70 * i) + 30, modShits[i].modName, true, false, 32); optionText.isMenuItem = true; optionText.isFreeplay = true; optionText.targetY = i; grpOptions.add(optionText); Paths.currentMod = modShits[i].modName; var iconShit:ModIcon = new ModIcon(0, 0, modShits[i].modName); iconShit.sprTracker = optionText; add(iconShit); iconArray.push(iconShit); var description:FlxText = new FlxText(optionText.x + 10, optionText.y + optionText.height + 10, (FlxG.width / 2)+100, modShits[i].modDesc, 14); description.setFormat(FunkinFonts.VCR, 20, FlxColor.WHITE, LEFT, OUTLINE, FlxColor.BLACK); descArray.push(description); add(description); } changeSelection(0, false); var text = meta.states.MainMenuState.coreEngineText + ' - '; var versionShit:FlxText = new FlxText(20, FlxG.height - 30, 1000, text, 16); versionShit.scrollFactor.set(); versionShit.setFormat(FunkinFonts.VCR, 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); versionShit.alpha = 0.7; if (Paths.curModDir.length == 1) { var lastCurMod = Paths.currentMod; Paths.currentMod = Paths.curModDir[0]; var d:ModFile = Paths.modData(); if (Reflect.hasField(d, "restart_required")) { if (d.restart_required) { lastModRequireRestart = true; trace("will restart"); } } Paths.currentMod = lastCurMod; } super.create(); } override function closeSubState() { super.closeSubState(); changeSelection(); } var restartOnExit:Bool = false; public var lastModRequireRestart:Bool = false; override function update(elapsed:Float) { super.update(elapsed); for (i in 0...descArray.length) { var daThing:Alphabet = grpOptions.members[i]; descArray[i].setPosition(daThing.x, daThing.y + daThing.height + 10); } for (i in 0...modShits.length) { var thing:Array<String> = Paths.curModDir.copy(); var theObject:Alphabet = grpOptions.members[i]; theObject.color = (thing.contains(theObject.text) ? FlxColor.CYAN : FlxColor.WHITE); } if (controls.UI_UP_P) { changeSelection(-1); } if (controls.UI_DOWN_P) { changeSelection(1); } if (controls.BACK) { if (!restartOnExit) { FlxG.switchState(new ModdingState()); } else { Paths.currentMod = Paths.curModDir[0]; TitleState.loadMod = !lastModRequireRestart; if (FlxG.sound.music != null) FlxTween.tween(FlxG.sound.music, {volume: 0}, 1); FlxTween.tween(FlxG.camera, {alpha: 0}, 1, { onComplete: function(e:FlxTween) { CDevConfig.utils.restartGame(); } }); } FlxG.save.flush(); Conductor.updateSettings(); FlxG.sound.play(Paths.sound('cancelMenu')); } if (controls.RESET) { FlxG.sound.play(Paths.sound('cancelMenu')); Paths.curModDir = []; doCheck(); } if (controls.ACCEPT) { if (!noMods) { if (!Paths.curModDir.contains(modShits[curSelected].modName)) { FlxG.sound.play(Paths.sound('confirmMenu')); Paths.curModDir.push(modShits[curSelected].modName); } else { FlxG.sound.play(Paths.sound('cancelMenu')); checkRestart(modShits[curSelected].modName); Paths.curModDir.remove(modShits[curSelected].modName); } doCheck(); } } } function doCheck() { restartOnExit = false; CDevConfig.saveData.loadedMods = Paths.curModDir; CDevConfig.checkLoadedMods(); Paths.curModDir = CDevConfig.saveData.loadedMods; if (Paths.curModDir.length == 1) { var lastCurMod = Paths.currentMod; checkRestart(Paths.curModDir[0]); Paths.currentMod = lastCurMod; } else{ if (lastModRequireRestart){ restartOnExit = true; } } } function checkRestart(mod) { Paths.currentMod = mod; var d:ModFile = Paths.modData(); if (Reflect.hasField(d, "restart_required")) { if (d.restart_required) { restartOnExit = true; trace("Going to restart cuz of " + d.modName); } } } function changeSelection(change:Int = 0, noBGupdate:Bool = false) { var bullShit:Int = 0; FlxG.sound.play(Paths.sound('scrollMenu'), 0.4); curSelected += change; if (curSelected < 0) curSelected = modShits.length - 1; if (curSelected >= modShits.length) curSelected = 0; for (i in 0...descArray.length) { descArray[i].alpha = 0.6; } for (i in 0...iconArray.length) { iconArray[i].alpha = 0.6; } descArray[curSelected].alpha = 1; iconArray[curSelected].alpha = 1; for (item in grpOptions.members) { item.targetY = bullShit - curSelected; bullShit++; item.alpha = 0.6; item.selected = false; if (item.targetY == 0) { item.selected = true; item.alpha = 1; } } if (!noBGupdate) changeBackground(); } var tweenie:FlxTween; var uhh:FlxTween; function changeBackground() { var mod:String = modShits[curSelected].modName; Paths.currentMod = mod; if (FileSystem.exists(Paths.modFolders("background.png"))) { modBG.loadGraphic(Paths.modImage(Paths.modFolders("background.png"), true)); modBG.screenCenter(); modBG.setGraphicSize(FlxG.width, FlxG.height); modBG.color = 0xffffffff; if (!usingCustomBG) modBG.alpha = 0; if (!usingCustomBG) { if (tweenie != null) tweenie.cancel(); tweenie = FlxTween.tween(modBG, {alpha: 0.9}, 0.5, { onComplete: function(aa:FlxTween) { tweenie = null; } }); if (uhh != null) uhh.cancel(); uhh = FlxTween.tween(menuBG, {alpha: 0}, 0.5, { onComplete: function(aa:FlxTween) { uhh = null; } }); } usingCustomBG = true; return; } if (usingCustomBG) { if (tweenie != null) tweenie.cancel(); tweenie = FlxTween.tween(modBG, {alpha: 0}, 0.5, { onComplete: function(aa:FlxTween) { tweenie = null; } }); if (uhh != null) uhh.cancel(); uhh = FlxTween.tween(menuBG, {alpha: 0.6}, 0.5, { onComplete: function(aa:FlxTween) { uhh = null; } }); } usingCustomBG = false; } }
2-
//damn dude, you fr checked this?
2+
//damn dude, you fr checked this?

source/meta/states/MainMenuState.hx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package meta.states;
22

33
import game.system.native.Windows;
4-
#if android import game.system.native.Android; #end
4+
#if android import game.system.native.Android; #elseif ios import game.system.native.IOS; #end
55
import game.settings.data.SettingsProperties;
66
import meta.modding.week_editor.WeekData;
77
import meta.modding.ModPaths;
@@ -276,6 +276,18 @@ class MainMenuState extends MusicBeatState
276276
}
277277
});
278278
});
279+
#elseif ios
280+
menuItems.forEach(function(spr:FlxSprite)
281+
{
282+
IOS.touchJustPressed(spr, function (){
283+
if (selectedSomethin) return;
284+
if (spr.ID != curSelected){
285+
changeItem(spr.ID, true);
286+
} else{
287+
confirmShit();
288+
}
289+
});
290+
});
279291
#end
280292

281293
if (CDevConfig.saveData.testMode){

source/meta/states/OptionsState.hx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package meta.states;
22

33
#if android
44
import game.system.native.Android;
5+
#elseif ios
6+
import game.system.native.IOS;
57
#end
68
import game.settings.SettingsSubState;
79
import game.settings.data.SettingsProperties;
@@ -95,6 +97,21 @@ class OptionsState extends MusicBeatState
9597
}
9698
});
9799
});
100+
#elseif ios
101+
grpOptions.forEach(function(spr:FlxText)
102+
{
103+
Android.touchJustPressed(spr, function()
104+
{
105+
if (spr.ID != curSelected)
106+
{
107+
changeSelection(spr.ID, true);
108+
}
109+
else
110+
{
111+
onSelected();
112+
}
113+
});
114+
});
98115
#end
99116

100117
if (controls.UI_UP_P)

0 commit comments

Comments
 (0)