package content_database
Variables
ContentCategories
[]ContentCategory{}
ImportableTypes
[]string{}
Functions
ToContentPath
ToContentPath is an auxiliary function to simplify getting the matching content path relative to the project file system.
WriteConfig
WriteConfig is used to write a config file to the project file system. This is primarily used by the cache database, but could be used for other needs to extend the editor.
Types
Cache
struct
Cache is an in-memory cache of all of the content in the project. It keeps an internal lookup so that it's quick to look up cached information on an asset by it's id. The structure is designed so that it keeps track of when it is building internally atomically which is set when the [Build] function is called. Removing items from the cache will cause a swap removal which means that the ids inside of the lookup are not stable and change with removals.
New
New will return a new instance of the cache database with it's members pre-sized to an arbitrary amount to speed up initial loading
Cache.Build
Build will run through the project's file system config folder and scan all of the content configurations in the folder and load them into memory as part of the cache. While the build is running, searches and filters will work, but [Read] will not (due to it's mapping nature). You can use [OnBuildFinished] to know when the build has completed.
Cache.Index
Index will insert the given content configuration into the cache. If the cache already contains the id for the path, then the cache will replace it's currently held values with the new values. This should be called when building the cache, importing new content to the project, or when the developer changes settings for content that alters the configuration.
Cache.List
List will return the internally held cached content slice.
Cache.ListByType
Cache.Read
Read will try and locate the cached content data by id. This can fail if the content is not in the cache, in which case the caller should call [Index] to index the file. This can also fail if the cache is currently in the process of being built, in which case the caller should wait until it's done building and try again, or bind to the [OnBuildFinished] event.
Cache.ReadLinked
ReadLinked will return all of the linked content for the given id. This will also return the content for the id itself.
Cache.Remove
Remove will delete an entry from the cache (not the config), it is useful when content is being deleted from the project. This will delete the entry from the lookup as well. Deleting from the lookup makes it unstable since removing items from the cache will swap the deleted entry with the last entry and resize the length. This once last item will have the index of the removed entry and it's lookup will be updated.
Cache.Search
Search will filter all content by the given query and return any content that matches the query. Currently the only thing that is matched by this query is the developer-given name of the content. This is an exact match on part or all of the name (case-insensitive), fuzzy search may be introduced later.
Cache.TagFilter
TagFilter will filter all content to that which matches the given tags. This is an OR comparison so that any content that has at least one of the tags will be selected by the filter.
Cache.TypeFilter
TypeFilter will filter all content to that which matches the given types. This is an OR comparison so that any content that has at least one of the types will be selected by the filter.
CachedContent
struct
type CachedContent struct {
// Path is the location in the file system for this cached configuration.
// You will typically want to use [content_database.ToContentPath] with this
// path to get the content's location in the content folder.
Path string
Config ContentConfig
}
CachedContent is the content entry in the cache that is returned from lookups and searches.
CachedContent.Id
CachedContent will read the id from the file name and return it as a string
CategoryNotFoundError
struct
CategoryNotFoundError.Error
ContentCategory
interface
type ContentCategory interface {
// Path returns the singular folder that all of the content of the category
// will be stored within the file database. This path is relative to the
// content/config folders. So, the "Texture" category would return "texture"
// as the path, whereas the "Music" category would return "audio/music".
Path() string
// TypeName will return the string-friendly type name that is used to store
// into the content's config data file. It could be used to test against a
// specific asset type. It is expected that you can create a ContentCategory
// instance and use this method without any state, for example:
// Css{}.TypeName().
TypeName() string
// ExtNames will return all of the file extensions that this content
// category operates on. Many formats need only return a single string here
// like ".html" for a HTML file, but others may have multiple like ".png",
// ".jpg", ".jpeg", etc. for the Texture category.
ExtNames() []string
// Import will read the source file and extract the relevant data that
// should be stored in the database. In some cases, this would just return
// the contents of the file directly. In other cases, this may need to do
// some processing of the file to extract the relevant information which is
// contained within (i.e. glTF files).
Import(src string, fs *project_file_system.FileSystem) (ProcessedImport, error)
// Reimport will mostly do the same thing as import, however it will also
// determine if the content can be re-imported. In some cases, like model
// files, there are multiple pices of content that match up in specific
// ways. This function will return an error if the re-import isn't possible.
Reimport(id string, cache *Cache, fs *project_file_system.FileSystem) (ProcessedImport, error)
// PostImportProcessing allows for any optional post-processing to be done
// now that the file and all of the dependencies have been imported into the
// project. This is called for each variant that has been imported. This is
// useful to do things like creating/importing new materials based on
// imported mesh files, for example.
PostImportProcessing(proc ProcessedImport, res *ImportResult, fs *project_file_system.FileSystem, cache *Cache, linkedId string) error
}
ContentCategory is the representation of a single category within the content system for the engine. Different categories are things like "texture", "mesh", "material", etc.
CategoryFromTypeName
CategoryFromTypeName is an auxiliary function for getting the category that matches the type supplied. If the content is found, true will be returned, otherwise false.
ContentConfig
struct
type ContentConfig struct {
// Tags is a list of strings used in the editor to group similar
// things together. This removes the need for the developer to manage their
// own folder structure and allows them to control content without
// physically moving things around.
Tags []string `json:",omitempty"`
// Name is a developer-facing friendly name for the content. This is often
// set to the same name as the asset that was imported. The developer can
// change it's name at a later time as needed though.
Name string
// Type is the type of asset this content is. This will always match
// ContentCategory.TypeName() and can not be changed by the developer.
Type string
// SrcPath is the path to the file that was used to import this content. If
// the path is within the project folder, then a relative path will be used.
// If the path is outside of the project folder, an absolute path will be
// used. This path is not guarenteed to exist, as the developer may have
// moved or deleted the file.
SrcPath string
// SrcName is the name given to this content when it was imported by the
// source file. This name is not allowed to be changed, it is mainly used
// for re-importing content.
SrcName string
// LinkedId will contain a unique identifier across all content that was
// linked to a single file import. This field will be empty if there is no
// other linked content to this one. All content that is linked together
// will have the same LinkedId.
LinkedId string `json:",omitempty"`
Font *FontConfig `json:",omitempty"`
Material *MaterialConfig `json:",omitempty"`
Mesh *MeshConfig `json:",omitempty"`
Music *MusicConfig `json:",omitempty"`
Sound *SoundConfig `json:",omitempty"`
Texture *TextureConfig `json:",omitempty"`
}
ContentConfig is a composition of all possible configs, identified by their matching field name. It also contains some generic developer-facing properties.
The reason that an interface is not used is so that the serialization and usage of the various metadata types is simpler to work with, at the cost of some extra memory usage per instance.
ReadConfig
ReadConfig is used to read a config file from the project file system. This is primarily used by the cache database, but could be used for other needs to extend the editor.
ContentConfig.AddTag
AddTag is an auxiliary function that will try to add the tag to the config. If the config already contains the tag (case insensitive), then it will return false. It will also return false if the tag is invalid. In both pass and failed cases, it will return the cleaned tag value.
ContentConfig.NameLower
NameLower is an auxiliary function that simply returns a lowercase version of the Name assigned to the config
ContentConfig.RemoveTag
RemoveTag will attempt to locate the tag (case insensitive) and remove it. If it finds the tag and removes it, this will return true, otherwise false.
Css
struct
Css is a ContentCategory represented by a file with a ".css" extension. It is a CSS (cascading style sheet) file as they are known to web browsers. This expects to be a singular text file with the extension ".css" and containing CSS parsable markup.
Css.ExtNames
Css.Import
Css.Path
Css.PostImportProcessing
func (Css) PostImportProcessing(proc ProcessedImport, res *ImportResult, fs *project_file_system.FileSystem, cache *Cache, linkedId string) error
Css.Reimport
func (c Css) Reimport(id string, cache *Cache, fs *project_file_system.FileSystem) (ProcessedImport, error)
Css.TypeName
Font
struct
Font is a ContentCategory represented by a file with a ".ttf" extension. This file is expected to be a binary file. When imported, the file will be ran through a program to convert it to a format that is compatible with a MSDF text shader. This file is a composition or character positional data and an image/texture.
Font.ExtNames
Font.Import
Font.Path
Font.PostImportProcessing
func (Font) PostImportProcessing(proc ProcessedImport, res *ImportResult, fs *project_file_system.FileSystem, cache *Cache, linkedId string) error
Font.Reimport
func (c Font) Reimport(id string, cache *Cache, fs *project_file_system.FileSystem) (ProcessedImport, error)
Font.TypeName
FontCharsetFilesMissingError
struct
FontCharsetFilesMissingError.Error
FontConfig
struct
Html
struct
Html is a ContentCategory represented by a file with a ".html" extension. It is a HTML (hyper-text markup language) file as they are known to web browsers. This expects to be a singular text file with the extension ".html" and containing HTML parsable markup code.
Html.ExtNames
Html.Import
Html.Path
Html.PostImportProcessing
func (Html) PostImportProcessing(proc ProcessedImport, res *ImportResult, fs *project_file_system.FileSystem, cache *Cache, linkedId string) error
Html.Reimport
func (c Html) Reimport(id string, cache *Cache, fs *project_file_system.FileSystem) (ProcessedImport, error)
Html.TypeName
ImageImportError
struct
ImageImportError.Error
ImageReimportUnsupportedError
struct
ImageReimportUnsupportedError.Error
ImportResult
struct
type ImportResult struct {
// Id is a globally unique identifier for this imported content
Id string
// Category is the content type category that was used to import this file
Category ContentCategory
// Dependencies lists out the import results for all of the imported
// dependencies. An example of this is, when importing a mesh, that file
// will also contain references to textures that need to be imported. So,
// those textures would be imported and listed in this slice.
Dependencies []ImportResult
}
ImportResult contains the result of importing a singular file into the content database. The most important field is the Id field, which holds the new content's GUID.
Import
func Import(path string, fs *project_file_system.FileSystem, cache *Cache, linkedId string) ([]ImportResult, error)
Reimport
ImportResult.ConfigPath
ConfigPath will return the project file system path for the matching config file for the target content.
ImportResult.ContentPath
ContentPath will return the project file system path for the matching content file for the target content.
ImportVariant
struct
type ImportVariant struct {
// Name is the name of the content, typically the file name associated
Name string
// Data contains the binary representation of the content that was imported
Data []byte
}
ImportVariant contains information about a variant of the imported content
Material
struct
Material is a ContentCategory represented by a file with a ".material" extension. A material is a conglomeration of a specific render pass, a specific shader pipeline, and a set of specific shaders.
Material.ExtNames
Material.Import
Material.Path
Material.PostImportProcessing
func (Material) PostImportProcessing(proc ProcessedImport, res *ImportResult, fs *project_file_system.FileSystem, cache *Cache, linkedId string) error
Material.Reimport
func (c Material) Reimport(id string, cache *Cache, fs *project_file_system.FileSystem) (ProcessedImport, error)
Material.TypeName
MaterialConfig
struct
Mesh
struct
Mesh is a ContentCategory represented by a file with a ".gltf" or ".glb" extension. This file can contain multiple meshes as well as the textures that are assigned to the meshes. The textures will be imported as dependencies.
Mesh.ExtNames
Mesh.Import
Mesh.Path
Mesh.PostImportProcessing
func (Mesh) PostImportProcessing(proc ProcessedImport, res *ImportResult, fs *project_file_system.FileSystem, cache *Cache, linkedId string) error
Mesh.Reimport
func (c Mesh) Reimport(id string, cache *Cache, fs *project_file_system.FileSystem) (ProcessedImport, error)
Mesh.TypeName
MeshConfig
struct
MeshInvalidTextureError
struct
MeshInvalidTextureError.Error
Music
struct
Music is a ContentCategory represented by a file with a ".mp3" or ".ogg" extension. Music is as it sounds.
Music.ExtNames
Music.Import
Music.Path
Music.PostImportProcessing
func (Music) PostImportProcessing(proc ProcessedImport, res *ImportResult, fs *project_file_system.FileSystem, cache *Cache, linkedId string) error
Music.Reimport
func (c Music) Reimport(id string, cache *Cache, fs *project_file_system.FileSystem) (ProcessedImport, error)
Music.TypeName
MusicConfig
struct
NoMeshesInFileError
struct
NoMeshesInFileError.Error
NotInCacheError
struct
NotInCacheError.Error
ProcessedImport
struct
type ProcessedImport struct {
// Dependencies are the other files being imported when importing this file
Dependencies []string
// Variants holds all of the imported variants from this file. An example of
// this (in the future) might be different languages when importing a font.
Variants []ImportVariant
// Has unexported fields.
}
ProcessedImport holds all the information related to the single target file that was imported. A single imported file may expand into multiple pieces of content being imported, those are stored in the Variants.
ReadDuringBuildError
struct
ReadDuringBuildError.Error
ReimportMeshMissingError
struct
ReimportMeshMissingError.Error
ReimportSourceMissingError
struct
ReimportSourceMissingError.Error
RenderPass
struct
RenderPass is a ContentCategory represented by a file with a ".RenderPass" extension. A RenderPass is a conglomeration of a specific render pass, a specific RenderPass pipeline, and a set of specific RenderPasss.
RenderPass.ExtNames
RenderPass.Import
RenderPass.Path
RenderPass.PostImportProcessing
func (RenderPass) PostImportProcessing(proc ProcessedImport, res *ImportResult, fs *project_file_system.FileSystem, cache *Cache, linkedId string) error
RenderPass.Reimport
func (c RenderPass) Reimport(id string, cache *Cache, fs *project_file_system.FileSystem) (ProcessedImport, error)
RenderPass.TypeName
RenderPassConfig
struct
Shader
struct
Shader is a ContentCategory represented by a file with a ".shader" extension. A Shader is a conglomeration of a specific render pass, a specific shader pipeline, and a set of specific shaders.
Shader.ExtNames
Shader.Import
Shader.Path
Shader.PostImportProcessing
func (Shader) PostImportProcessing(proc ProcessedImport, res *ImportResult, fs *project_file_system.FileSystem, cache *Cache, linkedId string) error
Shader.Reimport
func (c Shader) Reimport(id string, cache *Cache, fs *project_file_system.FileSystem) (ProcessedImport, error)
Shader.TypeName
ShaderConfig
struct
ShaderPipeline
struct
ShaderPipeline is a ContentCategory represented by a file with a ".ShaderPipeline" extension. A ShaderPipeline is a conglomeration of a specific render pass, a specific ShaderPipeline pipeline, and a set of specific ShaderPipelines.
ShaderPipeline.ExtNames
ShaderPipeline.Import
func (ShaderPipeline) Import(src string, _ *project_file_system.FileSystem) (ProcessedImport, error)
ShaderPipeline.Path
ShaderPipeline.PostImportProcessing
func (ShaderPipeline) PostImportProcessing(proc ProcessedImport, res *ImportResult, fs *project_file_system.FileSystem, cache *Cache, linkedId string) error
ShaderPipeline.Reimport
func (c ShaderPipeline) Reimport(id string, cache *Cache, fs *project_file_system.FileSystem) (ProcessedImport, error)
ShaderPipeline.TypeName
ShaderPipelineConfig
struct
Sound
struct
Sound is a ContentCategory represented by a file with a ".wav" extension. Sound is as it sounds.
Sound.ExtNames
Sound.Import
Sound.Path
Sound.PostImportProcessing
func (Sound) PostImportProcessing(proc ProcessedImport, res *ImportResult, fs *project_file_system.FileSystem, cache *Cache, linkedId string) error
Sound.Reimport
func (c Sound) Reimport(id string, cache *Cache, fs *project_file_system.FileSystem) (ProcessedImport, error)
Sound.TypeName
SoundConfig
struct
Spv
struct
Spv is a ContentCategory represented by a file with a ".spv" extension. SPV is a file format for compiled shaders in Vulkan.
Spv.ExtNames
Spv.Import
Spv.Path
Spv.PostImportProcessing
func (Spv) PostImportProcessing(proc ProcessedImport, res *ImportResult, fs *project_file_system.FileSystem, cache *Cache, linkedId string) error
Spv.Reimport
func (c Spv) Reimport(id string, cache *Cache, fs *project_file_system.FileSystem) (ProcessedImport, error)
Spv.TypeName
Stage
struct
Stage is a ContentCategory represented by a file with a ".stage" extension. This expects to be a singular text file with the extension ".stage" and containing the definitions that make up a Kaiju stage.
Stage.ExtNames
Stage.Import
Stage.Path
Stage.PostImportProcessing
func (Stage) PostImportProcessing(proc ProcessedImport, res *ImportResult, fs *project_file_system.FileSystem, cache *Cache, linkedId string) error
Stage.Reimport
func (c Stage) Reimport(id string, cache *Cache, fs *project_file_system.FileSystem) (ProcessedImport, error)
Stage.TypeName
Texture
struct
Texture is a ContentCategory represented by a file with a ".png", ".jpg", or ".jpeg" extension. Textures are as they seem.
Texture.ExtNames
Texture.Import
Texture.Path
Texture.PostImportProcessing
func (Texture) PostImportProcessing(proc ProcessedImport, res *ImportResult, fs *project_file_system.FileSystem, cache *Cache, linkedId string) error
Texture.Reimport
func (c Texture) Reimport(id string, cache *Cache, fs *project_file_system.FileSystem) (ProcessedImport, error)
Texture.TypeName
TextureConfig
struct