Develop Scripts

Robotmon ?

Robotmon scripts APIs

RBM library for beginner (auto support different resolution)

Raw APIs for efficiency, You should hold every thing yourself.

Web view APIs

Javascript interface for controlling Floating Window and Robotmon Service (JavascriptInterface.runScript();)

Javascript Events for receiving events from Floating Window and Robotmon Service (onLog())

GRPC Commands

GRPC commands for communicating with Robotmon Service. You can connect to robotmon service anywhere.

Robotmon Developer Tool

  1. Download Develop IDE (or Build it yourself)
  2. Unzip it (If using MAC OS, move app to Applications folder)
  3. Open It. Success!

Service Controller

IDE will receive broadcast from phones, and show on left side. If not received you can add a service by IP

You should choice one service (device) to start

If use emulator, you should forward port first, then connect to 127.0.0.1

adb forward tcp:8081 tcp:8081

Script Controller

Open JS file, and Run it (execute JS script in editor) or Stop it (call stop() function)

Script Editor

Simple JS editor, you can use other editor too

Just do a test!

console.log('Hello world!');

Then click 'Run'

Log

Show console log

Screen Controller

Start/Stop sync Screen.

  • Tap: tap screen by click
  • Color: get color info by click
  • Crop: crop an image (by selection) in to /sdcard/Robotmon/scripts/com.my.newProject/images (You may want to editor app name first) (This function is base on RBM library)

Floating window

After opening floating window by click scripts, it will do two things:

  1. Create a web view and load index.html file.
  2. Load index.js and inject to Robotmon Service.

(*** So index.js and index.html are independent ***)

There are 6 buttons on menu of Floating window. And onEvent will receive 6 events with them. You should control with them yourself.

  • Icon button - show/hide menu and inject event OnMenuClick
  • Start button - inject event OnPlayClick
  • Pause button - inject event OnPauseClick
  • Log button - show/hide log and inject event OnLogClick
  • Setting button - show/hide setting UI (web view) and inject event OnSettingClick
  • Close button - close script and inject event OnCloseClick

In index.html, you should put UI of settings in <body></body> and controller in <script></scripts> (like function onEvent(){})

Example

<html>
<!-- You can load any library here like jQuery -->
<script>
  function onEvent(eventType) {
    if (eventType == 'OnPlayClick') {
      JavaScriptInterface.runScript('start();'); // call start function in index.js
      // you can also put parameters like 'start(10, "run", "stop")'
    } else if (eventType == 'OnPauseClick') {
      JavaScriptInterface.runScript('stop();'); // call stop function in index.js
    }
  }
  function onLog(message) {
    console.log(message);
  }
</script>
<body>
  <div>Setting UI</div>
  <button>Setting</button>
</body>
</html>

More examples

Test Your Scripts

With IDE

You can just click Run in Developer Tool, then developer tool will send your scripts to Robotmon service and run it.

With Robotmon App (Web view APIs)

Preparing two file index.js and index.html (Or zip two file as index.zip) and put them into phone /sdcard/Robotmon/scripts/your.script.name/index.(js)(html)(zip)

Publish your scripts

1. Git fork and clone https://github.com/r2-studio/robotmon-scripts

2. Add your scripts in scripts folder

3. ZIP all your files as index.zip

4. Editor script-config.json and add information about your scripts

5. Commit and push to your branch

Make a pull request to https://github.com/r2-studio/robotmon-scripts


發Pull Request 中文教學

1 申請 GitHub 帳號 (已經有的可以不用再申請)

2 至 https://github.com/r2-studio/robotmon-scripts 點 fork (可以順便點一下星星)

此步驟會複製一份robotmon-scripts專案至自己的帳號下

3 可能需要安裝 GitHub tools (https://desktop.github.com/)

3 git clone https://github.com/{your GitHub account}/robotmon-scripts

4 git checkout -b {gameNameBranch}

gameNameBranch 是一個 branch name 可以自己取喜歡的名字

5 開新資料夾在 robotmon-scripts/scripts內 名字請命名 com.yourName.gameName

6 將 index.js index.html 和所有用到的圖檔資料夾壓縮成 index.zip 一起放到剛剛開的資料夾內

7 修改 script-config.json 新增一筆資料

8 git add .

將資料夾內的檔案全部新增到git內

9 git commit -m “your message”

將這個動作取一個名字像是 “add xxx game scripts”

10 git push origin gameName

push 剛剛的 branch 上去 GitHub

11 到 GitHub 上發 pull request 到 r2-studio/robotmon-scripts master