Handle record rename/delete/lock/favorite

This commit is contained in:
Melledy
2025-10-29 22:31:31 -07:00
parent 0f4f56a96b
commit 08520493ed
8 changed files with 217 additions and 20 deletions
@@ -3,6 +3,7 @@ package emu.nebula.game.tower;
import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Id;
import dev.morphia.annotations.Indexed;
import emu.nebula.Nebula;
import emu.nebula.data.GameData;
import emu.nebula.database.GameDatabaseObject;
import emu.nebula.proto.Public.ItemTpl;
@@ -41,7 +42,7 @@ public class StarTowerBuild implements GameDatabaseObject {
}
public StarTowerBuild(StarTowerInstance instance) {
public StarTowerBuild(StarTowerGame instance) {
this.uid = Snowflake.newUid();
this.playerUid = instance.getPlayer().getUid();
this.name = "";
@@ -74,6 +75,25 @@ public class StarTowerBuild implements GameDatabaseObject {
}
}
}
public void setName(String newName) {
if (newName.length() > 32) {
newName = newName.substring(0, 31);
}
this.name = newName;
Nebula.getGameDatabase().update(this, this.getUid(), "name", this.getName());
}
public void setLock(boolean state) {
this.lock = state;
Nebula.getGameDatabase().update(this, this.getUid(), "lock", this.isLock());
}
public void setPreference(boolean state) {
this.preference = state;
Nebula.getGameDatabase().update(this, this.getUid(), "preference", this.isPreference());
}
// Proto
@@ -129,4 +149,10 @@ public class StarTowerBuild implements GameDatabaseObject {
return proto;
}
// Database
public void delete() {
Nebula.getGameDatabase().delete(this);
}
}