Exemple #1
0
  static {
    ResourceLoader.addResourceLocation(
        new ResourceLocation() {
          public URL getResource(String ref) {
            return this.getClass().getResource(ref);
          }

          public InputStream getResourceAsStream(String ref) {
            return this.getClass().getResourceAsStream(ref);
          }
        });
  }
  @Override
  public void init(GameContainer container, StateBasedGame game) throws SlickException {
    super.init(container, game);

    this.game = game;

    // add asset-folder to the ResourceLocators of nifty and slick2d
    ResourceLoader.addResourceLocation(new FileSystemLocation(new File(menuAssetPath)));
    org.newdawn.slick.util.ResourceLoader.addResourceLocation(
        new org.newdawn.slick.util.FileSystemLocation(new File(menuAssetPath)));
    // read the nifty-xml-fiel
    fromXml(menuNiftyXMLFile, ResourceLoader.getResourceAsStream(menuNiftyXMLFile), this);
  }
Exemple #3
0
  /** Launches opsu!. */
  public static void main(String[] args) {
    // log all errors to a file
    Log.setVerbose(false);
    try {
      DefaultLogSystem.out = new PrintStream(new FileOutputStream(Options.LOG_FILE, true));
    } catch (FileNotFoundException e) {
      Log.error(e);
    }
    Thread.setDefaultUncaughtExceptionHandler(
        new Thread.UncaughtExceptionHandler() {
          @Override
          public void uncaughtException(Thread t, Throwable e) {
            ErrorHandler.error("** Uncaught Exception! **", e, true);
          }
        });

    // parse configuration file
    Options.parseOptions();

    // only allow a single instance
    try {
      SERVER_SOCKET = new ServerSocket(Options.getPort(), 1, InetAddress.getLocalHost());
    } catch (UnknownHostException e) {
      // shouldn't happen
    } catch (IOException e) {
      ErrorHandler.error(
          String.format(
              "opsu! could not be launched for one of these reasons:\n"
                  + "- An instance of opsu! is already running.\n"
                  + "- Another program is bound to port %d. "
                  + "You can change the port opsu! uses by editing the \"Port\" field in the configuration file.",
              Options.getPort()),
          null,
          false);
      System.exit(1);
    }

    // set path for lwjgl natives - NOT NEEDED if using JarSplice
    File nativeDir = new File("./target/natives/");
    if (nativeDir.isDirectory())
      System.setProperty("org.lwjgl.librarypath", nativeDir.getAbsolutePath());

    // set the resource paths
    ResourceLoader.addResourceLocation(new FileSystemLocation(new File("./res/")));

    // initialize databases
    try {
      DBController.init();
    } catch (UnsatisfiedLinkError e) {
      errorAndExit(e, "The databases could not be initialized.");
    }

    // check if just updated
    if (args.length >= 2) Updater.get().setUpdateInfo(args[0], args[1]);

    // check for updates
    if (!Options.isUpdaterDisabled()) {
      new Thread() {
        @Override
        public void run() {
          try {
            Updater.get().checkForUpdates();
          } catch (IOException e) {
            Log.warn("Check for updates failed.", e);
          }
        }
      }.start();
    }

    // start the game
    try {
      // loop until force exit
      while (true) {
        Opsu opsu = new Opsu("opsu!");
        Container app = new Container(opsu);

        // basic game settings
        Options.setDisplayMode(app);
        String[] icons = {"icon16.png", "icon32.png"};
        app.setIcons(icons);
        app.setForceExit(true);

        app.start();

        // run update if available
        if (Updater.get().getStatus() == Updater.Status.UPDATE_FINAL) {
          close();
          Updater.get().runUpdate();
          break;
        }
      }
    } catch (SlickException e) {
      errorAndExit(e, "An error occurred while creating the game container.");
    }
  }