当前位置: 首页>>代码示例>>Java>>正文


Java Base64Coder类代码示例

本文整理汇总了Java中com.badlogic.gdx.utils.Base64Coder的典型用法代码示例。如果您正苦于以下问题:Java Base64Coder类的具体用法?Java Base64Coder怎么用?Java Base64Coder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Base64Coder类属于com.badlogic.gdx.utils包,在下文中一共展示了Base64Coder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: saveGameStateSync

import com.badlogic.gdx.utils.Base64Coder; //导入依赖的package包/类
public Boolean saveGameStateSync(String id, byte[] gameState, long progressValue,
                                 ISaveGameStateResponseListener listener) {
    if (!isSessionActive() || !whisperSyncEnabled)
        return false;

    GameDataMap gameDataMap = AmazonGamesClient.getWhispersyncClient().getGameData();

    SyncableString savedData = gameDataMap.getLatestString(id);
    SyncableNumber savedProgress = gameDataMap.getLatestNumber(id + "progress");

    if (!savedProgress.isSet() || savedProgress.asLong() <= progressValue) {
        savedData.set(new String(Base64Coder.encode(gameState)));
        savedProgress.set(progressValue);
        if (listener != null)
            listener.onGameStateSaved(true, null);
        return true;
    } else {
        Gdx.app.error(GameCircleClient.GS_CLIENT_ID, "Progress of saved game state higher than current one. Did " +
                "not save.");
        if (listener != null)
            listener.onGameStateSaved(true, null);
        return false;
    }
}
 
开发者ID:MrStahlfelge,项目名称:gdx-gamesvcs,代码行数:25,代码来源:GameCircleClient.java

示例2: onMessage

import com.badlogic.gdx.utils.Base64Coder; //导入依赖的package包/类
@Override
public void onMessage(WebSocket conn, String message) {
    try {
        KryoConnection k = getBySocket(conn);
        if (k == null) return;

        if(message.equals("_ping_")){
            conn.send(connections.size() + "|" + Vars.player.name);
            connections.remove(k);
        }else {
            if (debug) UCore.log("Got message: " + message);

            byte[] out = Base64Coder.decode(message);
            if (debug) UCore.log("Decoded: " + Arrays.toString(out));
            ByteBuffer buffer = ByteBuffer.wrap(out);
            Object o = serializer.read(buffer);
            Net.handleServerReceived(o, k.id);
        }
    }catch (Exception e){
        UCore.log("Error reading message!");
        e.printStackTrace();
    }
}
 
开发者ID:Anuken,项目名称:Mindustry,代码行数:24,代码来源:KryoServer.java

示例3: saveToSlot

import com.badlogic.gdx.utils.Base64Coder; //导入依赖的package包/类
public static void saveToSlot(int slot){
	if(Vars.gwt){
		ByteArrayOutputStream stream = new ByteArrayOutputStream();
		write(stream);
		Settings.putString("save-"+slot+"-data", new String(Base64Coder.encode(stream.toByteArray())));
		Settings.save();
	}else{
		FileHandle file = fileFor(slot);
		boolean exists = file.exists();
		if(exists) file.moveTo(file.sibling(file.name() + "-backup." + file.extension()));
		try {
			write(fileFor(slot));
		}catch (Exception e){
			if(exists) file.sibling(file.name() + "-backup." + file.extension()).moveTo(file);
			throw new RuntimeException(e);
		}
	}
}
 
开发者ID:Anuken,项目名称:Mindustry,代码行数:19,代码来源:SaveIO.java

示例4: hasOlderVersionSavingSystem

import com.badlogic.gdx.utils.Base64Coder; //导入依赖的package包/类
public boolean hasOlderVersionSavingSystem() {
	String codedKey = Base64Coder.encodeString("currentLevel");
	String stringUncodedValue = Base64Coder.decodeString(pref.getString(codedKey));

	String codedKey2 = Base64Coder.encodeString("chapter1");
	String stringUncodedValue2 = Base64Coder.decodeString(pref.getString(codedKey2));

	if (stringUncodedValue.compareTo("") == 0) {
		return false;
	} else {
		if (stringUncodedValue2.compareTo("") == 0) {
			return true;
		} else {
			return false;
		}
	}
}
 
开发者ID:bogdanguranda,项目名称:sokobug,代码行数:18,代码来源:PlayerProgressManager.java

示例5: loadLevelsStatus

import com.badlogic.gdx.utils.Base64Coder; //导入依赖的package包/类
private void loadLevelsStatus() {
	if (hasOlderVersionSavingSystem()) {
		loadOlderVersionChapter1();
	}

	for (int i = 0; i < PlayerProgress.NUMBER_OF_CHAPTERS; i++) {
		String codedKey = Base64Coder.encodeString("chapter" + (i + 1));
		String stringUncodedValue = Base64Coder.decodeString(pref.getString(codedKey));
		if (stringUncodedValue.compareTo("") == 0) {
			saveLevelsStatus();
			break;
		} else {
			String stringLevelsStatus[] = stringUncodedValue.split(" ");
			int levelsStatus[] = new int[stringLevelsStatus.length];
			for (int j = 0; j < stringLevelsStatus.length; j++) {
				levelsStatus[j] = Integer.valueOf(stringLevelsStatus[j]);
			}
			playerProgress.setLevelsStatus(levelsStatus, i + 1);
		}
	}
}
 
开发者ID:bogdanguranda,项目名称:sokobug,代码行数:22,代码来源:PlayerProgressManager.java

示例6: retrieveHighScores

import com.badlogic.gdx.utils.Base64Coder; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void retrieveHighScores() {
	FileHandle highScoresFile = Gdx.files.local(SCORES_DATA_FILE);
	if( highScoresFile.exists() ) {
		Json json = new Json();
		try {
			String encScoresStr = highScoresFile.readString();
			String scoresStr = Base64Coder.decodeString( encScoresStr );
			highScores = json.fromJson(ArrayList.class, HighScore.class, scoresStr);
			return;
           } catch( Exception e ) {
               Gdx.app.error( HighScoreManager.class.getName(), 
               		"Unable to parse high scores data file", e );
           }
	}
	highScores = new ArrayList<HighScore>();
	String playerName = textResources.getDefaultPlayerName();
	for(int i=0;i<HIGH_SCORES_COUNT;i++){
		highScores.add(new HighScore(playerName, 50 - 10*i, false));
	}
}
 
开发者ID:kgiannakakis,项目名称:FruitCatcher,代码行数:22,代码来源:HighScoreManager.java

示例7: save

import com.badlogic.gdx.utils.Base64Coder; //导入依赖的package包/类
public static void save(TilePrefab prefab, String outputFilename) {
	if (prefab == null)
		throw new IllegalArgumentException();

	JsonTilePrefab jsonPrefab = new JsonTilePrefab();
	jsonPrefab.width = prefab.getWidth();
	jsonPrefab.height = prefab.getHeight();
	jsonPrefab.depth = prefab.getDepth();

	byte[] dataBytes = new byte[prefab.getData().length * TileDataSerializer.TILE_SIZE_BYTES];
	ByteBuffer buffer = ByteBuffer.wrap(dataBytes);

	TileDataSerializer.serialize(prefab, buffer);
	jsonPrefab.data = new String(Base64Coder.encode(dataBytes));

	Json json = new Json();
	String output = json.prettyPrint(jsonPrefab);
	FileHandle outputFile = Gdx.files.local(outputFilename);
	outputFile.writeString(output, false);
}
 
开发者ID:gered,项目名称:gdx-tilemap3d,代码行数:21,代码来源:TilePrefabSaver.java

示例8: persist

import com.badlogic.gdx.utils.Base64Coder; //导入依赖的package包/类
protected void persist(Profile profile)
{
	// create the handle for profile data file
	FileHandle profileDataFile = Gdx.files.local(PROFILE_DATA_FILE);
	Gdx.app.log(GensokyoGame.LOG, "Persisting profile in: " + profileDataFile.path());
	
	Json json = new Json();
	
	// convert profile to text
	String profileAsText = json.toJson(profile);
	
	// encode the text
	if (!GensokyoGame.DEV)
	{
		profileAsText = Base64Coder.encodeString(profileAsText);
	}
	
	// write the profile data file
	profileDataFile.writeString(profileAsText, false);
}
 
开发者ID:silconsystem,项目名称:Gensokyo_LibGdx,代码行数:21,代码来源:ProfileManager.java

示例9: loadGameStateSync

import com.badlogic.gdx.utils.Base64Coder; //导入依赖的package包/类
protected boolean loadGameStateSync(String fileId, ILoadGameStateResponseListener listener) {
    if (!isSessionActive() || !whisperSyncEnabled) {
        listener.gsGameStateLoaded(null);
        return false;
    }

    // wait some time to get data loaded from cloud
    int maxWaitTime = 5000;
    if (!loadedFromCloud)
        Gdx.app.log(GameCircleClient.GS_CLIENT_ID, "Waiting for cloud data to get synced...");

    while (!loadedFromCloud && maxWaitTime > 0) {
        SystemClock.sleep(100);
        maxWaitTime -= 100;
    }

    GameDataMap gameDataMap = AmazonGamesClient.getWhispersyncClient().getGameData();
    SyncableString savedData = gameDataMap.getLatestString(fileId);
    if (!savedData.isSet()) {
        Gdx.app.log(GameCircleClient.GS_CLIENT_ID, "No data in whispersync for " + fileId);
        listener.gsGameStateLoaded(null);
        return false;
    } else {
        Gdx.app.log(GameCircleClient.GS_CLIENT_ID, "Loaded " + fileId + "from whispersync successfully.");
        listener.gsGameStateLoaded(Base64Coder.decode(savedData.getValue()));
        return true;
    }
}
 
开发者ID:MrStahlfelge,项目名称:gdx-gamesvcs,代码行数:29,代码来源:GameCircleClient.java

示例10: send

import com.badlogic.gdx.utils.Base64Coder; //导入依赖的package包/类
@Override
public void send(Object object, SendMode mode) {
    if(!(object instanceof Packet)) throw new RuntimeException("All sent objects must be packets!");
    Packet p = (Packet)object;
    buffer.position(0);
    buffer.put(Registrator.getID(object.getClass()));
    p.write(buffer);
    int pos = buffer.position();
    buffer.position(0);
    byte[] out = new byte[pos];
    buffer.get(out);
    String string = new String(Base64Coder.encode(out));
    if(debug) UCore.log("Sending string: " + string);
    socket.send(string);
}
 
开发者ID:Anuken,项目名称:Mindustry,代码行数:16,代码来源:JavaWebsocketClient.java

示例11: send

import com.badlogic.gdx.utils.Base64Coder; //导入依赖的package包/类
@Override
public void send(Object object, SendMode mode){
    if(socket != null){
        try {
            synchronized (buffer) {
                buffer.position(0);
                if(debug) UCore.log("Sending object with ID " + Registrator.getID(object.getClass()));
                serializer.write(buffer, object);
                int pos = buffer.position();
                buffer.position(0);
                byte[] out = new byte[pos];
                buffer.get(out);
                String string = new String(Base64Coder.encode(out));
                if(debug) UCore.log("Sending string: " + string);
                socket.send(string);
            }
        }catch (Exception e){
            e.printStackTrace();
            connections.remove(this);
        }
    }else if (connection != null) {
        if (mode == SendMode.tcp) {
            connection.sendTCP(object);
        } else {
            connection.sendUDP(object);
        }
    }
}
 
开发者ID:Anuken,项目名称:Mindustry,代码行数:29,代码来源:KryoServer.java

示例12: send

import com.badlogic.gdx.utils.Base64Coder; //导入依赖的package包/类
@Override
public void send(Object object, SendMode mode) {
    if(!(object instanceof Packet)) throw new RuntimeException("All sent objects must be packets!");
    Packet p = (Packet)object;
    buffer.position(0);
    buffer.put(Registrator.getID(object.getClass()));
    p.write(buffer);
    int pos = buffer.position();
    buffer.position(0);
    byte[] out = new byte[pos];
    buffer.get(out);
    String string = new String(Base64Coder.encode(out));
    socket.send(string);
}
 
开发者ID:Anuken,项目名称:Mindustry,代码行数:15,代码来源:WebsocketClient.java

示例13: loadFromSlot

import com.badlogic.gdx.utils.Base64Coder; //导入依赖的package包/类
public static void loadFromSlot(int slot){
	if(Vars.gwt){
		String string = Settings.getString("save-"+slot+"-data");
		ByteArrayInputStream stream = new ByteArrayInputStream(Base64Coder.decode(string));
		load(stream);
	}else{
		load(fileFor(slot));
	}
}
 
开发者ID:Anuken,项目名称:Mindustry,代码行数:10,代码来源:SaveIO.java

示例14: readSlotMeta

import com.badlogic.gdx.utils.Base64Coder; //导入依赖的package包/类
public static DataInputStream readSlotMeta(int slot){
	if(Vars.gwt){
		String string = Settings.getString("save-"+slot+"-data");
		byte[] bytes = Base64Coder.decode(string);
		return new DataInputStream(new ByteArrayInputStream(bytes));
	}else{
		return new DataInputStream(fileFor(slot).read());
	}
}
 
开发者ID:Anuken,项目名称:Mindustry,代码行数:10,代码来源:SaveIO.java

示例15: createTextureFromBytes

import com.badlogic.gdx.utils.Base64Coder; //导入依赖的package包/类
/**
 * Creates texture region from byte[].
 * <p>
 * GWT platform requires additional step (as far as i know) to deal with Pixmap. It is need to load Image element
 * and wait until it is loaded.
 *
 * @param bytes    Image byte[] representation, not null
 * @param consumer Consumer where you should deal with region, not null
 */
public static void createTextureFromBytes(byte[] bytes, final Consumer<TextureRegion> consumer)
{
    String base64 = "data:image/png;base64," + new String(Base64Coder.encode(bytes));
    final Image image = new Image();
    image.setVisible(false);
    image.addLoadHandler(new LoadHandler()
    {
        @Override
        public void onLoad(LoadEvent event)
        {
            ImageElement imageElement = image.getElement().cast();
            Pixmap pixmap = new Pixmap(imageElement);
            Gdx.app.log("ImageHelper", "pixmap: " + pixmap.getWidth() + "/" + pixmap.getHeight());
            final int orgWidth = pixmap.getWidth();
            final int orgHeight = pixmap.getHeight();
            int width = MathUtils.nextPowerOfTwo(orgWidth);
            int height = MathUtils.nextPowerOfTwo(orgHeight);
            final Pixmap potPixmap = new Pixmap(width, height, pixmap.getFormat());
            potPixmap.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight());
            pixmap.dispose();
            TextureRegion region = new TextureRegion(new Texture(potPixmap), 0, 0, orgWidth, orgHeight);
            potPixmap.dispose();
            RootPanel.get().remove(image);
            consumer.accept(region);
        }
    });
    image.setUrl(base64);
    RootPanel.get().add(image);
}
 
开发者ID:mk-5,项目名称:gdx-fireapp,代码行数:39,代码来源:ImageHelper.java


注:本文中的com.badlogic.gdx.utils.Base64Coder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。