From 62f2f4546a22972ec74e3d06ebd8bf66a4e2be59 Mon Sep 17 00:00:00 2001 From: luk3yx Date: Tue, 6 Jul 2021 15:57:56 +1200 Subject: [PATCH] Create default worlds on restart if none exist --- build/android/app/build.gradle | 9 ---- .../com/multicraft/game/MainActivity.java | 4 +- .../multicraft/game/helpers/Constants.java | 1 - .../multicraft/game/helpers/Utilities.java | 10 +---- build/worlds/World 1/map_meta.txt | 4 -- build/worlds/World 1/world.mt | 1 - build/worlds/World 2/map_meta.txt | 4 -- build/worlds/World 2/world.mt | 1 - build/worlds/World 3/map_meta.txt | 4 -- build/worlds/World 3/world.mt | 1 - build/worlds/World 4/map_meta.txt | 4 -- build/worlds/World 4/world.mt | 1 - build/worlds/World 5 Flat/map_meta.txt | 4 -- build/worlds/World 5 Flat/world.mt | 1 - builtin/mainmenu/tab_local_default.lua | 45 +++++++++++++++++++ 15 files changed, 47 insertions(+), 47 deletions(-) delete mode 100644 build/worlds/World 1/map_meta.txt delete mode 100644 build/worlds/World 1/world.mt delete mode 100644 build/worlds/World 2/map_meta.txt delete mode 100644 build/worlds/World 2/world.mt delete mode 100644 build/worlds/World 3/map_meta.txt delete mode 100644 build/worlds/World 3/world.mt delete mode 100644 build/worlds/World 4/map_meta.txt delete mode 100644 build/worlds/World 4/world.mt delete mode 100644 build/worlds/World 5 Flat/map_meta.txt delete mode 100644 build/worlds/World 5 Flat/world.mt diff --git a/build/android/app/build.gradle b/build/android/app/build.gradle index d1ae39c8b..6f0ba6e21 100644 --- a/build/android/app/build.gradle +++ b/build/android/app/build.gradle @@ -113,17 +113,8 @@ task prepareAssetsGames() { } } -task zipAssetsWorlds(type: Zip) { - archiveFileName = "worlds.zip" - destinationDirectory = file("src/main/assets/data") - from("../../worlds") { - into "worlds" - } -} - preBuild.dependsOn zipAssetsFiles preBuild.dependsOn zipAssetsGames -preBuild.dependsOn zipAssetsWorlds // Map for the version code that gives each ABI a value. def abiCodes = ['armeabi-v7a': 0, 'arm64-v8a': 1] diff --git a/build/android/app/src/main/java/com/multicraft/game/MainActivity.java b/build/android/app/src/main/java/com/multicraft/game/MainActivity.java index d949a2de2..7c958e9eb 100644 --- a/build/android/app/src/main/java/com/multicraft/game/MainActivity.java +++ b/build/android/app/src/main/java/com/multicraft/game/MainActivity.java @@ -93,7 +93,6 @@ import static com.multicraft.game.helpers.Constants.NO_SPACE_LEFT; import static com.multicraft.game.helpers.Constants.REQUEST_CONNECTION; import static com.multicraft.game.helpers.Constants.REQUEST_UPDATE; import static com.multicraft.game.helpers.Constants.UPDATE_LINK; -import static com.multicraft.game.helpers.Constants.WORLDS; import static com.multicraft.game.helpers.Constants.versionName; import static com.multicraft.game.helpers.PreferencesHelper.TAG_BUILD_NUMBER; import static com.multicraft.game.helpers.PreferencesHelper.TAG_LAUNCH_TIMES; @@ -136,7 +135,7 @@ public class MainActivity extends AppCompatActivity implements CallBackListener Toast.makeText(MainActivity.this, intent.getStringExtra(ACTION_FAILURE), Toast.LENGTH_LONG).show(); showRestartDialog(""); } else if (progress == UNZIP_SUCCESS) { - deleteFiles(Arrays.asList(FILES, WORLDS, GAMES), getCacheDir().toString()); + deleteFiles(Arrays.asList(FILES, GAMES), getCacheDir().toString()); runGame(); } } @@ -385,7 +384,6 @@ public class MainActivity extends AppCompatActivity implements CallBackListener private void startCopy(boolean isAll) { zips = getZipsFromAssets(this); - if (!isAll) zips.remove(WORLDS); copySub = Completable.fromAction(() -> runOnUiThread(() -> copyAssets(zips))) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) diff --git a/build/android/app/src/main/java/com/multicraft/game/helpers/Constants.java b/build/android/app/src/main/java/com/multicraft/game/helpers/Constants.java index 85275423a..688b4a0a6 100644 --- a/build/android/app/src/main/java/com/multicraft/game/helpers/Constants.java +++ b/build/android/app/src/main/java/com/multicraft/game/helpers/Constants.java @@ -28,7 +28,6 @@ public class Constants { public static final int SESSION_COUNT = 5; public static final String NO_SPACE_LEFT = "ENOSPC"; public static final String FILES = "Files.zip"; - public static final String WORLDS = "worlds.zip"; public static final String GAMES = "games.zip"; public static final int versionCode = BuildConfig.VERSION_CODE; public static final String versionName = BuildConfig.VERSION_NAME; diff --git a/build/android/app/src/main/java/com/multicraft/game/helpers/Utilities.java b/build/android/app/src/main/java/com/multicraft/game/helpers/Utilities.java index 09d08b967..cca528ff9 100644 --- a/build/android/app/src/main/java/com/multicraft/game/helpers/Utilities.java +++ b/build/android/app/src/main/java/com/multicraft/game/helpers/Utilities.java @@ -53,7 +53,6 @@ import static android.os.Environment.getExternalStorageDirectory; import static com.multicraft.game.helpers.ApiLevelHelper.isKitkat; import static com.multicraft.game.helpers.Constants.FILES; import static com.multicraft.game.helpers.Constants.GAMES; -import static com.multicraft.game.helpers.Constants.WORLDS; import static com.multicraft.game.helpers.Constants.appPackage; import static com.multicraft.game.helpers.PreferencesHelper.TAG_SHORTCUT_EXIST; @@ -157,13 +156,6 @@ public class Utilities { case GAMES: path = context.getFilesDir().toString(); break; - case WORLDS: - try { - path = context.getExternalFilesDir(null).toString(); - } catch (NullPointerException e) { - path = getExternalStorageDirectory() + "/Android/data/com.multicraft.game/files"; - } - break; default: throw new IllegalArgumentException("No such zip name"); } @@ -174,7 +166,7 @@ public class Utilities { try { return new ArrayList<>(Arrays.asList(context.getAssets().list("data"))); } catch (IOException e) { - return new ArrayList<>(Arrays.asList(FILES, GAMES, WORLDS)); + return new ArrayList<>(Arrays.asList(FILES, GAMES)); } } } diff --git a/build/worlds/World 1/map_meta.txt b/build/worlds/World 1/map_meta.txt deleted file mode 100644 index e2af5f116..000000000 --- a/build/worlds/World 1/map_meta.txt +++ /dev/null @@ -1,4 +0,0 @@ -water_level = 1 -mg_name = v7p -seed = 15823438331521897617 -[end_of_params] diff --git a/build/worlds/World 1/world.mt b/build/worlds/World 1/world.mt deleted file mode 100644 index 8e2686024..000000000 --- a/build/worlds/World 1/world.mt +++ /dev/null @@ -1 +0,0 @@ -gameid = default diff --git a/build/worlds/World 2/map_meta.txt b/build/worlds/World 2/map_meta.txt deleted file mode 100644 index 9c2e639d5..000000000 --- a/build/worlds/World 2/map_meta.txt +++ /dev/null @@ -1,4 +0,0 @@ -water_level = 1 -mg_name = v7p -seed = 1841722166046826822 -[end_of_params] diff --git a/build/worlds/World 2/world.mt b/build/worlds/World 2/world.mt deleted file mode 100644 index 8e2686024..000000000 --- a/build/worlds/World 2/world.mt +++ /dev/null @@ -1 +0,0 @@ -gameid = default diff --git a/build/worlds/World 3/map_meta.txt b/build/worlds/World 3/map_meta.txt deleted file mode 100644 index 73e8a97a2..000000000 --- a/build/worlds/World 3/map_meta.txt +++ /dev/null @@ -1,4 +0,0 @@ -water_level = 1 -mg_name = v7p -seed = CC -[end_of_params] diff --git a/build/worlds/World 3/world.mt b/build/worlds/World 3/world.mt deleted file mode 100644 index 8e2686024..000000000 --- a/build/worlds/World 3/world.mt +++ /dev/null @@ -1 +0,0 @@ -gameid = default diff --git a/build/worlds/World 4/map_meta.txt b/build/worlds/World 4/map_meta.txt deleted file mode 100644 index 3414244e8..000000000 --- a/build/worlds/World 4/map_meta.txt +++ /dev/null @@ -1,4 +0,0 @@ -water_level = 1 -mg_name = valleys -seed = 8572 -[end_of_params] diff --git a/build/worlds/World 4/world.mt b/build/worlds/World 4/world.mt deleted file mode 100644 index 8e2686024..000000000 --- a/build/worlds/World 4/world.mt +++ /dev/null @@ -1 +0,0 @@ -gameid = default diff --git a/build/worlds/World 5 Flat/map_meta.txt b/build/worlds/World 5 Flat/map_meta.txt deleted file mode 100644 index 7db9b3af1..000000000 --- a/build/worlds/World 5 Flat/map_meta.txt +++ /dev/null @@ -1,4 +0,0 @@ -water_level = 1 -mg_name = flat -seed = 2 -[end_of_params] diff --git a/build/worlds/World 5 Flat/world.mt b/build/worlds/World 5 Flat/world.mt deleted file mode 100644 index 8e2686024..000000000 --- a/build/worlds/World 5 Flat/world.mt +++ /dev/null @@ -1 +0,0 @@ -gameid = default diff --git a/builtin/mainmenu/tab_local_default.lua b/builtin/mainmenu/tab_local_default.lua index e5b3bfb44..e92bf3fc1 100644 --- a/builtin/mainmenu/tab_local_default.lua +++ b/builtin/mainmenu/tab_local_default.lua @@ -18,9 +18,54 @@ local lang = core.settings:get("language") if not lang or lang == "" then lang = os.getenv("LANG") end +local default_worlds = { + {name = "World 1", mg_name = "v7p", seed = "15823438331521897617"}, + {name = "World 2", mg_name = "v7p", seed = "1841722166046826822"}, + {name = "World 3", mg_name = "v7p", seed = "CC"}, + {name = "World 4", mg_name = "valleys", seed = "8572"}, + {name = "World 5 Flat", mg_name = "flat", seed = "2"} +} + +local function create_default_worlds() + local _, gameindex = pkgmgr.find_by_gameid("default") + if not gameindex or gameindex == 0 then return end + + -- Preserve the old map seed and mapgen values + local old_map_seed = core.settings:get("fixed_map_seed") + local old_mapgen = core.settings:get("mg_name") + + -- Create the worlds + for _, world in ipairs(default_worlds) do + core.settings:set("fixed_map_seed", world.seed) + core.settings:set("mg_name", world.mg_name) + core.create_world(world.name, gameindex) + end + + -- Restore the old values + if old_map_seed then + core.settings:set("fixed_map_seed", old_map_seed) + else + core.settings:remove("fixed_map_seed") + end + if old_mapgen then + core.settings:set("mg_name", old_mapgen) + else + core.settings:remove("mg_name") + end + + menudata.worldlist:refresh() +end + +local checked_worlds = false local function get_formspec() menudata.worldlist:set_filtercriteria("default") + -- Only check the worlds once (on restart) + if not checked_worlds and #menudata.worldlist:get_list() == 0 then + create_default_worlds() + end + checked_worlds = true + local index = filterlist.get_current_index(menudata.worldlist, tonumber(core.settings:get("mainmenu_last_selected_world"))) if not index or index < 1 then