Esempio n. 1
0
  public static void loadPlayer(Registry registry) {
    Player p = (Player) getPlayers().get(player);
    if (p != null) {
      p.setTransient(registry);
    }

    GameController gc = registry.getGameController();
    registry.getPlayerManager().clearPlayers();
    registry.getPlayerManager().registerPlayer(p);
    BlockManager bm = (BlockManager) blockManagers.get(player);
    bm.name = "Saved";
    bm = (BlockManager) bm.clone();
    bm.name = "Clone";
    bm.setTransient(registry);
    gc.setBlockManager(bm);
    PlaceableManager pm = (PlaceableManager) placeableManagers.get(player).clone();
    gc.setPlaceableManager(pm);
    MonsterManager mm = (MonsterManager) monsterManagers.get(player).clone();
    mm.setTransient(registry);
    gc.setMonsterManager(mm);

    if (p != null) {
      p.resetPlayer();
    }

    // unloadUnused();
  }
Esempio n. 2
0
  public static boolean save() {
    if (registry.isSaving) {
      return false;
    }

    boolean status = true;

    registry.isSaving = true;

    resolutions.add("800x600");
    resolutions.add("1024x768");
    resolutions.add("1152x864");
    resolutions.add("1280x720");
    resolutions.add("1280x768");
    resolutions.add("1280x800");
    resolutions.add("1280x960");
    resolutions.add("1280x1024");
    resolutions.add("1360x768");
    resolutions.add("1366x768");
    resolutions.add("1440x900");
    resolutions.add("1600x900");
    resolutions.add("1600x1024");
    resolutions.add("1680x1050");
    resolutions.add("1920x1080");
    resolutions.add("1920x1200");
    // resolutions.add("Full Screen");

    // try to save the settings file
    try {
      FileOutputStream settingsFile = new FileOutputStream("SettingsTemp.dat");
      ObjectOutputStream settings = new ObjectOutputStream(settingsFile);

      settings.writeObject(new Integer(1)); // settings file version
      settings.writeObject(new Integer(resolution));
      if (volumeMusic == 0) {
        settings.writeObject(new Integer(-1));
      } else {
        settings.writeObject(new Integer(volumeMusic));
      }
      if (volumeFX == 0) {
        settings.writeObject(new Integer(-1));
      } else {
        settings.writeObject(new Integer(volumeFX));
      }
      settings.writeObject(new Integer(buttonMoveRight));
      settings.writeObject(new Integer(buttonMoveLeft));
      settings.writeObject(new Integer(buttonJump));
      settings.writeObject(new Integer(buttonAction));
      settings.writeObject(new Integer(buttonRobot));
      settings.writeObject(new Integer(buttonInventory));
      settings.writeObject(new Integer(buttonPause));

      settings.close();

      moveFile("SettingsTemp.dat", "Settings.dat");
      EIError.debugMsg("Saved Settings", EIError.ErrorLevel.Notice);
    } catch (Exception e) {
      status = false;
      EIError.debugMsg("Couldn't save settings " + e.getMessage(), EIError.ErrorLevel.Error);
    }

    // try to save the players
    for (int i = 1; i <= NUMBER_OF_PLAYER_SLOTS; i++) {
      try {
        if (player == i - 1) {
          FileOutputStream playerFile = new FileOutputStream("PlayerTemp.dat");
          ObjectOutputStream playerInfo = new ObjectOutputStream(playerFile);

          playerInfo.writeObject(new Integer(2)); // settings file version
          playerInfo.writeObject(players.get(i - 1));
          if (registry.getGameController().multiplayerMode != GameController.MultiplayerMode.CLIENT
              && player == i - 1) {
            blockManagers.set(i - 1, registry.getBlockManager());
            placeableManagers.set(i - 1, registry.getPlaceableManager());
            monsterManagers.set(i - 1, registry.getMonsterManager());
          }
          playerInfo.writeObject(blockManagers.get(i - 1));
          playerInfo.writeObject(placeableManagers.get(i - 1));
          playerInfo.writeObject(monsterManagers.get(i - 1));

          playerInfo.close();

          moveFile("PlayerTemp.dat", "Player" + i + ".dat");
          EIError.debugMsg("Saved Player " + i, EIError.ErrorLevel.Notice);
        }
      } catch (Exception e) {
        status = false;
        EIError.debugMsg(
            "Couldn't save Player " + i + " " + e.getMessage(), EIError.ErrorLevel.Error);
      }
    }

    registry.isSaving = false;

    return status;
  }