Skip to content

Commit

Permalink
Set up serialization for mod info files
Browse files Browse the repository at this point in the history
  • Loading branch information
p0t4t0sandwich committed May 4, 2024
1 parent 472185f commit 95e2710
Show file tree
Hide file tree
Showing 5 changed files with 254 additions and 0 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
)

require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
Expand All @@ -35,4 +36,5 @@ require (
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/ZeroErrors/go-bedrockping v1.0.0 h1:nCAkSohHa9c/Gk8klpwBueiJQHOWz2aMKgF1iOLhgko=
github.com/ZeroErrors/go-bedrockping v1.0.0/go.mod h1:JQdyrc0ScjiSi8O0mbRxMyWQ3fnXrTgMApB/9HOmVPQ=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
Expand Down
227 changes: 227 additions & 0 deletions modules/archive/serialization.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
package archive

// BukkitPlugin is a struct that represents the plugin.yml file of a Bukkit plugin
type BukkitPlugin struct {
Name string `yaml:"name"`
Version string `yaml:"version"`
Author string `yaml:"author"`
Authors []string `yaml:"authors"`
Description string `yaml:"description"`
Website string `yaml:"website"`
Main string `yaml:"main"`
Depend []string `yaml:"depend"`
Depends []string `yaml:"depends"`
SoftDepend []string `yaml:"softdepend"`
SoftDepends []string `yaml:"softdepends"`
LoadBefore []string `yaml:"loadbefore"`
Load string `yaml:"load"`
}

// BungeeCordPlugin is a struct that represents the bungee.yml/plugin.yml file of a BungeeCord plugin
type BungeeCordPlugin struct {
Name string `yaml:"name"`
Version string `yaml:"version"`
Author string `yaml:"author"`
Authors []string `yaml:"authors"`
Description string `yaml:"description"`
Website string `yaml:"website"`
Main string `yaml:"main"`
Depend []string `yaml:"depend"`
Depends []string `yaml:"depends"`
SoftDepend []string `yaml:"softdepend"`
SoftDepends []string `yaml:"softdepends"`
LoadBefore []string `yaml:"loadbefore"`
}

type (
// FabricMod is a struct that represents the fabric.mod.json file of a Fabric mod
FabricMod struct {
SchemaVersion int `json:"schemaVersion"`

// Mandatory fields
ID string `json:"id"`
Version string `json:"version"`

// Optional fields - Mod Loading
Environment string `json:"environment"` // client, server, *. can also be a list, will ignore for this implementation
EntryPoints map[string]string `json:"entrypoints"`
Jars []struct {
File string `json:"file"`
} `json:"jars"`
LanguageAdapters map[string]string `json:"languageAdapters"`
Mixins []string `json:"mixins"`
AccessWidener string `json:"accessWidener"`

// Optional fields - Dependency Resolution
Depends map[string]string `json:"depends"`
Recommends map[string]string `json:"recommends"`
Suggests map[string]string `json:"suggests"`
Conflicts map[string]string `json:"conflicts"`
Breaks map[string]string `json:"breaks"`

// Optional fields - Metadata
Name string `json:"name"`
Description string `json:"description"`
Authors []FabricPerson `json:"authors"`
Contributors []FabricPerson `json:"contributors"`
Contact FabricContactInformation `json:"contact"`
License string `json:"license"` // Can also be a list, will ignore for this implementation
Icon string `json:"icon"` // Can also be a map, will ignore for this implementation
}

// FabricPerson - author or contributor
FabricPerson struct {
Name string `json:"name"`
Contact FabricContactInformation `json:"contact"`
}

// FabricContactInformation - contact information for a person
FabricContactInformation struct {
Email string `json:"email"`
IRC string `json:"irc"`
HomePage string `json:"homepage"`
Issues string `json:"issues"`
Sources string `json:"sources"`
}
)

// ForgeLegacyMod is a struct that represents the mcmod.info file of a Forge mod
type ForgeLegacyMod []struct {
ModID string `json:"modid"`
Name string `json:"name"`
Description string `json:"description"`
Version string `json:"version"`
MCVersion string `json:"mcversion"`
URL string `json:"url"`
UpdateURL string `json:"updateUrl"`
UpdateJSON string `json:"updateJSON"`
AuthorList []string `json:"authorList"`
Credits string `json:"credits"`
LogoFile string `json:"logoFile"`
Screenshots []string `json:"screenshots"`
Parent string `json:"parent"`
UseDependencyInformation bool `json:"useDependencyInformation"`
RequiredMods []string `json:"requiredMods"`
Dependencies []string `json:"dependencies"`
Dependants []string `json:"dependants"`
}

// MCMeta is a struct that represents the pack.mcmeta file
type MCMeta struct {
Pack struct {
PackFormat int `json:"pack_format"`
Description string `json:"description"`
} `json:"pack"`
}

type (
// ForgeMod is a struct that represents the META-INF/mods.toml file of a Forge mod
ForgeMod struct {
// Mandatory non-mod-specific properties
ModLoader string `toml:"modLoader"`
LoaderVersion string `toml:"loaderVersion"`
License string `toml:"license"`

// Optional non-mod-specific properties
ShowAsResourcePack bool `toml:"showAsResourcePack"`
Properties map[string]interface{}
IssueTrackerURL string `toml:"issueTrackerURL"`

Mods []ForgeModInfo
Dependencies map[string][]ForgeModDependency
}

// ModInfo represents the [[mods]] section of the mods.toml file
ForgeModInfo struct {
// Mandatory Mod Properties
ModID string `toml:"modId"`

// Optional Mod Properties
Namespace string `toml:"namespace"`
Version string `toml:"version"`
DisplayName string `toml:"displayName"`
Description string `toml:"description"`
LogoFile string `toml:"logoFile"`
LogoBlur bool `toml:"logoBlur"`
UpdateJSONURL string `toml:"updateJSONURL"`
ModProperties map[string]interface{} `toml:"modProperties"`
Credits string `toml:"credits"`
Authors string `toml:"authors"`
DisplayURL string `toml:"displayURL"`
DisplayTest string `toml:"displayTest"`
}

// ModDependency represents the [[dependencies.modId]] section of the mods.toml file
ForgeModDependency struct {
ModID string `toml:"modId"`
Mandatory bool `toml:"mandatory"`
VersionRange string `toml:"versionRange"`
Ordering string `toml:"ordering"`
Side string `toml:"side"`
}
)

type (
// SpongePlugin is a struct that represents the META-INF/sponge_plugins.json file of a Sponge plugin
SpongePlugin struct {
// Required properties
Loader SpongeLoader `json:"loader"`
License string `json:"license"`

// Optional properties (need at least one plugin)
Global SpongeGlobal `json:"global"`
Plugins []SpongePluginInfo `json:"plugins"`
}

// SpongeLoader is a struct that represents the loader property of a Sponge plugin
SpongeLoader struct {
Name string `json:"name"`
Version string `json:"version"`
}

// SpongeGlobal is a struct that represents the global property of a Sponge plugin
SpongeGlobal struct {
Version string `json:"version"`
Links SpongeLinks `json:"links"`
Contributors []SpongeContributor `json:"contributors"`
Dependencies []SpongeDependency `json:"dependencies"`
Branding SpongeBranding `json:"branding"`
}

// SpongeLinks is a struct that represents the links property of a Sponge plugin
SpongeLinks struct {
Homepage string `json:"homepage"`
Source string `json:"source"`
Issues string `json:"issues"`
}

// SpongeContributor is a struct that represents a contributor to a Sponge plugin
SpongeContributor struct {
Name string `json:"name"`
Description string `json:"description"`
}

// SpongeDependency is a struct that represents a dependency of a Sponge plugin
SpongeDependency struct {
ID string `json:"id"`
Version string `json:"version"`
LoadOrder string `json:"load-order"`
Optional bool `json:"optional"`
}

// SpongeBranding is a struct that represents the branding property of a Sponge plugin
SpongeBranding struct {
Logo string `json:"logo"`
Icon string `json:"icon"`
}

// SpongePluginInfo is a struct that represents a plugin in a Sponge plugin
// Note: Version and Contributors are not required if global.version and global.contributors are set
SpongePluginInfo struct {
SpongeGlobal
ID string `json:"id"`
Name string `json:"name"`
Entrypoint string `json:"entrypoint"`
Description string `json:"description"`
}
)
1 change: 1 addition & 0 deletions modules/archive/store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package archive
22 changes: 22 additions & 0 deletions modules/archive/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package archive

// ArchiveItem is a struct that represents an item in the archive
type ArchiveItem struct {
ID string `json:"id"`
Name string `json:"name"`
Endpoint string `json:"endpoint"`
Size int64 `json:"size"`
Links []Link `json:"links"`
}

// Link is a struct that represents external links
type Link struct {
Rel string `json:"rel"`
Href string `json:"href"`
}

// MinecraftMod is a struct that represents a Minecraft mod
type MinecraftMod struct {
ArchiveItem
ModID string `json:"mod_id"`
}

0 comments on commit 95e2710

Please sign in to comment.