Skip to content

Commit 4200c60

Browse files
committed
Merge tag 'v155' into be
2 parents 2640e0a + e1ae143 commit 4200c60

File tree

27 files changed

+2919
-13
lines changed

27 files changed

+2919
-13
lines changed

arc-core/src/arc/Files.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ default String getCachePath(){
5353
return local("cache").absolutePath();
5454
}
5555

56+
/** @return on IOS, the internal path to the assets directory. Not used on other platforms. */
57+
default String getInternalStoragePath(){
58+
return "";
59+
}
60+
5661
/**
5762
* @return the external storage path directory. This is the SD card on Android and the home directory of the current user on
5863
* the desktop.

arc-core/src/arc/Input.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ public float axisTap(KeyBind key){
235235
public void getTextInput(TextInput input){
236236
}
237237

238+
/** @return on mobile, whether text input is currently being fetched. Not implemented on other platforms. */
239+
public boolean isShowingTextInput(){
240+
return false;
241+
}
242+
238243
/**
239244
* Sets the on-screen keyboard visible if available. Only applicable on mobile.
240245
* @param visible visible or not
@@ -357,6 +362,11 @@ public Orientation getNativeOrientation(){
357362
return Orientation.landscape;
358363
}
359364

365+
/** Internal method for looking up a key's name based on keyboard layout. Internal use only - use {@link KeyCode#getName()} instead. */
366+
public String getKeyName(KeyCode code){
367+
return code.value;
368+
}
369+
360370
public enum Orientation{
361371
landscape, portrait
362372
}

arc-core/src/arc/audio/Audio.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public class Audio implements Disposable{
1515
public int defaultSoundMaxConcurrent = 6;
1616

1717
boolean initialized;
18-
float sfxVolume = 0f;
1918

19+
public float sfxVolume = 0f;
2020
/** Global bus for all sounds. */
2121
public AudioBus soundBus = new AudioBus();
2222
/** Global bus for all music. */

arc-core/src/arc/audio/Music.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package arc.audio;
22

33
import arc.*;
4+
import arc.Files.*;
45
import arc.files.*;
56
import arc.util.*;
67

arc-core/src/arc/input/KeyCode.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package arc.input;
22

3+
import arc.*;
34
import arc.input.KeyBind.*;
45

56
/** Enum for storing input codes of mouse, keyboard and controllers. */
@@ -206,6 +207,8 @@ public enum KeyCode implements KeybindValue{
206207
public final String value;
207208
public final boolean axis;
208209

210+
private String cachedName;
211+
209212
KeyCode(KeyType type, String value){
210213
this(type, value, false);
211214
}
@@ -221,9 +224,18 @@ public static KeyCode byOrdinal(int id){
221224
return all[id];
222225
}
223226

227+
/** @return a human-friendly name based on keyboard layout. */
228+
public String getName(){
229+
if(cachedName == null){
230+
cachedName = Core.input == null ? value : Core.input.getKeyName(this);
231+
if(cachedName == null || cachedName.isEmpty()) cachedName = value;
232+
}
233+
return cachedName;
234+
}
235+
224236
@Override
225237
public String toString(){
226-
return value;
238+
return getName();
227239
}
228240

229241
public enum KeyType{

arc-core/src/arc/math/geom/Geometry.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@ public static <T extends Position> T findClosest(float x, float y, Iterable<T> l
112112
return closest;
113113
}
114114

115+
public static <T extends Position> T findClosest(float x, float y, Iterable<T> list, Boolf<T> predicate){
116+
T closest = null;
117+
float cdist = 0f;
118+
for(T t : list){
119+
if(!predicate.get(t)) continue;
120+
float dst = t.dst2(x, y);
121+
if(closest == null || dst < cdist){
122+
closest = t;
123+
cdist = dst;
124+
}
125+
}
126+
return closest;
127+
}
128+
115129
public static <T extends Position> T findFurthest(float x, float y, Iterable<T> list){
116130
T furthest = null;
117131
float fdist = 0f;
@@ -125,6 +139,20 @@ public static <T extends Position> T findFurthest(float x, float y, Iterable<T>
125139
return furthest;
126140
}
127141

142+
public static <T extends Position> T findFurthest(float x, float y, Iterable<T> list, Boolf<T> predicate){
143+
T furthest = null;
144+
float fdist = 0f;
145+
for(T t : list){
146+
if(!predicate.get(t)) continue;
147+
float dst = t.dst2(x, y);
148+
if(furthest == null || dst > fdist){
149+
furthest = t;
150+
fdist = dst;
151+
}
152+
}
153+
return furthest;
154+
}
155+
128156
public static Vec2[] pixelCircle(float tindex){
129157
return pixelCircle(tindex, (index, x, y) -> Mathf.dst(x, y, index, index) < index - 0.5f);
130158
}

arc-core/src/arc/util/Strings.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.*;
88
import java.net.*;
99
import java.nio.charset.*;
10+
import java.util.*;
1011
import java.util.regex.*;
1112

1213
public class Strings{
@@ -285,6 +286,30 @@ public static String join(String separator, Iterable<String> strings){
285286
public static int levenshtein(String x, String y){
286287
int[][] dp = new int[x.length() + 1][y.length() + 1];
287288

289+
for(int i = 0; i <= x.length(); i++){
290+
for(int j = 0; j <= y.length(); j++){
291+
if(i == 0){
292+
dp[i][j] = j;
293+
}else if(j == 0){
294+
dp[i][j] = i;
295+
}else{
296+
dp[i][j] = Math.min(Math.min(dp[i - 1][j - 1] + (x.charAt(i - 1) == y.charAt(j - 1) ? 0 : 1),
297+
dp[i - 1][j] + 1),
298+
dp[i][j - 1] + 1);
299+
}
300+
}
301+
}
302+
303+
return dp[x.length()][y.length()];
304+
}
305+
306+
/** Returns the case-independent biased levenshtein distance between two strings. */
307+
public static float biasedLevenshtein(String x, String y){
308+
x = x.toLowerCase(Locale.ROOT);
309+
y = y.toLowerCase(Locale.ROOT);
310+
311+
int[][] dp = new int[x.length() + 1][y.length() + 1];
312+
288313
for(int i = 0; i <= x.length(); i++){
289314
for(int j = 0; j <= y.length(); j++){
290315
if(i == 0){
@@ -300,7 +325,11 @@ public static int levenshtein(String x, String y){
300325
}
301326
}
302327

303-
return dp[x.length()][y.length()];
328+
float output = dp[x.length()][y.length()];
329+
if(y.startsWith(x) || x.startsWith(y)){
330+
return output / 3f;
331+
}
332+
return (y.contains(x) || x.contains(y)) ? output / 1.5f : output;
304333
}
305334

306335
public static String animated(float time, int length, float scale, String replacement){

arc-core/src/arc/util/serialization/Jval.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,15 @@ static Jval tryParseNumber(StringBuilder value, boolean stopAtNext){
716716
while(idx < len && isDigit(value.charAt(idx))) idx++;
717717
}
718718

719+
// exp
720+
if(idx < len && Character.toLowerCase(value.charAt(idx)) == 'e'){
721+
idx++;
722+
if(idx < len && (value.charAt(idx) == '+' || value.charAt(idx) == '-')) idx++;
723+
724+
if(idx >= len || !isDigit(value.charAt(idx++))) return null;
725+
while(idx < len && isDigit(value.charAt(idx))) idx++;
726+
}
727+
719728
int last = idx;
720729
while(idx < len && isWhiteSpace(value.charAt(idx))) idx++;
721730

arc-core/test/utils/JvalTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010

1111
public class JvalTest{
1212

13+
@Test
14+
public void parseExponential(){
15+
Jval val = Jval.read("{a: 1e-4, b: 1e92}");
16+
assertEquals(1e-4f, val.getDouble("a", 0f), 0.00001f);
17+
assertEquals(1e92, val.getDouble("b", 0f), 0.00001f);
18+
}
19+
1320
@Test
1421
public void parseUnquotedStringArray(){
1522
Jval val = Jval.read("{\nkey: [result, result2]\n}");

backends/backend-android/src/arc/backend/android/AndroidInput.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ protected TouchEvent newObject(){
7777
private int mouseLastX = 0;
7878
private int mouseLastY = 0;
7979
private boolean justTouched = false;
80+
private boolean showingTextInput;
8081
private long currentEventTimeStamp = System.nanoTime();
8182
private Vec3 accel = new Vec3(), gyro = new Vec3(), orient = new Vec3();
8283
private SensorEventListener accelerometerListener;
@@ -157,7 +158,10 @@ public void getTextInput(TextInput info){
157158
alert.setView(input);
158159
alert.setPositiveButton(context.getString(android.R.string.ok), (dialog, whichButton) -> Core.app.post(() -> info.accepted.get(input.getText().toString())));
159160
alert.setNegativeButton(context.getString(android.R.string.cancel), (dialog, whichButton) -> Core.app.post(() -> info.canceled.run()));
160-
alert.setOnCancelListener(arg0 -> Core.app.post(() -> info.canceled.run()));
161+
alert.setOnCancelListener(a -> Core.app.post(() -> info.canceled.run()));
162+
alert.setOnDismissListener(a -> showingTextInput = false);
163+
164+
showingTextInput = true;
161165
AlertDialog dialog = alert.show();
162166

163167
input.addTextChangedListener(new TextWatcher(){
@@ -190,6 +194,11 @@ public void afterTextChanged(Editable editable){
190194
});
191195
}
192196

197+
@Override
198+
public boolean isShowingTextInput(){
199+
return showingTextInput;
200+
}
201+
193202
@Override
194203
public int mouseX(){
195204
synchronized(this){

0 commit comments

Comments
 (0)