feature/d01-component-system #5
@@ -0,0 +1,38 @@
|
||||
package com.tiedup.remake.v2.bondage.component;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import java.util.function.Function;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum ComponentType {
|
||||
LOCKABLE("lockable", LockableComponent::fromJson),
|
||||
RESISTANCE("resistance", ResistanceComponent::fromJson),
|
||||
GAGGING("gagging", GaggingComponent::fromJson);
|
||||
|
||||
private final String jsonKey;
|
||||
private final Function<JsonObject, IItemComponent> factory;
|
||||
|
||||
ComponentType(
|
||||
String jsonKey,
|
||||
Function<JsonObject, IItemComponent> factory
|
||||
) {
|
||||
this.jsonKey = jsonKey;
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
public String getJsonKey() {
|
||||
return jsonKey;
|
||||
}
|
||||
|
||||
public IItemComponent create(JsonObject config) {
|
||||
return factory.apply(config);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ComponentType fromKey(String key) {
|
||||
for (ComponentType type : values()) {
|
||||
if (type.jsonKey.equals(key)) return type;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.tiedup.remake.v2.bondage.component;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class GaggingComponent implements IItemComponent {
|
||||
|
||||
private GaggingComponent() {}
|
||||
|
||||
public static IItemComponent fromJson(JsonObject config) {
|
||||
return new GaggingComponent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.tiedup.remake.v2.bondage.component;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class LockableComponent implements IItemComponent {
|
||||
|
||||
private LockableComponent() {}
|
||||
|
||||
public static IItemComponent fromJson(JsonObject config) {
|
||||
return new LockableComponent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.tiedup.remake.v2.bondage.component;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class ResistanceComponent implements IItemComponent {
|
||||
|
||||
private ResistanceComponent() {}
|
||||
|
||||
public static IItemComponent fromJson(JsonObject config) {
|
||||
return new ResistanceComponent();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user