mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-07 16:26:14 +00:00
Initial
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package com.volmit.iris.engine;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class EngineConfiguration {
|
||||
@Builder.Default
|
||||
private boolean mutable = false;
|
||||
|
||||
@Builder.Default
|
||||
private boolean timings = false;
|
||||
|
||||
@Builder.Default
|
||||
private int threads = 4;
|
||||
}
|
||||
23
src/main/java/com/volmit/iris/engine/IrisEngine.java
Normal file
23
src/main/java/com/volmit/iris/engine/IrisEngine.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.volmit.iris.engine;
|
||||
|
||||
import com.volmit.iris.engine.registry.EngineRegistry;
|
||||
import com.volmit.iris.engine.registry.PlatformRegistry;
|
||||
import com.volmit.iris.platform.IrisPlatform;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class IrisEngine<NS, BLOCK, BIOME> {
|
||||
private IrisPlatform<NS, BLOCK, BIOME> platform;
|
||||
private EngineRegistry<BLOCK, BIOME> registry;
|
||||
private EngineConfiguration configuration;
|
||||
|
||||
public IrisEngine(IrisPlatform<NS, BLOCK, BIOME> platform, EngineConfiguration configuration)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
this.platform = platform;
|
||||
this.registry = EngineRegistry.<BLOCK, BIOME>builder()
|
||||
.blockRegistry(new PlatformRegistry<>(getPlatform().getBlockDataTransformer()))
|
||||
.biomeRegistry(new PlatformRegistry<>(getPlatform().getBiomeTransformer()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
53
src/main/java/com/volmit/iris/engine/object/NSKey.java
Normal file
53
src/main/java/com/volmit/iris/engine/object/NSKey.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package com.volmit.iris.engine.object;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public class NSKey
|
||||
{
|
||||
private final String key;
|
||||
|
||||
/**
|
||||
* accepts dirt as minecraft:dirt
|
||||
* accepts somemod:ground as somemod:ground
|
||||
* @param key the key
|
||||
*/
|
||||
public NSKey(String key)
|
||||
{
|
||||
this(key.contains(":") ? key.split("\\Q:\\E")[0] : "minecraft", key.contains(":") ? key.split("\\Q:\\E")[1] : key);
|
||||
}
|
||||
|
||||
public NSKey(String namespace, String key)
|
||||
{
|
||||
this.key = namespace + ":" + key;
|
||||
}
|
||||
|
||||
public String getNamespace()
|
||||
{
|
||||
return key.split("\\Q:\\E")[0];
|
||||
}
|
||||
|
||||
public String getKey()
|
||||
{
|
||||
return key.split("\\Q:\\E")[1];
|
||||
}
|
||||
|
||||
public NSKey withKey(String key)
|
||||
{
|
||||
return new NSKey(getNamespace(), key);
|
||||
}
|
||||
|
||||
public NSKey withNamespace(String namespace)
|
||||
{
|
||||
return new NSKey(namespace, getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return key;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.volmit.iris.engine.object;
|
||||
|
||||
public interface Namespaced {
|
||||
NSKey getKey();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.volmit.iris.engine.object.biome;
|
||||
|
||||
import com.volmit.iris.engine.object.Namespaced;
|
||||
import com.volmit.iris.engine.object.NSKey;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class NativeBiome implements Namespaced {
|
||||
private final NSKey key;
|
||||
|
||||
public NativeBiome(NSKey key)
|
||||
{
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return key.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.volmit.iris.engine.object.block;
|
||||
|
||||
import com.volmit.iris.engine.object.Namespaced;
|
||||
import com.volmit.iris.engine.object.NSKey;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class IrisBlock implements Namespaced {
|
||||
private static final Map<String, String> EMPTY_PROPERTIES = Map.of();
|
||||
private final NSKey key;
|
||||
private final Map<String, String> properties;
|
||||
|
||||
public IrisBlock(NSKey key, Map<String, String> properties)
|
||||
{
|
||||
this.key = key;
|
||||
this.properties = Collections.unmodifiableMap(properties);
|
||||
}
|
||||
|
||||
public IrisBlock(NSKey key)
|
||||
{
|
||||
this(key, EMPTY_PROPERTIES);
|
||||
}
|
||||
|
||||
public IrisBlock property(String key, String value) {
|
||||
Map<String, String> map = new HashMap<>(getProperties());
|
||||
map.put(key, value);
|
||||
return new IrisBlock(getKey(), map);
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for(String i : getProperties().keySet())
|
||||
{
|
||||
sb.append(",").append(i).append("=").append(getProperties().get(i));
|
||||
}
|
||||
|
||||
return sb.append(getKey()).append("[") + sb.append("]").substring(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.volmit.iris.engine.object.world;
|
||||
|
||||
public class IrisWorld
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.volmit.iris.engine.registry;
|
||||
|
||||
import com.volmit.iris.engine.object.biome.NativeBiome;
|
||||
import com.volmit.iris.engine.object.block.IrisBlock;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public class EngineRegistry<BLOCK, BIOME> {
|
||||
private final PlatformRegistry<BLOCK, IrisBlock> blockRegistry;
|
||||
private final PlatformRegistry<BIOME, NativeBiome> biomeRegistry;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.volmit.iris.engine.registry;
|
||||
|
||||
import art.arcane.amulet.collections.Biset;
|
||||
import art.arcane.amulet.collections.ObjectBiset;
|
||||
import com.volmit.iris.engine.object.Namespaced;
|
||||
import com.volmit.iris.engine.object.NSKey;
|
||||
import com.volmit.iris.platform.PlatformDataTransformer;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class PlatformRegistry<NATIVE, T extends Namespaced> {
|
||||
@Getter
|
||||
private final PlatformDataTransformer<NATIVE, T> transformer;
|
||||
private final Map<NSKey, RegistryValue<NATIVE, T>> registry;
|
||||
|
||||
public PlatformRegistry(PlatformDataTransformer<NATIVE, T> transformer)
|
||||
{
|
||||
this.transformer = transformer;
|
||||
registry = transformer.getRegistry().collect(Collectors.toMap(transformer::getKey, (t) -> new RegistryValue<>(t, transformer.toIris(t))));
|
||||
d("Registered " + transformer.countSuffixName(registry.size()));
|
||||
}
|
||||
|
||||
public NATIVE getNative(NSKey key) {
|
||||
return registry.get(key).getNativeValue();
|
||||
}
|
||||
|
||||
public T get(NSKey key) {
|
||||
return registry.get(key).getValue();
|
||||
}
|
||||
|
||||
public Set<NSKey> getKeys() {
|
||||
return Collections.unmodifiableSet(registry.keySet());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.volmit.iris.engine.registry;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RegistryValue<NATIVE, T> {
|
||||
private final NATIVE nativeValue;
|
||||
private final T value;
|
||||
}
|
||||
15
src/main/java/com/volmit/iris/platform/IrisPlatform.java
Normal file
15
src/main/java/com/volmit/iris/platform/IrisPlatform.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.volmit.iris.platform;
|
||||
|
||||
import com.volmit.iris.engine.object.NSKey;
|
||||
import com.volmit.iris.engine.object.biome.NativeBiome;
|
||||
import com.volmit.iris.engine.object.block.IrisBlock;
|
||||
|
||||
public interface IrisPlatform<NS, BLOCK, BIOME> {
|
||||
String getPlatformName();
|
||||
|
||||
PlatformTransformer<NS, NSKey> getNamespaceTransformer();
|
||||
|
||||
PlatformDataTransformer<BLOCK, IrisBlock> getBlockDataTransformer();
|
||||
|
||||
PlatformDataTransformer<BIOME, NativeBiome> getBiomeTransformer();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.volmit.iris.platform;
|
||||
|
||||
import com.volmit.iris.engine.object.Namespaced;
|
||||
import com.volmit.iris.engine.object.NSKey;
|
||||
|
||||
import java.text.Normalizer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public interface PlatformDataTransformer<NATIVE, T extends Namespaced> extends PlatformTransformer<NATIVE, T> {
|
||||
default Stream<NSKey> getRegistryKeys() {
|
||||
return getRegistry().map(this::getKey);
|
||||
}
|
||||
|
||||
Stream<NATIVE> getRegistry();
|
||||
|
||||
NSKey getKey(NATIVE nativeType);
|
||||
|
||||
String getTypeName();
|
||||
|
||||
default String getTypeNamePlural()
|
||||
{
|
||||
return getTypeName() + "s";
|
||||
}
|
||||
|
||||
default String countSuffixName(int count)
|
||||
{
|
||||
return count + " " + (count == 1 ? getTypeName() : getTypeNamePlural());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.volmit.iris.platform;
|
||||
|
||||
public interface PlatformTransformer<NATIVE, T> {
|
||||
T toIris(NATIVE nativeType);
|
||||
|
||||
NATIVE toNative(T t);
|
||||
}
|
||||
Reference in New Issue
Block a user