Skip to content

Commit 7258d2d

Browse files
committed
Make object browser functional
1 parent 0973b2e commit 7258d2d

10 files changed

Lines changed: 175 additions & 23 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
- name: Setup Gradle
4747
uses: gradle/gradle-build-action@v2
4848
with:
49-
gradle-version: 8.7
49+
gradle-version: 8.12
5050

5151
- name: Setup Java
5252
uses: actions/setup-java@v3

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
android:exported="false"
3535
android:label="@string/help"
3636
android:theme="@style/Theme.PCSimulatorSaveEditor" />
37+
<activity
38+
android:name=".BrowserActivity"
39+
android:exported="false"
40+
android:label="@string/help"
41+
android:theme="@style/Theme.PCSimulatorSaveEditor" />
3742
<activity
3843
android:name=".MainActivity2"
3944
android:exported="true"

app/src/main/java/com/mokkachocolata/pcsimulatorsaveeditorandroidport/MainActivity2.kt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -660,18 +660,18 @@ class MainActivity2 : AppCompatActivity() {
660660
override fun onOptionsItemSelected(item: MenuItem): Boolean {
661661
when (item.itemId) {
662662
R.id.explorer -> {
663-
val text = input.text.toString()
664-
if (text.lines().size < 2) return false
665-
val jsonObject = JSONObject(text.lines()[1])
663+
if (input.text.lines().size < 2) return false
664+
val jsonObject = JSONObject(input.text.lines()[1])
666665
val itemArray = jsonObject.getJSONArray("itemData")
667666
val lists = arrayListOf<String>()
668667
for (i in 0 until itemArray.length()) {
669668
val item = itemArray.getJSONObject(i)
670669
val spawnId = item.getString("spawnId")
671670
lists.add(spawnId)
672671
}
673-
dialog("Object Browser", null, null, {_,_->}, null, "Close", lists.toTypedArray()) {_, i ->
674-
672+
dialog(resources.getString(R.string.object_explorer), null, null, {_,_->}, null, "Close", lists.toTypedArray()) {_, i ->
673+
val dialog = ObjectFragment(itemArray.getJSONObject(i), input, i)
674+
dialog.show(supportFragmentManager, "objectFragment")
675675
}
676676
}
677677
R.id.mods -> {
@@ -713,8 +713,7 @@ class MainActivity2 : AppCompatActivity() {
713713
dialog("Mods", null, {_, _ ->
714714
pickMod.launch(arrayOf("application/octet-stream"))
715715
}, {_,_->}, "Add Mod", "Close", strArray.toTypedArray()) {_, i ->
716-
val dialog = ModFragment()
717-
dialog.mod = mods[i]
716+
val dialog = ModFragment(mods[i])
718717
dialog.show(supportFragmentManager, "modFragment")
719718
dialog.deleteListener = {
720719
files[i].delete()
@@ -741,11 +740,16 @@ class MainActivity2 : AppCompatActivity() {
741740
R.id.clear -> {
742741
// Clear all cardboard boxes
743742
val text = input.text.toString()
743+
744744
val lines = text.lines()
745745
val jsonObject = JSONObject(lines[1])
746746
val itemArray = jsonObject.getJSONArray("itemData")
747-
for (i in 0 until itemArray.length()) if (i < itemArray.length() && (itemArray.getJSONObject(i).getString("spawnId") == "CardboardBox" || itemArray.getJSONObject(i).getString("spawnId") == "LongCardboardBox" || itemArray.getJSONObject(i).getString("spawnId") == "CardboardBox 2")) itemArray.remove(i)
748-
for (i in 0 until itemArray.length()) if (i < itemArray.length() && (itemArray.getJSONObject(i).getString("spawnId").contains("Part_") || itemArray.getJSONObject(i).getString("spawnId") == "Part")) itemArray.remove(i)
747+
for (i in 0 until itemArray.length())
748+
if (i < itemArray.length() && (itemArray.getJSONObject(i).getString("spawnId") == "CardboardBox" || itemArray.getJSONObject(i).getString("spawnId") == "LongCardboardBox" || itemArray.getJSONObject(i).getString("spawnId") == "CardboardBox 2"))
749+
itemArray.remove(i)
750+
for (i in 0 until itemArray.length())
751+
if (i < itemArray.length() && (itemArray.getJSONObject(i).getString("spawnId").contains("Part_") || itemArray.getJSONObject(i).getString("spawnId") == "Part"))
752+
itemArray.remove(i)
749753
input.setText(lines[0] + "\n" + jsonObject.toString())
750754
}
751755
R.id.dump -> {
@@ -913,7 +917,7 @@ class MainActivity2 : AppCompatActivity() {
913917
handleClickJson(i)
914918
}
915919
}
916-
R.id.license -> {
920+
R.id.rotation -> {
917921
dialog("Open Source Licenses", """
918922
This app is licensed with GPLv3.0 or later.
919923
AndroidX (Apache License 2.0)

app/src/main/java/com/mokkachocolata/pcsimulatorsaveeditorandroidport/ModFragment.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import android.widget.Button
1010
import android.widget.TextView
1111
import androidx.fragment.app.DialogFragment
1212

13-
class ModFragment : DialogFragment() {
14-
lateinit var mod : MainActivity2.Mod
13+
class ModFragment(val mod: MainActivity2.Mod) : DialogFragment() {
1514
var deleteListener: () -> Unit = {}
1615
override fun onCreateView(
1716
inflater: LayoutInflater,
@@ -26,8 +25,8 @@ class ModFragment : DialogFragment() {
2625
if (mod.repositoryUrl?.isEmpty() == true) flate.findViewById<TextView>(R.id.repo).visibility = View.GONE
2726
flate.findViewById<TextView>(R.id.creator).text = mod.creator
2827
flate.findViewById<TextView>(R.id.title).text = mod.name
29-
flate.findViewById<TextView>(R.id.description).text = mod.description
30-
flate.findViewById<TextView>(R.id.license).text = mod.license
28+
flate.findViewById<TextView>(R.id.pos).text = mod.description
29+
flate.findViewById<TextView>(R.id.rotation).text = mod.license
3130
flate.findViewById<TextView>(R.id.version).text = mod.version
3231
flate.findViewById<Button>(R.id.delete).setOnClickListener { deleteListener() }
3332
return flate
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.mokkachocolata.pcsimulatorsaveeditorandroidport
2+
3+
import android.annotation.SuppressLint
4+
import android.content.Intent
5+
import android.net.Uri
6+
import android.os.Bundle
7+
import android.view.LayoutInflater
8+
import android.view.View
9+
import android.view.ViewGroup
10+
import android.widget.Button
11+
import android.widget.EditText
12+
import android.widget.TextView
13+
import androidx.fragment.app.DialogFragment
14+
import org.json.JSONArray
15+
import org.json.JSONObject
16+
17+
class ObjectFragment(val obj: JSONObject, val textBox: EditText, val index: Int) : DialogFragment() {
18+
@SuppressLint("SetTextI18n")
19+
override fun onCreateView(
20+
inflater: LayoutInflater,
21+
container: ViewGroup?,
22+
savedInstanceState: Bundle?
23+
): View? {
24+
super.onCreateView(inflater, container, savedInstanceState)
25+
val flate = inflater.inflate(R.layout.fragment_object, container, false)
26+
val pos = obj.getJSONObject("pos")
27+
val rot = obj.getJSONObject("rot")
28+
flate.findViewById<TextView>(R.id.pos).text = "${pos.getDouble("x")}, ${pos.getDouble("y")}, ${pos.getDouble("z")}"
29+
flate.findViewById<TextView>(R.id.rotation).text = "${rot.getDouble("x")}, ${rot.getDouble("y")}, ${rot.getDouble("z")}, ${rot.getDouble("w")}"
30+
flate.findViewById<TextView>(R.id.smasnug).text = "ID: ${obj.getInt("id")}"
31+
flate.findViewById<TextView>(R.id.title).text = obj.getString("spawnId")
32+
flate.findViewById<Button>(R.id.delete).setOnClickListener {
33+
val text = textBox.text.toString()
34+
val lines = text.lines()
35+
val jsonObject = JSONObject(lines[1])
36+
val itemArray = jsonObject.getJSONArray("itemData")
37+
itemArray.remove(index)
38+
textBox.setText(lines[0] + "\n" + jsonObject.toString())
39+
dismiss()
40+
}
41+
return flate
42+
}
43+
44+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent">
7+
8+
<TextView
9+
android:id="@+id/pos"
10+
android:layout_width="wrap_content"
11+
android:layout_height="wrap_content"
12+
android:layout_marginTop="32dp"
13+
android:text="X: 0, Y: 0, Z: 0"
14+
app:layout_constraintStart_toStartOf="@+id/title"
15+
app:layout_constraintTop_toBottomOf="@+id/title" />
16+
17+
<TextView
18+
android:id="@+id/rotation"
19+
android:layout_width="wrap_content"
20+
android:layout_height="wrap_content"
21+
android:layout_marginTop="12dp"
22+
android:text="RX: 0, RY: 0, RZ: 0"
23+
app:layout_constraintStart_toStartOf="@+id/pos"
24+
app:layout_constraintTop_toBottomOf="@+id/pos" />
25+
26+
<TextView
27+
android:id="@+id/smasnug"
28+
android:layout_width="wrap_content"
29+
android:layout_height="wrap_content"
30+
android:layout_marginStart="88dp"
31+
android:text="ID: 69420"
32+
app:layout_constraintStart_toEndOf="@+id/pos"
33+
app:layout_constraintTop_toTopOf="@+id/pos" />
34+
35+
<TextView
36+
android:id="@+id/title"
37+
android:layout_width="wrap_content"
38+
android:layout_height="wrap_content"
39+
android:layout_marginStart="16dp"
40+
android:layout_marginTop="16dp"
41+
android:text="TextView"
42+
android:textStyle="bold"
43+
app:layout_constraintStart_toStartOf="parent"
44+
app:layout_constraintTop_toTopOf="parent" />
45+
46+
<Button
47+
android:id="@+id/delete"
48+
android:layout_width="wrap_content"
49+
android:layout_height="wrap_content"
50+
android:layout_marginTop="24dp"
51+
android:text="Delete"
52+
app:layout_constraintStart_toStartOf="@+id/rotation"
53+
app:layout_constraintTop_toBottomOf="@+id/rotation" />
54+
55+
<View
56+
android:id="@+id/view2"
57+
android:layout_width="320dp"
58+
android:layout_height="300dp"
59+
app:layout_constraintBottom_toBottomOf="parent"
60+
app:layout_constraintEnd_toEndOf="parent"
61+
app:layout_constraintStart_toStartOf="parent"
62+
app:layout_constraintTop_toTopOf="parent" />
63+
64+
<Button
65+
android:id="@+id/setSpawnID"
66+
android:layout_width="wrap_content"
67+
android:layout_height="wrap_content"
68+
android:layout_marginStart="8dp"
69+
android:text="Set spawn ID"
70+
app:layout_constraintStart_toEndOf="@+id/delete"
71+
app:layout_constraintTop_toTopOf="@+id/delete" />
72+
73+
<Button
74+
android:id="@+id/setPosition"
75+
android:layout_width="wrap_content"
76+
android:layout_height="wrap_content"
77+
android:layout_marginStart="12dp"
78+
android:text="Set position"
79+
app:layout_constraintStart_toEndOf="@+id/setSpawnID"
80+
app:layout_constraintTop_toTopOf="@+id/setSpawnID" />
81+
82+
<Button
83+
android:id="@+id/setRotation"
84+
android:layout_width="wrap_content"
85+
android:layout_height="wrap_content"
86+
android:layout_marginTop="12dp"
87+
android:text="Set rotation"
88+
app:layout_constraintStart_toStartOf="@+id/delete"
89+
app:layout_constraintTop_toBottomOf="@+id/delete" />
90+
91+
<Button
92+
android:id="@+id/setID"
93+
android:layout_width="wrap_content"
94+
android:layout_height="wrap_content"
95+
android:layout_marginStart="12dp"
96+
android:text="Set ID"
97+
app:layout_constraintStart_toEndOf="@+id/setRotation"
98+
app:layout_constraintTop_toTopOf="@+id/setRotation" />
99+
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/layout/mod_fragment.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
4-
xmlns:tools="http://schemas.android.com/tools"
54
android:layout_width="match_parent"
65
android:layout_height="match_parent">
76

87
<TextView
9-
android:id="@+id/description"
8+
android:id="@+id/pos"
109
android:layout_width="wrap_content"
1110
android:layout_height="wrap_content"
1211
android:layout_marginTop="32dp"
@@ -15,13 +14,13 @@
1514
app:layout_constraintTop_toBottomOf="@+id/title" />
1615

1716
<TextView
18-
android:id="@+id/license"
17+
android:id="@+id/rotation"
1918
android:layout_width="wrap_content"
2019
android:layout_height="wrap_content"
2120
android:layout_marginTop="12dp"
2221
android:text="License"
23-
app:layout_constraintStart_toStartOf="@+id/description"
24-
app:layout_constraintTop_toBottomOf="@+id/description" />
22+
app:layout_constraintStart_toStartOf="@+id/pos"
23+
app:layout_constraintTop_toBottomOf="@+id/pos" />
2524

2625
<TextView
2726
android:id="@+id/repo"
@@ -32,7 +31,7 @@
3231
android:text="Visit the repository"
3332
android:textColor="#0027FF"
3433
app:layout_constraintEnd_toEndOf="parent"
35-
app:layout_constraintTop_toBottomOf="@+id/license" />
34+
app:layout_constraintTop_toBottomOf="@+id/rotation" />
3635

3736
<TextView
3837
android:id="@+id/creator"

app/src/main/res/menu/menu.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
android:title="@string/options" />
3333
<item
3434
android:id="@+id/explorer"
35-
android:title="Object Browser" />
35+
android:title="@string/object_explorer" />
3636
<item
3737
android:id="@+id/dump"
3838
android:title="@string/dumper" />
@@ -44,7 +44,7 @@
4444
android:title="Keyboard Shortcuts"
4545
android:titleCondensed="Shortcuts" />
4646
<item
47-
android:id="@+id/license"
47+
android:id="@+id/rotation"
4848
android:title="Open Source Licenses"
4949
android:titleCondensed="Licenses" />
5050
<item

app/src/main/res/values-in/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@
2929
<string name="dailymarket">Daily Market (tidak perlu Bitcoin)</string>
3030
<string name="m2">NVMe SSD M.2</string>
3131
<string name="password">Kata Sandi</string>
32+
<string name="object_explorer">Browser Objek</string>
3233
</resources>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@
2929
<string name="dailymarket">Daily Market (bypass Bitcoin requirement)</string>
3030
<string name="m2">M.2 NVMe SSD</string>
3131
<string name="password">Password</string>
32+
<string name="object_explorer">Object Browser</string>
3233
</resources>

0 commit comments

Comments
 (0)