Skip to content

Commit 7136775

Browse files
anarchuserxeruf
authored andcommitted
refactor(sdk): convert SlotDescriptor to kotlin
It also moves the "static default SlotDescriptor" to SlotDescriptor's default arguments. here's no need for a "default object"
1 parent bd458b0 commit 7136775

File tree

4 files changed

+23
-64
lines changed

4 files changed

+23
-64
lines changed

server/src/sc/server/gaming/PlayerSlot.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public PlayerSlot(GameRoom room) {
1717
throw new IllegalStateException("Room must not be null.");
1818

1919
this.room = room;
20+
descriptor = new SlotDescriptor();
2021
}
2122

2223
public PlayerRole getRole() {
@@ -85,15 +86,12 @@ public String getDisplayName() {
8586
}
8687

8788
public SlotDescriptor getDescriptor() {
88-
if (this.descriptor == null) {
89-
return SlotDescriptor.DEFAULT_DESCRIPTOR;
90-
}
91-
9289
return this.descriptor;
9390
}
9491

9592
public void setDescriptor(SlotDescriptor descriptor) {
96-
this.descriptor = descriptor;
93+
if (descriptor == null) this.descriptor = new SlotDescriptor();
94+
else this.descriptor = descriptor;
9795
}
9896

9997
public IClient getClient() {

socha-sdk/src/framework/sc/shared/SlotDescriptor.java

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package sc.shared
2+
3+
import com.thoughtworks.xstream.annotations.XStreamAlias
4+
import com.thoughtworks.xstream.annotations.XStreamAsAttribute
5+
6+
@XStreamAlias(value = "slotDescriptor")
7+
class SlotDescriptor(
8+
@XStreamAsAttribute val displayName: String,
9+
@XStreamAsAttribute val canTimeout: Boolean,
10+
@XStreamAsAttribute val shouldBePaused: Boolean) {
11+
12+
constructor(displayName: String, canTimeout: Boolean) : this(displayName, canTimeout, true)
13+
constructor(displayName: String) : this(displayName, true, true)
14+
constructor() : this("Unknown", true, true)
15+
16+
override fun toString(): String {
17+
return "SlotDescriptor{displayName=$displayName, canTimeout=$canTimeout, shouldBePaused=$shouldBePaused"
18+
}
19+
}

socha-sdk/src/test/sc/shared/SlotDescriptorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class SlotDescriptorTest : StringSpec({
1818
SlotDescriptor("another name", true, false)
1919
)
2020
val XMLs = listOf(
21-
"""<slotDescriptor canTimeout="false" shouldBePaused="false"/>""",
21+
"""<slotDescriptor displayName="Unknown" canTimeout="true" shouldBePaused="true"/>""",
2222
"""<slotDescriptor displayName="Display Name" canTimeout="true" shouldBePaused="true"/>""",
2323
"""<slotDescriptor displayName="name" canTimeout="false" shouldBePaused="true"/>""",
2424
"""<slotDescriptor displayName="another name" canTimeout="true" shouldBePaused="false"/>"""

0 commit comments

Comments
 (0)