Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 36 additions & 35 deletions docs/asset_specs.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
# Asset types specs

| Type | Extension | Icon | ChipText | ChipColor | CanBeCreated | Category | HasThumbnail | CanBeEdited | EditorTool |
|----------------------|---------------|-------------------|----------|-----------|--------------|----------|--------------|-------------|---------------|
| Node | .tnode | Box | NODE | Red | false | | true | true | NodeEditor |
| Project Settings | .toast | Settings | SETTINGS | DeepPink | false | Project | false | true | GenericEditor |
| Material | .tmat | Eclipse | MAT | Green | true | Visual | false | true | GenericEditor |
| Material Instance | .tmi | Eclipse | INST | Green | true | Visual | false | true | GenericEditor |
| Shader | .slang | WandSparkles | SHADER | Green | true | Visual | false | false | |
| Mesh | .tmesh | Shapes | MESH | Blue | false | Visual | false | false | |
| Texture | .ktx2 | Image | TEX | Orange | false | Visual | true | false | |
| Voxel Model | .tvox | Boxes | VOX | Magenta | false | Visual | true | false | |
| Voxel Palette | .tpal | Brush | V PAL | Magenta | true | Visual | false | true | PaletteEditor |
| Animation | .tanim | Film | ANIM | Purple | false | Visual | false | false | |
| Physics Material | .tpm | Atom | PHYS | Orange | true | Physics | false | true | GenericEditor |
| Destruction Material | .tdm | Hammer | DSTY | Orange | true | Physics | false | true | GenericEditor |
| Input Action | .taction | Zap | ACTION | Yellow | true | Input | false | true | GenericEditor |
| Input Layout | .tlayout | Gamepad2 | LAYOUT | Yellow | true | Input | false | true | GenericEditor |
| Haptic Effect | .thaptic | Vibrate | HAPTIC | Yellow | true | Input | false | true | HapticsEditor |
| Script | .lua | CodeXml | LUA | Magenta | true | Logic | false | false | |
| Data | .toml | Database | DATA | Cyan | true | Data | false | true | GenericEditor |
| Schema | .schema.json | Settings | SCHEMA | Cyan | true | Data | false | true | SchemaEditor |
| Curve | .tcurve | Spline | CURVE | Cyan | true | Data | false | true | CurveEditor |
| Audio Bank | .bank | AudioWaveform | BANK | Beige | false | Audio | false | false | |
| Audio Strings | .strings.bank | BookHeadphones | BSTR | Beige | false | Audio | false | false | |
| Bus | .tbus | SlidersVertical | BUS | Beige | false | Audio | false | false | |
| VCA | .tvca | SlidersHorizontal | VCA | Beige | false | Audio | false | false | |
| Port | .taport | Speaker | PORT | Beige | false | Audio | false | false | |
| Snapshot | .tasnap | Activity | SNAP | Beige | false | Audio | false | false | |
| Audio Event | .tae | Volume2 | EVENT | Beige | false | Audio | false | false | |
| UI Element | .rml | AppWindow | UI | Blue | true | UI | false | false | |
| UI Style | .rcss | Brush | STYLE | Blue | true | UI | false | false | |
| UI Image | .tga | FileImage | IMG | Blue | false | UI | true | false | |
| Font | .ttf | Type | FONT | Blue | false | UI | false | false | |
| Localization | .tloc | Languages | LOC | Cyan | true | UI | false | true | TableEditor |
| Image Localization | .tiloc | Images | ILOC | Cyan | true | UI | false | true | TableEditor |
| Color Scheme | .tcolor | Palette | COLOR | Cyan | true | UI | false | true | GenericEditor |
| Type | Extension | Icon | ChipText | ChipColor | CanBeCreated | Category | HasThumbnail | CanBeEdited | EditorTool |
|----------------------|---------------|-------------------|----------|-----------|--------------|----------|--------------|-------------|---------------------|
| Node | .tnode | Box | NODE | Red | false | | true | true | NodeEditor |
| Project Settings | .toast | Settings | SETTINGS | DeepPink | false | Project | false | true | GenericEditor |
| Material | .tmat | Eclipse | MAT | Green | true | Visual | false | true | GenericEditor |
| Material Instance | .tmi | Eclipse | INST | Green | true | Visual | false | true | GenericEditor |
| Shader | .slang | WandSparkles | SHADER | Green | true | Visual | false | false | |
| Mesh | .tmesh | Shapes | MESH | Blue | false | Visual | false | false | |
| Texture | .ktx2 | Image | TEX | Orange | false | Visual | true | false | |
| Voxel Model | .tvox | Boxes | VOX | Magenta | false | Visual | true | false | |
| Voxel Palette | .tpal | Brush | V PAL | Magenta | true | Visual | false | true | PaletteEditor |
| Detail Texture | .tdet | Layers | DET | Orange | true | Visual | false | true | DetailTextureEditor |
| Animation | .tanim | Film | ANIM | Purple | false | Visual | false | false | |
| Physics Material | .tpm | Atom | PHYS | Orange | true | Physics | false | true | GenericEditor |
| Destruction Material | .tdm | Hammer | DSTY | Orange | true | Physics | false | true | GenericEditor |
| Input Action | .taction | Zap | ACTION | Yellow | true | Input | false | true | GenericEditor |
| Input Layout | .tlayout | Gamepad2 | LAYOUT | Yellow | true | Input | false | true | GenericEditor |
| Haptic Effect | .thaptic | Vibrate | HAPTIC | Yellow | true | Input | false | true | HapticsEditor |
| Script | .lua | CodeXml | LUA | Magenta | true | Logic | false | false | |
| Data | .toml | Database | DATA | Cyan | true | Data | false | true | GenericEditor |
| Schema | .schema.json | Settings | SCHEMA | Cyan | true | Data | false | true | SchemaEditor |
| Curve | .tcurve | Spline | CURVE | Cyan | true | Data | false | true | CurveEditor |
| Audio Bank | .bank | AudioWaveform | BANK | Beige | false | Audio | false | false | |
| Audio Strings | .strings.bank | BookHeadphones | BSTR | Beige | false | Audio | false | false | |
| Bus | .tbus | SlidersVertical | BUS | Beige | false | Audio | false | false | |
| VCA | .tvca | SlidersHorizontal | VCA | Beige | false | Audio | false | false | |
| Port | .taport | Speaker | PORT | Beige | false | Audio | false | false | |
| Snapshot | .tasnap | Activity | SNAP | Beige | false | Audio | false | false | |
| Audio Event | .tae | Volume2 | EVENT | Beige | false | Audio | false | false | |
| UI Element | .rml | AppWindow | UI | Blue | true | UI | false | false | |
| UI Style | .rcss | Brush | STYLE | Blue | true | UI | false | false | |
| UI Image | .tga | FileImage | IMG | Blue | false | UI | true | false | |
| Font | .ttf | Type | FONT | Blue | false | UI | false | false | |
| Localization | .tloc | Languages | LOC | Cyan | true | UI | false | true | TableEditor |
| Image Localization | .tiloc | Images | ILOC | Cyan | true | UI | false | true | TableEditor |
| Color Scheme | .tcolor | Palette | COLOR | Cyan | true | UI | false | true | GenericEditor |
73 changes: 73 additions & 0 deletions editor/Assets/DetailTextureFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Tomlyn;
using Tomlyn.Model;

namespace editor.Assets;

public sealed class DetailTextureEntry {
public int Id { get; set; }
public string Name { get; set; } = "";
public string AlbedoUid { get; set; } = "";
public string RoughnessUid { get; set; } = "";
public string HeightUid { get; set; } = "";
public DetailTextureEntry Clone() => new() { Id = Id, Name = Name, AlbedoUid = AlbedoUid, RoughnessUid = RoughnessUid, HeightUid = HeightUid };
}

public sealed class DetailTextureFile {
public const int MaxTextures = 255;
public List<DetailTextureEntry> Entries { get; } = [];

public static DetailTextureFile FromFile(string path) => FromString(File.ReadAllText(path));

public static DetailTextureFile FromString(string toml) {
var table = TomlSerializer.Deserialize<TomlTable>(toml)
?? throw new FormatException("Detail texture: failed to parse TOML");

var file = new DetailTextureFile();
if (!table.TryGetValue("textures", out var list) || list is not TomlTableArray entries) return file;

var seen = new HashSet<int>();
foreach (var entry in entries) {
var id = entry.TryGetValue("id", out var v) ? v switch { long l => (int)l, int i => i, _ => 0 } : 0;
if (id is < 1 or > MaxTextures || !seen.Add(id)) continue;

file.Entries.Add(new DetailTextureEntry {
Id = id,
Name = entry.TryGetValue("name", out var name) && name is string n ? n : "",
AlbedoUid = entry.TryGetValue("albedo", out var albedo) && albedo is string a ? a : "",
RoughnessUid = entry.TryGetValue("roughness", out var roughness) && roughness is string r ? r : "",
HeightUid = entry.TryGetValue("height", out var height) && height is string h ? h : ""
});
}

return file;
}

public int NextFreeId() {
var used = Entries.Select(e => e.Id).ToHashSet();
for (var id = 1; id <= MaxTextures; id++)
if (!used.Contains(id)) return id;
return 0;
}

public string Serialize() {
var list = new TomlTableArray();
foreach (var entry in Entries) {
var table = new TomlTable {
["id"] = (long)Math.Clamp(entry.Id, 1, MaxTextures),
["name"] = entry.Name
};
if (entry.AlbedoUid.Length > 0) table["albedo"] = entry.AlbedoUid;
if (entry.RoughnessUid.Length > 0) table["roughness"] = entry.RoughnessUid;
if (entry.HeightUid.Length > 0) table["height"] = entry.HeightUid;
list.Add(table);
}

return TomlSerializer.Serialize(new TomlTable { ["textures"] = list });
}

public void Save(string path) => File.WriteAllText(path, Serialize());
}
27 changes: 27 additions & 0 deletions editor/Assets/Types/DetailTextureAsset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.IO;
using System.Threading.Tasks;
using Lucide.Avalonia;

namespace editor.Assets.Types;

public sealed class DetailTextureAsset : BaseAsset {
public override string Type => "detail_texture";
public override string Extension => ".tdet";
public override string DisplayName => "Detail Texture";
public override string ChipText => "DET";
public override string ChipColor => "Orange";
public override LucideIconKind Icon => LucideIconKind.Layers;
public override bool CanBeCreated => true;
public override string Category => "Visual";
public override bool HasThumbnail => false;
public override bool CanBeEdited => true;

public override string EditorTool => "DetailTextureEditor";

public override string SchemaPath => "";

public override Task CreateAsync(string path) {
File.WriteAllText(path, "# Toast Detail Texture\n");
return Task.CompletedTask;
}
}
34 changes: 28 additions & 6 deletions editor/Assets/VoxelPaletteFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ public sealed class VoxelPaletteEntry {

public int TransformsTo { get; set; }

/// <summary>Layer of the detail library, 0 for none</summary>
public int DetailLayer { get; set; }
public int DetailId { get; set; }
public byte DetailTintR { get; set; } = 255;
public byte DetailTintG { get; set; } = 255;
public byte DetailTintB { get; set; } = 255;

/// <summary>Texels per voxel edge, 0 for the engine default</summary>
public int DetailScale { get; set; }
Expand All @@ -52,6 +54,8 @@ public sealed class VoxelPaletteEntry {
public float DetailRoughness { get; set; }
public float DetailBump { get; set; }

public bool HasDetail => DetailId != 0;

public void CopyFrom(VoxelPaletteEntry other) {
InUse = other.InUse;
R = other.R;
Expand All @@ -66,6 +70,14 @@ public void CopyFrom(VoxelPaletteEntry other) {
Material = other.Material;
HasMaterial = other.HasMaterial;
TransformsTo = other.TransformsTo;
DetailId = other.DetailId;
DetailTintR = other.DetailTintR;
DetailTintG = other.DetailTintG;
DetailTintB = other.DetailTintB;
DetailScale = other.DetailScale;
DetailAlbedo = other.DetailAlbedo;
DetailRoughness = other.DetailRoughness;
DetailBump = other.DetailBump;
}

public void Clear() {
Expand All @@ -77,7 +89,9 @@ public void Clear() {
Alpha = 1f;
Ior = DefaultIor;
TransformsTo = 0;
DetailLayer = DetailScale = 0;
DetailId = 0;
DetailTintR = DetailTintG = DetailTintB = 255;
DetailScale = 0;
DetailAlbedo = DetailRoughness = DetailBump = 0f;
}
}
Expand Down Expand Up @@ -184,7 +198,12 @@ public static VoxelPaletteFile FromString(string toml) {

target.TransformsTo = GetInt(entry, "transforms_to", 0);

target.DetailLayer = GetInt(entry, "detail_layer", 0);
target.DetailId = Math.Clamp(GetInt(entry, "detail_id", 0), 0, 255);
if (entry.TryGetValue("detail_tint", out var tint) && tint is TomlArray tintRgb && tintRgb.Count == 3) {
target.DetailTintR = ToByte(tintRgb[0]);
target.DetailTintG = ToByte(tintRgb[1]);
target.DetailTintB = ToByte(tintRgb[2]);
}
target.DetailScale = GetInt(entry, "detail_scale", 0);
target.DetailAlbedo = GetFloat(entry, "detail_albedo", 0f);
target.DetailRoughness = GetFloat(entry, "detail_roughness", 0f);
Expand Down Expand Up @@ -246,8 +265,11 @@ public string Serialize() {
table["ior"] = Math.Round((double)Math.Clamp(entry.Ior, 1f, VoxelPaletteEntry.MaxIor), 2);
if (entry.HasMaterial) table["material"] = (long)Math.Clamp(entry.Material, 0, SlotCount - 1);
table["transforms_to"] = (long)Math.Clamp(entry.TransformsTo, 0, 255);
if (entry.DetailLayer != 0) {
table["detail_layer"] = (long)Math.Clamp(entry.DetailLayer, 0, 255);
if (entry.HasDetail) {
table["detail_id"] = (long)Math.Clamp(entry.DetailId, 0, 255);
table["detail_tint"] = new TomlArray {
(long)entry.DetailTintR, (long)entry.DetailTintG, (long)entry.DetailTintB
};
table["detail_scale"] = (long)Math.Clamp(entry.DetailScale, 0, 255);
table["detail_albedo"] = (double)Clamp01(entry.DetailAlbedo);
table["detail_roughness"] = (double)Clamp01(entry.DetailRoughness);
Expand Down
Loading
Loading