mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 18:15:28 -04:00
iOS: Implement saving map to external provider (e.g. iCloud)
This commit is contained in:
parent
0e916bfeed
commit
75f00743ff
@ -462,7 +462,6 @@ void LocalInterpComp_SetLocation(struct InterpComp* interp, struct LocationUpdat
|
||||
struct EntityLocation* next = &e->next;
|
||||
cc_uint8 flags = update->flags;
|
||||
cc_bool interpolate = flags & LU_ORI_INTERPOLATE;
|
||||
float yOffset;
|
||||
|
||||
if (flags & LU_HAS_POS) {
|
||||
LocalInterpComp_SetPosition(update, flags & LU_POS_MODEMASK);
|
||||
|
@ -1542,8 +1542,7 @@ cc_result Cw_Save(struct Stream* stream) {
|
||||
/*########################################################################################################################*
|
||||
*---------------------------------------------------Schematic export------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
|
||||
static cc_uint8 sc_begin[78] = {
|
||||
static cc_uint8 sc_begin[] = {
|
||||
NBT_DICT, 0,9, 'S','c','h','e','m','a','t','i','c',
|
||||
NBT_STR, 0,9, 'M','a','t','e','r','i','a','l','s', 0,7, 'C','l','a','s','s','i','c',
|
||||
NBT_I16, 0,5, 'W','i','d','t','h', 0,0,
|
||||
@ -1551,10 +1550,10 @@ NBT_DICT, 0,9, 'S','c','h','e','m','a','t','i','c',
|
||||
NBT_I16, 0,6, 'L','e','n','g','t','h', 0,0,
|
||||
NBT_I8S, 0,6, 'B','l','o','c','k','s', 0,0,0,0,
|
||||
};
|
||||
static cc_uint8 sc_data[11] = {
|
||||
static cc_uint8 sc_data[] = {
|
||||
NBT_I8S, 0,4, 'D','a','t','a', 0,0,0,0,
|
||||
};
|
||||
static cc_uint8 sc_end[37] = {
|
||||
static cc_uint8 sc_end[] = {
|
||||
NBT_LIST, 0,8, 'E','n','t','i','t','i','e','s', NBT_DICT, 0,0,0,0,
|
||||
NBT_LIST, 0,12, 'T','i','l','e','E','n','t','i','t','i','e','s', NBT_DICT, 0,0,0,0,
|
||||
NBT_END,
|
||||
@ -1588,6 +1587,10 @@ cc_result Schematic_Save(struct Stream* stream) {
|
||||
return Stream_Write(stream, sc_end, sizeof(sc_end));
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------Dat export---------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static const struct JField {
|
||||
cc_uint8 type, isFloat;
|
||||
const char* name;
|
||||
@ -1649,10 +1652,8 @@ static cc_result WriteClassDesc(struct Stream* stream, cc_uint8 typecode, const
|
||||
|
||||
cc_result Dat_Save(struct Stream* stream) {
|
||||
static const cc_uint8 header[] = {
|
||||
/* DAT signature + version */
|
||||
0x27,0x1B,0xB7,0x88, 0x02,
|
||||
/* JSF signature + version */
|
||||
0xAC,0xED, 0x00,0x05
|
||||
0x27,0x1B,0xB7,0x88, 0x02, /* DAT signature + version */
|
||||
0xAC,0xED, 0x00,0x05 /* JSF signature + version */
|
||||
};
|
||||
const struct JField* field;
|
||||
cc_uint8 tmp[4];
|
||||
|
@ -586,6 +586,7 @@ cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* args) {
|
||||
String_Format1(&path, "Downloads/%s", &file);
|
||||
|
||||
args->Callback(&path);
|
||||
/* TODO use utf8 instead */
|
||||
pathBuffer[path.length] = '\0';
|
||||
fileBuffer[file.length] = '\0';
|
||||
return interop_DownloadFile(pathBuffer, fileBuffer);
|
||||
|
@ -108,7 +108,20 @@ static CGRect GetViewFrame(void) {
|
||||
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
|
||||
}
|
||||
|
||||
static OpenFileDialogCallback open_dlg_callback;
|
||||
// ==== UIDocumentPickerDelegate ====
|
||||
static FileDialogCallback open_dlg_callback;
|
||||
static char save_buffer[FILENAME_SIZE];
|
||||
static cc_string save_path = String_FromArray(save_buffer);
|
||||
|
||||
static void DeleteExportTempFile(void) {
|
||||
if (!save_path.length) return;
|
||||
|
||||
char path[NATIVE_STR_LEN];
|
||||
Platform_EncodeUtf8(path, &save_path);
|
||||
unlink(path);
|
||||
save_path.length = 0;
|
||||
}
|
||||
|
||||
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
|
||||
NSString* str = url.path;
|
||||
const char* utf8 = str.UTF8String;
|
||||
@ -116,7 +129,15 @@ static OpenFileDialogCallback open_dlg_callback;
|
||||
char tmpBuffer[NATIVE_STR_LEN];
|
||||
cc_string tmp = String_FromArray(tmpBuffer);
|
||||
String_AppendUtf8(&tmp, utf8, String_Length(utf8));
|
||||
|
||||
DeleteExportTempFile();
|
||||
if (!open_dlg_callback) return;
|
||||
open_dlg_callback(&tmp);
|
||||
open_dlg_callback = NULL;
|
||||
}
|
||||
|
||||
- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller {
|
||||
DeleteExportTempFile();
|
||||
}
|
||||
|
||||
static cc_bool kb_active;
|
||||
@ -514,6 +535,29 @@ cc_result Window_OpenFileDialog(const struct OpenFileDialogArgs* args) {
|
||||
return 0; // TODO still unfinished
|
||||
}
|
||||
|
||||
cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* args) {
|
||||
if (!args->defaultName.length) return SFD_ERR_NEED_DEFAULT_NAME;
|
||||
|
||||
// save the item to a temp file, which is then (usually) later deleted by picker callbacks
|
||||
cc_string tmpDir = String_FromConst("Exported");
|
||||
Directory_Create(&tmpDir);
|
||||
|
||||
save_path.length = 0;
|
||||
String_Format3(&save_path, "%s/%s%c", &tmpDir, &args->defaultName, args->filters[0]);
|
||||
args->Callback(&save_path);
|
||||
|
||||
NSString* str = ToNSString(&save_path);
|
||||
NSURL* url = [NSURL fileURLWithPath:str isDirectory:NO];
|
||||
|
||||
UIDocumentPickerViewController* dlg;
|
||||
dlg = [UIDocumentPickerViewController alloc];
|
||||
dlg = [dlg initWithURL:url inMode:UIDocumentPickerModeExportToService];
|
||||
|
||||
dlg.delegate = cc_controller;
|
||||
[cc_controller presentViewController:dlg animated:YES completion: Nil];
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*#########################################################################################################################*
|
||||
*--------------------------------------------------------2D window--------------------------------------------------------*
|
||||
@ -676,11 +720,8 @@ static char gameArgs[GAME_MAX_CMDARGS][STRING_SIZE];
|
||||
static int gameNumArgs;
|
||||
|
||||
cc_result Process_StartOpen(const cc_string* args) {
|
||||
NSURL* url;
|
||||
NSString* str;
|
||||
|
||||
str = ToNSString(args);
|
||||
url = [[NSURL alloc] initWithString:str];
|
||||
NSString* str = ToNSString(args);
|
||||
NSURL* url = [[NSURL alloc] initWithString:str];
|
||||
[UIApplication.sharedApplication openURL:url];
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user