mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Move attribute persistence to its own file.
This commit is contained in:
@@ -4,6 +4,7 @@ java_import 'org.apollo.game.model.entity.Entity'
|
||||
java_import 'org.apollo.game.model.entity.attr.Attribute'
|
||||
java_import 'org.apollo.game.model.entity.attr.AttributeDefinition'
|
||||
java_import 'org.apollo.game.model.entity.attr.AttributeMap'
|
||||
java_import 'org.apollo.game.model.entity.attr.AttributePersistence'
|
||||
java_import 'org.apollo.game.model.entity.attr.AttributeType'
|
||||
java_import 'org.apollo.game.model.entity.attr.BooleanAttribute'
|
||||
java_import 'org.apollo.game.model.entity.attr.NumericalAttribute'
|
||||
@@ -66,13 +67,5 @@ end
|
||||
def get_persistence(persistence)
|
||||
raise "Undefined persistence type #{persistence}." unless persistence == :serialized || persistence == :transient
|
||||
|
||||
return persistence == :serialized ? AttributeDefinition::Persistence::SERIALIZED : AttributeDefinition::Persistence::TRANSIENT
|
||||
end
|
||||
|
||||
declare_attribute :test, 42, :serialized
|
||||
|
||||
on :command, :test do |player, command|
|
||||
player.send_message(player.test.to_s)
|
||||
player.test = 6.5
|
||||
player.send_message(player.test.to_s)
|
||||
return persistence == :serialized ? AttributePersistence::SERIALIZED : AttributePersistence::TRANSIENT
|
||||
end
|
||||
@@ -9,23 +9,6 @@ package org.apollo.game.model.entity.attr;
|
||||
*/
|
||||
public final class AttributeDefinition<T> {
|
||||
|
||||
/**
|
||||
* The persistence state of an attribute - either {@code PERSISTENT} (saved) or {@code TRANSIENT} (not saved).
|
||||
*/
|
||||
public enum Persistence {
|
||||
|
||||
/**
|
||||
* The serialized persistence type, indicating that the attribute will be saved.
|
||||
*/
|
||||
SERIALIZED,
|
||||
|
||||
/**
|
||||
* The transient persistence type, indicating that the attribute will not be saved.
|
||||
*/
|
||||
TRANSIENT;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The default value of this definition.
|
||||
*/
|
||||
@@ -34,7 +17,7 @@ public final class AttributeDefinition<T> {
|
||||
/**
|
||||
* The persistence state of this definition.
|
||||
*/
|
||||
private final Persistence persistence;
|
||||
private final AttributePersistence persistence;
|
||||
|
||||
/**
|
||||
* The type of this definition.
|
||||
@@ -45,10 +28,10 @@ public final class AttributeDefinition<T> {
|
||||
* Creates the attribute definition.
|
||||
*
|
||||
* @param defaultValue The default value.
|
||||
* @param persistence The {@link Persistence} state.
|
||||
* @param persistence The {@link AttributePersistence} state.
|
||||
* @param type The {@link AttributeType}.
|
||||
*/
|
||||
public AttributeDefinition(T defaultValue, Persistence persistence, AttributeType type) {
|
||||
public AttributeDefinition(T defaultValue, AttributePersistence persistence, AttributeType type) {
|
||||
this.defaultValue = defaultValue;
|
||||
this.persistence = persistence;
|
||||
this.type = type;
|
||||
@@ -68,7 +51,7 @@ public final class AttributeDefinition<T> {
|
||||
*
|
||||
* @return The persistence.
|
||||
*/
|
||||
public Persistence getPersistence() {
|
||||
public AttributePersistence getPersistence() {
|
||||
return persistence;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.apollo.game.model.entity.attr;
|
||||
|
||||
/**
|
||||
* The persistence state of an attribute - either {@code PERSISTENT} (saved) or {@code TRANSIENT} (not saved).
|
||||
*/
|
||||
public enum AttributePersistence {
|
||||
|
||||
/**
|
||||
* The serialized persistence type, indicating that the attribute will be saved.
|
||||
*/
|
||||
SERIALIZED,
|
||||
|
||||
/**
|
||||
* The transient persistence type, indicating that the attribute will not be saved.
|
||||
*/
|
||||
TRANSIENT;
|
||||
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import org.apollo.game.model.entity.attr.Attribute;
|
||||
import org.apollo.game.model.entity.attr.AttributeDefinition;
|
||||
import org.apollo.game.model.entity.attr.AttributeMap;
|
||||
import org.apollo.game.model.entity.attr.AttributeType;
|
||||
import org.apollo.game.model.entity.attr.AttributePersistence;
|
||||
import org.apollo.game.model.inv.Inventory;
|
||||
import org.apollo.io.player.PlayerSaver;
|
||||
import org.apollo.util.NameUtil;
|
||||
@@ -101,7 +102,7 @@ public final class BinaryPlayerSaver implements PlayerSaver {
|
||||
String name = entry.getKey();
|
||||
AttributeDefinition<?> definition = AttributeMap.getDefinition(name);
|
||||
|
||||
if (definition.getPersistence() == AttributeDefinition.Persistence.SERIALIZED) {
|
||||
if (definition.getPersistence() == AttributePersistence.SERIALIZED) {
|
||||
StreamUtil.writeString(out, name);
|
||||
saveAttribute(out, entry.getValue());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user