-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make API importable into dev environments.
- Loading branch information
1 parent
bfcbbc7
commit 9f11b5e
Showing
13 changed files
with
427 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
201 changes: 201 additions & 0 deletions
201
build_logic/src/main/java/lambdynamiclights/data/Fmj.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
package lambdynamiclights.data; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonSerializationContext; | ||
import com.google.gson.JsonSerializer; | ||
|
||
import java.io.Serializable; | ||
import java.lang.reflect.Type; | ||
import java.util.*; | ||
import java.util.function.Consumer; | ||
|
||
public final class Fmj extends ModBase<Fmj> { | ||
private final String version; | ||
private final List<String> authors = new ArrayList<>(); | ||
private Contact contact; | ||
private String license; | ||
private String environment; | ||
private final Map<String, List<String>> entrypoints = new LinkedHashMap<>(); | ||
private String accessWidener; | ||
private final List<String> mixins = new ArrayList<>(); | ||
private final Map<String, String> depends = new LinkedHashMap<>(); | ||
private final Map<String, String> recommends = new LinkedHashMap<>(); | ||
private final Map<String, String> breaks = new LinkedHashMap<>(); | ||
private final Map<String, Object> custom = new LinkedHashMap<>(); | ||
|
||
public Fmj(String namespace, String name, String version) { | ||
super(namespace, name); | ||
this.version = version; | ||
} | ||
|
||
public Fmj withAuthors(List<String> authors) { | ||
this.authors.addAll(authors); | ||
return this; | ||
} | ||
|
||
public Fmj withAuthors(String... authors) { | ||
return this.withAuthors(Arrays.asList(authors)); | ||
} | ||
|
||
private Contact useContact() { | ||
if (this.contact == null) this.contact = new Contact(); | ||
return this.contact; | ||
} | ||
|
||
public Fmj withContact(Consumer<Contact> action) { | ||
action.accept(this.useContact()); | ||
return this; | ||
} | ||
|
||
public Fmj withLicense(String license) { | ||
this.license = license; | ||
return this; | ||
} | ||
|
||
public Fmj withEnvironment(String environment) { | ||
this.environment = environment; | ||
return this; | ||
} | ||
|
||
public Fmj withEntrypoints(String entrypointName, String... entrypoints) { | ||
this.entrypoints.computeIfAbsent(entrypointName, k -> new ArrayList<>()).addAll(Arrays.asList(entrypoints)); | ||
return this; | ||
} | ||
|
||
public Fmj withAccessWidener(String accessWidener) { | ||
this.accessWidener = accessWidener; | ||
return this; | ||
} | ||
|
||
public Fmj withMixins(String... mixins) { | ||
this.mixins.addAll(Arrays.asList(mixins)); | ||
return this; | ||
} | ||
|
||
public Fmj withDepend(String dependency, String constraint) { | ||
this.depends.put(dependency, constraint); | ||
return this; | ||
} | ||
|
||
public Fmj withRecommend(String dependency, String constraint) { | ||
this.recommends.put(dependency, constraint); | ||
return this; | ||
} | ||
|
||
public Fmj withBreak(String dependency, String constraint) { | ||
this.breaks.put(dependency, constraint); | ||
return this; | ||
} | ||
|
||
public Fmj withCustom(String key, Object value) { | ||
this.custom.put(key, value); | ||
return this; | ||
} | ||
|
||
public Fmj withModMenu(Consumer<ModMenu> action) { | ||
action.accept((ModMenu) this.custom.computeIfAbsent("modmenu", k -> new ModMenu())); | ||
return this; | ||
} | ||
|
||
public static final class Contact implements Serializable { | ||
private String homepage; | ||
private String sources; | ||
private String issues; | ||
|
||
public Contact withHomepage(String homepage) { | ||
this.homepage = homepage; | ||
return this; | ||
} | ||
|
||
public Contact withSources(String sources) { | ||
this.sources = sources; | ||
return this; | ||
} | ||
|
||
public Contact withIssues(String issues) { | ||
this.issues = issues; | ||
return this; | ||
} | ||
} | ||
|
||
public static final class ModMenu implements Serializable { | ||
private Map<String, String> links; | ||
private List<String> badges; | ||
private ParentMod parent; | ||
|
||
private Map<String, String> useLinks() { | ||
if (this.links == null) this.links = new LinkedHashMap<>(); | ||
return this.links; | ||
} | ||
|
||
public ModMenu withLink(String key, String value) { | ||
this.useLinks().put(key, value); | ||
return this; | ||
} | ||
|
||
private List<String> useBadges() { | ||
if (this.badges == null) this.badges = new ArrayList<>(); | ||
return this.badges; | ||
} | ||
|
||
public ModMenu withBadges(String... badges) { | ||
this.useBadges().addAll(Arrays.asList(badges)); | ||
return this; | ||
} | ||
|
||
public ModMenu withParent(ParentMod parent) { | ||
this.parent = parent; | ||
return this; | ||
} | ||
|
||
public ModMenu withParent(String namespace, String name, Consumer<ParentMod> action) { | ||
var mod = new ParentMod(namespace, name); | ||
action.accept(mod); | ||
return this.withParent(mod); | ||
} | ||
|
||
public static final class ParentMod extends ModBase<ParentMod> { | ||
private List<String> badges; | ||
|
||
public ParentMod(String namespace, String name) { | ||
super(namespace, name); | ||
} | ||
|
||
private List<String> useBadges() { | ||
if (this.badges == null) this.badges = new ArrayList<>(); | ||
return this.badges; | ||
} | ||
|
||
public ParentMod withBadges(String... badges) { | ||
this.useBadges().addAll(Arrays.asList(badges)); | ||
return this; | ||
} | ||
} | ||
} | ||
|
||
public static final class Serializer implements JsonSerializer<Fmj> { | ||
@Override | ||
public JsonElement serialize(Fmj src, Type typeOfSrc, JsonSerializationContext context) { | ||
var json = new JsonObject(); | ||
json.addProperty("schemaVersion", 1); | ||
json.addProperty("id", src.namespace); | ||
json.addProperty("name", src.name); | ||
json.addProperty("version", src.version); | ||
if (src.description != null) json.addProperty("description", src.description); | ||
if (!src.authors.isEmpty()) json.add("authors", context.serialize(src.authors)); | ||
if (src.contact != null) json.add("contact", context.serialize(src.contact)); | ||
if (src.license != null) json.addProperty("license", src.license); | ||
if (src.icon != null) json.addProperty("icon", src.icon); | ||
if (src.environment != null) json.addProperty("environment", src.environment); | ||
if (!src.entrypoints.isEmpty()) json.add("entrypoints", context.serialize(src.entrypoints)); | ||
if (src.accessWidener != null) json.addProperty("accessWidener", src.accessWidener); | ||
if (!src.mixins.isEmpty()) json.add("mixins", context.serialize(src.mixins)); | ||
if (!src.depends.isEmpty()) json.add("depends", context.serialize(src.depends)); | ||
if (!src.recommends.isEmpty()) json.add("recommends", context.serialize(src.recommends)); | ||
if (!src.breaks.isEmpty()) json.add("breaks", context.serialize(src.breaks)); | ||
if (!src.custom.isEmpty()) json.add("custom", context.serialize(src.custom)); | ||
return json; | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
build_logic/src/main/java/lambdynamiclights/data/ModBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package lambdynamiclights.data; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
import java.io.Serializable; | ||
|
||
public class ModBase<SELF extends ModBase<SELF>> implements Serializable { | ||
@SerializedName("id") | ||
protected String namespace; | ||
protected String name; | ||
protected String description; | ||
protected String icon; | ||
|
||
public ModBase(String namespace, String name) { | ||
this.namespace = namespace; | ||
this.name = name; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private SELF $self() { | ||
return (SELF) this; | ||
} | ||
|
||
public SELF withNamespace(String namespace) { | ||
this.namespace = namespace; | ||
return this.$self(); | ||
} | ||
|
||
public SELF withName(String name) { | ||
this.name = name; | ||
return this.$self(); | ||
} | ||
|
||
public SELF withDescription(String description) { | ||
this.description = description; | ||
return this.$self(); | ||
} | ||
|
||
public SELF withIcon(String icon) { | ||
this.icon = icon; | ||
return this.$self(); | ||
} | ||
} |
Oops, something went wrong.