Ejemplo n.º 1
0
  /** prepares Lua state and some bookkeeping */
  protected void prepareState() throws IOException {
    ui.debugMsg("Creating state...\n");
    state = new LuaState(System.out);

    /*write("Registering base libs...\n");
    BaseLib.register(state);
    MathLib.register(state);
    StringLib.register(state);
    CoroutineLib.register(state);
    OsLib.register(state);*/

    ui.debugMsg("Building javafunc map...\n");
    savegame.buildJavafuncMap(state.getEnvironment());

    ui.debugMsg("Loading stdlib...");
    InputStream stdlib = getClass().getResourceAsStream("/cz/matejcik/openwig/stdlib.lbc");
    LuaClosure closure = LuaPrototype.loadByteCode(stdlib, state.getEnvironment());
    ui.debugMsg("calling...\n");
    state.call(closure, null, null, null);
    stdlib.close();
    stdlib = null;

    ui.debugMsg("Registering WIG libs...\n");
    WherigoLib.register(state);

    ui.debugMsg("Building event queue...\n");
    eventRunner = new BackgroundRunner(true);
    eventRunner.setQueueListener(
        new Runnable() {
          public void run() {
            ui.refresh();
          }
        });
  }
Ejemplo n.º 2
0
 public void run() {
   // perform the actual sync
   try {
     ui.blockForSaving();
     savegame.store(state.getEnvironment());
   } catch (IOException e) {
     log("STOR: save failed: " + e.toString(), LOG_WARN);
     ui.showError("Sync failed.\n" + e.getMessage());
   } finally {
     ui.unblock();
   }
 }
Ejemplo n.º 3
0
  /** invokes creation of clean new game environment */
  private void newGame() throws IOException {
    // starting game normally
    ui.debugMsg("Loading gwc...");
    if (gwcfile == null) throw new IOException("invalid cartridge file");

    ui.debugMsg("pre-setting properties...");
    player.rawset("CompletionCode", gwcfile.code);
    player.rawset("Name", gwcfile.member);

    ui.debugMsg("loading code...");
    byte[] lbc = gwcfile.getBytecode();

    ui.debugMsg("parsing...");
    LuaClosure closure =
        LuaPrototype.loadByteCode(new ByteArrayInputStream(lbc), state.getEnvironment());

    ui.debugMsg("calling...\n");
    state.call(closure, null, null, null);
    lbc = null;
    closure = null;
  }
Ejemplo n.º 4
0
 /** invokes game restore */
 private void restoreGame() throws IOException {
   ui.debugMsg("Restoring saved state...");
   cartridge = new Cartridge();
   savegame.restore(state.getEnvironment());
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {

    // System.loadLibrary("luajava-1.1");

    // 設定橫向螢幕
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    this.getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    this.getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    this.registerReceiver(this.mBatInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

    L = LuaStateFactory.newLuaState();
    L.pushJavaObject(this);
    L.setGlobal("activity");

    res = getResources();
    conf = res.getConfiguration();

    conf.locale = Locale.TAIWAN;
    res.updateConfiguration(conf, null);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    appobject = this.getApplicationContext();

    surfaceView = (SurfaceView) findViewById(R.id.surfaceView1);
    surfaceHolder = surfaceView.getHolder();
    surfaceHolder.addCallback(this);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    ////////////////////////////////////////////////////////////////////////////////////////////

    /*bitmap2 = BitmapFactory.decodeResource(  getResources()    , R.raw.line  );

          surfaceView2 = (SurfaceView)findViewById(R.id.surface_level );
          surfaceHolder2 = surfaceView2.getHolder();

          SurfaceHolder.Callback  level_callback  = new SurfaceHolder.Callback()
          {

    	public void surfaceChanged(SurfaceHolder holder, int format,
    			int width, int height) {
    		//需要
    		 on_level_change(new float[3]);
    	}

    	public void surfaceCreated(SurfaceHolder holder) {
    	}

    	public void surfaceDestroyed(SurfaceHolder holder) {
    	}

          };

    surfaceHolder2.addCallback(  level_callback  );
          surfaceHolder2.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);  */

    //////////////////////////////////////////////////////////////////////////////////////////

    /*  sensormanager = (SensorManager) getSystemService(SENSOR_SERVICE);
         sensors =  sensormanager.getSensorList(Sensor.TYPE_ORIENTATION);

         SensorEventListener sl =new SensorEventListener ()
         {
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
    	//不需要
    }
    public void onSensorChanged(SensorEvent event) {
    	 on_level_change(event.values);
    }

         };
         sensormanager.registerListener  (   sl   ,  sensors.get(0) ,  SensorManager.SENSOR_DELAY_GAME  );
         */

    /////////////////////////////////////////////////////////////////////

    Button run_script = (Button) this.findViewById(R.id.run_script);
    run_script.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {

            if (is_video == true) {
              print_screen(res.getString(R.string.video_rec_ing));
              return;
            }

            if (is_audio == true) {
              print_screen(res.getString(R.string.audio_rec_ing));
              return;
            }

            if (lua_file == "") {
              print_screen(res.getString(R.string.file_load_no));
              return;
            }

            File f = new File("/sdcard/ez_Lua_Script_Camera/lua_scripts/" + lua_file);
            if (f.exists() == false) {
              print_screen(res.getString(R.string.file_load_fail));
              return;
            }
            ((TextView) findViewById(R.id.lua_file_screen)).setText(lua_file);
            all_pics = 0;
            ((TextView) findViewById(R.id.shutter_times_screen)).setText("拍攝張數 : 00000");
            (new lua_run()).start();
          }
        });

    Button about = (Button) this.findViewById(R.id.about);
    about.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {

            if (is_video == true) {
              print_screen(res.getString(R.string.video_rec_ing));
              return;
            }

            if (is_audio == true) {
              print_screen(res.getString(R.string.audio_rec_ing));
              return;
            }

            if (is_script_running == true) {
              print_screen(res.getString(R.string.script_running));
              return;
            }

            Intent i =
                new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse("http://dl.dropbox.com/u/61164954/homepage/ez_LSC/index.htm"));
            startActivity(i);
          }
        });

    Button audio_c = (Button) this.findViewById(R.id.audio);
    audio_c.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {

            if (is_script_running == true) {
              print_screen(res.getString(R.string.script_running));
              return;
            }

            if (is_video == true) {
              print_screen(res.getString(R.string.video_rec_ing));
              return;
            }

            if (is_audio == false) {
              print_screen(res.getString(R.string.audio_rec_start));
              CharSequence cs = res.getString(R.string.stop);
              Button keepa = (Button) findViewById(R.id.audio);
              keepa.setText(cs);
              is_audio = true;
              (new audio()).start();
            } else {
              arecorder.stop();
              is_audio = false;
              print_screen(res.getString(R.string.audio_rec_end));
              CharSequence xcs = res.getString(R.string.audio_rec);
              Button keepax = (Button) findViewById(R.id.audio);
              keepax.setText(xcs);
              camera.startPreview();
            }
          }
        });

    Button movie = (Button) this.findViewById(R.id.movie);
    movie.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {

            if (is_script_running == true) {
              print_screen(res.getString(R.string.script_running));
              return;
            }

            if (is_audio == true) {
              print_screen(res.getString(R.string.audio_rec_ing));
              return;
            }

            if (is_video == false) {
              print_screen(res.getString(R.string.video_rec_start));
              CharSequence cs = res.getString(R.string.stop);
              Button keepa = (Button) findViewById(R.id.movie);
              keepa.setText(cs);
              parameters.setFocusMode("continuous-video");
              camera.setParameters(parameters);
              is_video = true;
              (new video()).start();
            } else {
              recorder.stop();
              is_video = false;
              print_screen(res.getString(R.string.video_rec_end));
              CharSequence xcs = res.getString(R.string.video_rec);
              Button keepax = (Button) findViewById(R.id.movie);
              keepax.setText(xcs);
              camera.lock();
              camera.release();
              camera = Camera.open();
              parameters = camera.getParameters();
              parameters.setPreviewSize(640, 480);
              parameters.setPreviewFrameRate(30);
              parameters.setJpegQuality(100);
              parameters.setFocusMode("continuous-video");
              parameters.setPictureSize(2048, 1536);
              camera.setParameters(parameters);
              try {
                camera.setPreviewDisplay(surfaceHolder);
              } catch (IOException e) {
              }
              camera.startPreview();
            }
          }
        });

    Button lua = (Button) this.findViewById(R.id.lua);
    lua.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {

            if (is_script_running == true) {
              print_screen(res.getString(R.string.script_running));
              return;
            }

            if (is_audio == true) {
              print_screen(res.getString(R.string.audio_rec_ing));
              return;
            }

            if (is_video == true) {
              print_screen(res.getString(R.string.video_rec_ing));
              return;
            }
            show_choose_Dialog();
          }
        });

    test_caller();
    load_config();

    try {
      player.setDataSource("/sdcard/ez_Lua_Script_Camera/sound/shuttersound.ogg");
    } catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalStateException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    try {
      shutter_trigger.setDataSource("/sdcard/ez_Lua_Script_Camera/sound/trigger.wav");
    } catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalStateException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }