project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/FrontendDataUtil.java
author Xeli
Thu, 14 Jul 2011 15:55:28 +0200
branchhedgeroid
changeset 5433 8f82045953c1
permissions -rw-r--r--
Main class files for the start-local-game screen
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5433
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
     1
package org.hedgewars.mobile;
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
     2
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
     3
import java.io.File;
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
     4
import java.util.Arrays;
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
     5
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
     6
import android.content.Context;
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
     7
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
     8
public class FrontendDataUtil {
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
     9
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    10
	private static final String MISSION_PREFIX = "Mission: ";
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    11
	
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    12
	public static String[] getMaps(Context c){
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    13
		File[] files = Utils.getFilesFromRelativeDir(c,"Maps");
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    14
		String[] maps = new String[files.length];
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    15
		String[] missions = new String[maps.length];
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    16
		int mapsCounter = 0, missionsCounter = 0;
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    17
		
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    18
		for(File f : files){
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    19
			if(Utils.hasFileWithSuffix(f, ".lua")){
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    20
				missions[missionsCounter++] = MISSION_PREFIX + f.getName();
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    21
			}else{
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    22
				maps[mapsCounter++] = f.getName();
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    23
			}
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    24
		}
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    25
		String[] ret = new String[maps.length];
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    26
		System.arraycopy(missions, 0, ret, 0, missionsCounter);
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    27
		System.arraycopy(maps, 0, ret, missionsCounter, mapsCounter);
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    28
		Arrays.sort(ret, 0, missionsCounter);
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    29
		Arrays.sort(ret, missionsCounter, ret.length);
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    30
		return ret;
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    31
	}
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    32
	
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    33
	public static String[] getGameplay(Context c){
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    34
		String[] files = Utils.getFileNamesFromRelativeDir(c, "Scripts/Multiplayer");
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    35
		int retCounter = 0;
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    36
		
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    37
		for(int i = 0; i < files.length; i++){
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    38
			if(files[i].endsWith(".lua")){
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    39
				files[i] = files[i].replace('_', ' ').substring(0, files[i].length()-4); //replace _ by a space and removed the last four characters (.lua)
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    40
				retCounter++;
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    41
			}else files[i] = null;
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    42
		}
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    43
		String[] ret = new String[retCounter];
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    44
		retCounter = 0;
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    45
		for(String s : files){
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    46
			if(s != null) ret[retCounter++] = s;
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    47
		}
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    48
		Arrays.sort(ret);
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    49
		
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    50
		return ret;	
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    51
	}
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    52
	
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    53
	public static String[] getThemes(Context c){
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    54
		return Utils.getDirsWithFileSuffix(c, "Themes", "icon.png");
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    55
	}
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    56
	
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    57
	public static Scheme[] getSchemes(Context c){
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    58
		return Scheme.getSchemes(c);
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    59
	}
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    60
	
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    61
	public static Weapon[] getWeapons(Context c){
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    62
		return Weapon.getWeapons(c);
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    63
	}
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    64
}