Create default worlds on restart if none exist
This commit is contained in:
parent
c0f4228096
commit
62f2f4546a
@ -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 zipAssetsFiles
|
||||||
preBuild.dependsOn zipAssetsGames
|
preBuild.dependsOn zipAssetsGames
|
||||||
preBuild.dependsOn zipAssetsWorlds
|
|
||||||
|
|
||||||
// Map for the version code that gives each ABI a value.
|
// Map for the version code that gives each ABI a value.
|
||||||
def abiCodes = ['armeabi-v7a': 0, 'arm64-v8a': 1]
|
def abiCodes = ['armeabi-v7a': 0, 'arm64-v8a': 1]
|
||||||
|
@ -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_CONNECTION;
|
||||||
import static com.multicraft.game.helpers.Constants.REQUEST_UPDATE;
|
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.UPDATE_LINK;
|
||||||
import static com.multicraft.game.helpers.Constants.WORLDS;
|
|
||||||
import static com.multicraft.game.helpers.Constants.versionName;
|
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_BUILD_NUMBER;
|
||||||
import static com.multicraft.game.helpers.PreferencesHelper.TAG_LAUNCH_TIMES;
|
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();
|
Toast.makeText(MainActivity.this, intent.getStringExtra(ACTION_FAILURE), Toast.LENGTH_LONG).show();
|
||||||
showRestartDialog("");
|
showRestartDialog("");
|
||||||
} else if (progress == UNZIP_SUCCESS) {
|
} else if (progress == UNZIP_SUCCESS) {
|
||||||
deleteFiles(Arrays.asList(FILES, WORLDS, GAMES), getCacheDir().toString());
|
deleteFiles(Arrays.asList(FILES, GAMES), getCacheDir().toString());
|
||||||
runGame();
|
runGame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -385,7 +384,6 @@ public class MainActivity extends AppCompatActivity implements CallBackListener
|
|||||||
|
|
||||||
private void startCopy(boolean isAll) {
|
private void startCopy(boolean isAll) {
|
||||||
zips = getZipsFromAssets(this);
|
zips = getZipsFromAssets(this);
|
||||||
if (!isAll) zips.remove(WORLDS);
|
|
||||||
copySub = Completable.fromAction(() -> runOnUiThread(() -> copyAssets(zips)))
|
copySub = Completable.fromAction(() -> runOnUiThread(() -> copyAssets(zips)))
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
@ -28,7 +28,6 @@ public class Constants {
|
|||||||
public static final int SESSION_COUNT = 5;
|
public static final int SESSION_COUNT = 5;
|
||||||
public static final String NO_SPACE_LEFT = "ENOSPC";
|
public static final String NO_SPACE_LEFT = "ENOSPC";
|
||||||
public static final String FILES = "Files.zip";
|
public static final String FILES = "Files.zip";
|
||||||
public static final String WORLDS = "worlds.zip";
|
|
||||||
public static final String GAMES = "games.zip";
|
public static final String GAMES = "games.zip";
|
||||||
public static final int versionCode = BuildConfig.VERSION_CODE;
|
public static final int versionCode = BuildConfig.VERSION_CODE;
|
||||||
public static final String versionName = BuildConfig.VERSION_NAME;
|
public static final String versionName = BuildConfig.VERSION_NAME;
|
||||||
|
@ -53,7 +53,6 @@ import static android.os.Environment.getExternalStorageDirectory;
|
|||||||
import static com.multicraft.game.helpers.ApiLevelHelper.isKitkat;
|
import static com.multicraft.game.helpers.ApiLevelHelper.isKitkat;
|
||||||
import static com.multicraft.game.helpers.Constants.FILES;
|
import static com.multicraft.game.helpers.Constants.FILES;
|
||||||
import static com.multicraft.game.helpers.Constants.GAMES;
|
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.Constants.appPackage;
|
||||||
import static com.multicraft.game.helpers.PreferencesHelper.TAG_SHORTCUT_EXIST;
|
import static com.multicraft.game.helpers.PreferencesHelper.TAG_SHORTCUT_EXIST;
|
||||||
|
|
||||||
@ -157,13 +156,6 @@ public class Utilities {
|
|||||||
case GAMES:
|
case GAMES:
|
||||||
path = context.getFilesDir().toString();
|
path = context.getFilesDir().toString();
|
||||||
break;
|
break;
|
||||||
case WORLDS:
|
|
||||||
try {
|
|
||||||
path = context.getExternalFilesDir(null).toString();
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
path = getExternalStorageDirectory() + "/Android/data/com.multicraft.game/files";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("No such zip name");
|
throw new IllegalArgumentException("No such zip name");
|
||||||
}
|
}
|
||||||
@ -174,7 +166,7 @@ public class Utilities {
|
|||||||
try {
|
try {
|
||||||
return new ArrayList<>(Arrays.asList(context.getAssets().list("data")));
|
return new ArrayList<>(Arrays.asList(context.getAssets().list("data")));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return new ArrayList<>(Arrays.asList(FILES, GAMES, WORLDS));
|
return new ArrayList<>(Arrays.asList(FILES, GAMES));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
water_level = 1
|
|
||||||
mg_name = v7p
|
|
||||||
seed = 15823438331521897617
|
|
||||||
[end_of_params]
|
|
@ -1 +0,0 @@
|
|||||||
gameid = default
|
|
@ -1,4 +0,0 @@
|
|||||||
water_level = 1
|
|
||||||
mg_name = v7p
|
|
||||||
seed = 1841722166046826822
|
|
||||||
[end_of_params]
|
|
@ -1 +0,0 @@
|
|||||||
gameid = default
|
|
@ -1,4 +0,0 @@
|
|||||||
water_level = 1
|
|
||||||
mg_name = v7p
|
|
||||||
seed = CC
|
|
||||||
[end_of_params]
|
|
@ -1 +0,0 @@
|
|||||||
gameid = default
|
|
@ -1,4 +0,0 @@
|
|||||||
water_level = 1
|
|
||||||
mg_name = valleys
|
|
||||||
seed = 8572
|
|
||||||
[end_of_params]
|
|
@ -1 +0,0 @@
|
|||||||
gameid = default
|
|
@ -1,4 +0,0 @@
|
|||||||
water_level = 1
|
|
||||||
mg_name = flat
|
|
||||||
seed = 2
|
|
||||||
[end_of_params]
|
|
@ -1 +0,0 @@
|
|||||||
gameid = default
|
|
@ -18,9 +18,54 @@
|
|||||||
local lang = core.settings:get("language")
|
local lang = core.settings:get("language")
|
||||||
if not lang or lang == "" then lang = os.getenv("LANG") end
|
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()
|
local function get_formspec()
|
||||||
menudata.worldlist:set_filtercriteria("default")
|
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,
|
local index = filterlist.get_current_index(menudata.worldlist,
|
||||||
tonumber(core.settings:get("mainmenu_last_selected_world")))
|
tonumber(core.settings:get("mainmenu_last_selected_world")))
|
||||||
if not index or index < 1 then
|
if not index or index < 1 then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user