mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Baseline IrisApi draft before stage-graph redesign
This commit is contained in:
commit
9043d93fbd
91 files changed
+4045
No files matched your search
@@ -0,0 +1,23 @@
|
||||
package com.volmit.resource;
|
||||
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/** Immutable view of one loaded pack snapshot, safe for concurrent reads.
|
||||
* Reload produces a different snapshotId, even for the same pack. Resources must be immutable
|
||||
* or explicitly thread-safe. Unknown IDs return empty; a known ID with the wrong requested
|
||||
* type throws IllegalArgumentException. Broken resources fail loading rather than appearing absent.
|
||||
* The host owns resolution, imports, native handles and caches; no filesystem paths escape.
|
||||
*/
|
||||
public interface PackResources {
|
||||
ResourceId packId();
|
||||
UUID snapshotId();
|
||||
BlockRegistry blocks();
|
||||
<T> Optional<T> find(ResourceKey<T> key);
|
||||
|
||||
default <T> T require(ResourceKey<T> key) {
|
||||
return find(key).orElseThrow(() -> new NoSuchElementException("Missing resource: " + key.id()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.volmit.resource;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/** Case-sensitive namespaced identity. Parsing never supplies an implicit namespace. */
|
||||
public record ResourceId(String namespace, String path) implements Comparable<ResourceId> {
|
||||
public ResourceId {
|
||||
Objects.requireNonNull(namespace, "namespace");
|
||||
Objects.requireNonNull(path, "path");
|
||||
if (!namespace.matches("[a-z0-9_.-]+") || !path.matches("[a-z0-9_./-]+")) {
|
||||
throw new IllegalArgumentException("Invalid resource ID: " + namespace + ":" + path);
|
||||
}
|
||||
}
|
||||
|
||||
public static ResourceId parse(String value) {
|
||||
Objects.requireNonNull(value, "value");
|
||||
int separator = value.indexOf(':');
|
||||
if (separator < 0) throw new IllegalArgumentException("Expected a namespaced ID: " + value);
|
||||
return new ResourceId(value.substring(0, separator), value.substring(separator + 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() { return namespace + ":" + path; }
|
||||
|
||||
@Override
|
||||
public int compareTo(ResourceId other) { return toString().compareTo(other.toString()); }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.volmit.resource;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/** A resource ID paired with its public value type; the host owns loading and caching. */
|
||||
public record ResourceKey<T>(ResourceId id, Class<T> type) {
|
||||
public ResourceKey {
|
||||
Objects.requireNonNull(id, "id");
|
||||
Objects.requireNonNull(type, "type");
|
||||
if (type.isPrimitive()) throw new IllegalArgumentException("Resources require a reference type");
|
||||
}
|
||||
|
||||
public ResourceKey(String id, Class<T> type) { this(ResourceId.parse(id), type); }
|
||||
}
|
||||
Reference in new issue
Block a user