Skip to content

Commit

Permalink
make it work
Browse files Browse the repository at this point in the history
  • Loading branch information
scenemax3d committed Jul 23, 2024
1 parent 18345d2 commit 5b538b7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 57 deletions.
Binary file modified libs/scenemax_parser.jar
Binary file not shown.
63 changes: 26 additions & 37 deletions src/main/java/com/scenemaxeng/FullscreenGameActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,13 @@ protected void onDestroy() {
@Override
protected void onStart() {
super.onStart();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if(!destroyed) {
startGame();
}
}
},1000);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

com.scenemaxeng.Util.setContext(this);
importProgram();

setContentView(R.layout.activity_fullscreen_game);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
Expand Down Expand Up @@ -154,9 +145,16 @@ public void onUp() {
}
});

importProgram(new Runnable() {
@Override
public void run() {
startGame();
}
});

}

private void importProgram() {
private void importProgram(Runnable done) {
InputStream is = this.getResources().openRawResource(R.raw.code);
File code = new File(this.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),"code.zip");
System.out.println("copy code.zip to: " + code.getAbsolutePath());
Expand All @@ -173,7 +171,7 @@ public void done(Object res) {
System.out.println("done importing code.zip. received config: "+obj.toString(2));
FullscreenGameActivity.this.targetScriptPath = obj.getString("targetScriptPath");
FullscreenGameActivity.this.resourcesHash = obj.getString("resourcesHash");

done.run();
} catch (JSONException e) {
e.printStackTrace();
}
Expand All @@ -198,21 +196,19 @@ private void startGame() {
}

showJmeProjectorFragment();
File targetFile = new File(this.targetScriptPath);
if(targetFile.exists()) {
runOnUiThread(new Runnable() {
@Override
public void run() {
String code = Util.readFile(targetFile);
code=code.replaceFirst("^canvas\\.size\\s+((?<val1>\\d+),(?<val2>\\d+))","");;
code = applyMacros(code);
String workingFolder = targetFile.getParentFile().getAbsolutePath();
getJmeFragment().runScript(code, workingFolder);
app = (SceneMaxApp) getJmeFragment().getJmeApplication();
}
});
new Handler().postDelayed(() -> {
File targetFile = new File(this.targetScriptPath);
if(targetFile.exists()) {
String code = Util.readFile(targetFile);
code=code.replaceFirst("^canvas\\.size\\s+((?<val1>\\d+),(?<val2>\\d+))","");;
code = applyMacros(code);
String workingFolder = targetFile.getParentFile().getAbsolutePath();
getJmeFragment().runScript(code, workingFolder);
app = (SceneMaxApp) getJmeFragment().getJmeApplication();

}
}, 5000);

}
}

private String applyMacros(String code) {
Expand Down Expand Up @@ -249,22 +245,15 @@ private JmeProjectorFragment getJmeFragment() {

private void showJmeProjectorFragment() {

runOnUiThread(new Runnable() {
@Override
public void run() {
List<Fragment> fragments = getFragmentManager().getFragments();

jmeFragment = new JmeProjectorFragment();
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.frame, jmeFragment);
fragmentTransaction.commitAllowingStateLoss();
List<Fragment> fragments = getFragmentManager().getFragments();

}
});
jmeFragment = new JmeProjectorFragment();
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.frame, jmeFragment);
fragmentTransaction.commitAllowingStateLoss();

}


public long download(String url, File targetFolder, String title) {

try {
Expand Down
40 changes: 20 additions & 20 deletions src/main/java/com/scenemaxeng/JmeProjectorFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,17 @@
import java.util.regex.Pattern;

public class JmeProjectorFragment extends AndroidHarnessFragment {

//private IProjectorListener projListener = null;
private String startScript;
private String startWorkingFolder;

public JmeProjectorFragment() {
appClass=SceneMaxApp.class.getName();
}

// public void setProjectorListener(IProjectorListener listener) {
// this.projListener=listener;
// }

@Override
public void onStart() {
super.onStart();

final SceneMaxApp app=(SceneMaxApp)this.getJmeApplication();

}

public void clearScene() {
Expand All @@ -38,25 +32,31 @@ public void clearScene() {
}

public void runScript(String script, String workingFolder) {
SceneMaxApp app=(SceneMaxApp)this.getJmeApplication();
if(app == null) {
this.startScript = script;
this.startWorkingFolder = workingFolder;
return;
}

this.startScript = null;
this.startWorkingFolder = null;

// remove canvas size & window mode commands for Android execution
script=setCanvasSize(script);
script=setWindowMode(script);

SceneMaxApp app=(SceneMaxApp)this.getJmeApplication();
if(app!=null) {
File wf = new File(workingFolder);
File projFolder = wf.getParentFile().getParentFile();
File resourcesFolder = new File(projFolder,"resources");
AssetsMapping am = new AssetsMapping(this.getContext(),resourcesFolder.getAbsolutePath());
app.setAssetsMapping(am);
app.setWorkingFolder(workingFolder);
File wf = new File(workingFolder);
File projFolder = wf.getParentFile().getParentFile();
File resourcesFolder = new File(projFolder,"resources");
AssetsMapping am = new AssetsMapping(this.getContext(),resourcesFolder.getAbsolutePath());
app.setAssetsMapping(am);
app.setWorkingFolder(workingFolder);

File cf = new File(this.getContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),"common");
app.setCommonFolder(cf.getAbsolutePath());
File cf = new File(this.getContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),"common");
app.setCommonFolder(cf.getAbsolutePath());

app.run(script);
}
app.run(script);
}

public void stopScript() {
Expand Down

0 comments on commit 5b538b7

Please sign in to comment.