1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-12-25 09:30:35 +00:00

the Android version is now able to access honeycomb rules via assets

This commit is contained in:
Zeno Rogue 2021-06-01 14:24:22 +02:00
parent 3c3c95e072
commit 9ebd7d98d5
4 changed files with 36 additions and 2 deletions

View File

@ -48,6 +48,8 @@ import android.widget.FrameLayout.LayoutParams;
import android.widget.Toast; import android.widget.Toast;
import android.util.Log; import android.util.Log;
import java.io.InputStream;
public class HyperRogue extends Activity implements SensorEventListener { public class HyperRogue extends Activity implements SensorEventListener {
private static final int RESULT_SETTINGS = 1; private static final int RESULT_SETTINGS = 1;
@ -627,6 +629,18 @@ public class HyperRogue extends Activity implements SensorEventListener {
return bounds.width(); return bounds.width();
} }
public byte[] getAsset(String s) {
try {
InputStream is = getAssets().open(s);
int length = is.available();
byte[] data = new byte[length];
is.read(data);
return data;
} catch (IOException e) {
return null;
}
}
private SensorManager mSensorManager; private SensorManager mSensorManager;
private Sensor mSensor; private Sensor mSensor;
// private final float[] mAccelerometerReading = new float[3]; // private final float[] mAccelerometerReading = new float[3];

View File

@ -45,6 +45,7 @@ void special_log(char c);
#include <string> #include <string>
namespace hr { namespace hr {
std::string get_asset(const std::string &str);
void gdpush(int t); void gdpush(int t);
void shareScore(MOBPAR_FORMAL); void shareScore(MOBPAR_FORMAL);
@ -242,6 +243,20 @@ Java_com_roguetemple_hyperroid_HyperRogue_initGame(MOBPAR_FORMAL) {
JNIEnv *tw_env; jobject tw_thiz; JNIEnv *tw_env; jobject tw_thiz;
string get_asset(const string &str) {
jclass cls = tw_env->GetObjectClass(tw_thiz);
jmethodID mid = tw_env->GetMethodID(cls, "getAsset", "(Ljava/lang/String;)[B");
jobject jstr = tw_env->NewStringUTF(str.c_str());
jbyteArray arr = (jbyteArray) tw_env->CallObjectMethod(tw_thiz, mid, jstr);
tw_env->DeleteLocalRef(jstr);
tw_env->DeleteLocalRef(cls);
jsize len = tw_env->GetArrayLength(arr);
jbyte* data = tw_env->GetByteArrayElements(arr, NULL);
string s((char*) & (data[0]), len);
tw_env->DeleteLocalRef(arr);
return s;
}
int textwidth(int siz, const string &str) { int textwidth(int siz, const string &str) {
jclass cls = tw_env->GetObjectClass(tw_thiz); jclass cls = tw_env->GetObjectClass(tw_thiz);
jmethodID mid = tw_env->GetMethodID(cls, "getTextWidth", "(Ljava/lang/String;I)I"); jmethodID mid = tw_env->GetMethodID(cls, "getTextWidth", "(Ljava/lang/String;I)I");

View File

@ -1,6 +1,7 @@
#!/bin/sh #!/bin/sh
mkdir -p app/src/main/assets/sounds mkdir -p app/src/main/assets/sounds
cp ../sounds/* app/src/main/assets/sounds/ cp ../sounds/* app/src/main/assets/sounds/
cp ../honeycomb-rules-*.txt app/src/main/assets/
mkdir -p app/src/main/res/raw/ mkdir -p app/src/main/res/raw/
#for x in caves crossroads desert graveyard hell icyland jungle laboratory mirror rlyeh #for x in caves crossroads desert graveyard hell icyland jungle laboratory mirror rlyeh

View File

@ -941,12 +941,17 @@ EX namespace reg3 {
vector<int> otherpos; vector<int> otherpos;
void load_ruleset(string fname) { void load_ruleset(string fname) {
string buf;
#if ISANDROID
buf = get_asset(fname);
#else
FILE *f = fopen(fname.c_str(), "rb"); FILE *f = fopen(fname.c_str(), "rb");
if(!f) f = fopen((rsrcdir + fname).c_str(), "rb"); if(!f) f = fopen((rsrcdir + fname).c_str(), "rb");
string buf;
buf.resize(1000000); buf.resize(1000000);
int qty = fread(&buf[0], 1, 1000000, f); int qty = fread(&buf[0], 1, 1000000, f);
buf.resize(qty); buf.resize(qty);
fclose(f);
#endif
shstream ins(decompress_string(buf)); shstream ins(decompress_string(buf));
dynamicval<bool> q(fieldpattern::use_quotient_fp, true); dynamicval<bool> q(fieldpattern::use_quotient_fp, true);
@ -955,7 +960,6 @@ EX namespace reg3 {
hread(ins, root); hread(ins, root);
hread(ins, children); hread(ins, children);
hread(ins, other); hread(ins, other);
fclose(f);
} }
/** \brief address = (fieldvalue, state) */ /** \brief address = (fieldvalue, state) */