Skip to content

Commit

Permalink
Show part names on sprites tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim-zhao committed Oct 6, 2024
1 parent 8b3be1e commit af3c591
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 94 deletions.
5 changes: 4 additions & 1 deletion editor/ArtItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@

namespace sth1edwv
{
/// <summary>
/// Represents one non-level "thing", which may have multiple types of data.
/// </summary>
public class ArtItem
{
public TileSet TileSet { get; set; }
public Dictionary<string, Palette> Palettes { get; } = [];
public bool PaletteEditable { get; set; }
public string Name { get; init; }
public TileMap TileMap { get; set; }
public List<TileSet> SpriteTileSets { get; } = [];
public Dictionary<string, TileSet> SpriteTileSets { get; } = [];
public List<TileMapData> TileMapData { get; } = [];
public List<Cartridge.Game.Asset> Assets { get; } = [];
public List<RawValue> RawValues { get; } = [];
Expand Down
2 changes: 1 addition & 1 deletion editor/Cartridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2787,7 +2787,7 @@ private void ReadAssets()
? GetTileSet(offset, asset.GetLength(Memory), asset.BitPlanes, asset.TileGrouping, asset.TilesPerRow)
: GetTileSet(offset, asset.TileGrouping, asset.TilesPerRow);
_assetsLookup[asset] = tileSet;
item.SpriteTileSets.Add(tileSet);
item.SpriteTileSets.Add(part.Name, tileSet);
break;
case Game.Asset.Types.RawValue:
var rawValue = new RawValue(Memory, part.Asset.OriginalOffset, part.Asset.OriginalSize, part.Asset.Encoding, part.Name);
Expand Down
6 changes: 3 additions & 3 deletions editor/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ private void SelectedLevelChanged(object sender, EventArgs e)
{
PalettesLayout.Controls.Add(new PaletteEditor(level.Palette, "Base palette (only sprites part is used)", OnPaletteChanged));
PalettesLayout.Controls.Add(new PaletteEditor(level.CyclingPalette, "Colour cycling", OnPaletteChanged));
// TODO: extra palettes for some levels?
}

propertyGridLevel.SelectedObject = level;
Expand Down Expand Up @@ -582,9 +581,10 @@ private void listBoxArt_SelectedIndexChanged(object sender, EventArgs e)
tabControlArt.TabPages.Add(tabPageArtTiles);
}

foreach (var tileSet in artItem.SpriteTileSets)
foreach (var kvp in artItem.SpriteTileSets)
{
var page = new TabPage("Sprites") { Tag = tileSet, Padding = new Padding(3), UseVisualStyleBackColor = true};
var tileSet = kvp.Value;
var page = new TabPage(kvp.Key) { Tag = tileSet, Padding = new Padding(3), UseVisualStyleBackColor = true};
var viewer = new TileSetViewer { Dock = DockStyle.Fill, TilesPerRow = tileSet.TilesPerRow };
page.Controls.Add(viewer);
var palette = firstPalette.GetData().Count >= 32
Expand Down
106 changes: 17 additions & 89 deletions editor/GameObjects/Level.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace sth1edwv.GameObjects
Expand Down Expand Up @@ -102,84 +105,9 @@ public class Level : IDataItem
public bool UseUnderwaterBossPalette { get; set; }

[Category("General")]
[Description("Which music track to play")]
//[TypeConverter(typeof(MusicConverter))]
[Description("Which music track to play. Value 7 can be used for silence.")]
public int MusicIndex { get; set; }

/*
public class MusicConverter : StringConverter
{
// Enable a combo
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
// Disable free-form text
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return true;
}
// Get values
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
return new StandardValuesCollection(_musicTracks);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
return (value as MusicItem)?.ToString();
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (value is int i && destinationType == typeof(string))
{
return _musicTracks.First(x => x.Index == i).ToString();
}
if (value is MusicItem mi && destinationType == typeof(string))
{
return mi.ToString();
}
return null;
}
}
private class MusicItem
{
public int Index { get; }
private readonly string _name;
public MusicItem(int index, string name)
{
Index = index;
_name = name;
}
public override string ToString()
{
return $"{Index}: {_name}";
}
}
private static List<MusicItem> _musicTracks = new()
{
new(0, "Green Hill"),
new(1, "Bridge"),
new(2, "Jungle"),
new(3, "Labyrinth"),
new(4, "Scrap Brain"),
new(5, "Sky Base"),
new(6, "Title"),
new(8, "Invincibility"),
new(9, "Level Complete"),
new(10, "Death"),
new(11, "Boss"),
};
*/

// Objects representing referenced data
[Category("General")] public TileSet TileSet { get; }
[Category("General")] public TileSet SpriteTileSet { get; }
Expand All @@ -197,10 +125,6 @@ public override string ToString()
[Category("General")] public int Offset { get; set; }

private readonly string _label;
private readonly int _floorAddress;
private readonly int _floorSize;
private readonly int _offsetArt;
private readonly int _offsetObjectLayout;
private readonly int _initPalette;

// These should be encapsulated by a cycling palette object
Expand All @@ -213,6 +137,10 @@ public override string ToString()

public Level(Cartridge cartridge, int offset, string label)
{
int offsetObjectLayout;
int offsetArt;
int floorSize;
int floorAddress;
_label = label;
Offset = offset;
int blockMappingOffset;
Expand All @@ -237,17 +165,17 @@ public Level(Cartridge cartridge, int offset, string label)
BottomEdgeFactor = reader.ReadByte(); // LH
StartX = reader.ReadByte(); // SX
StartY = reader.ReadByte(); // SY
_floorAddress = reader.ReadUInt16(); // FL FL: relative to 0x14000
_floorSize = reader.ReadUInt16(); // FS FS: compressed size in bytes
floorAddress = reader.ReadUInt16(); // FL FL: relative to 0x14000
floorSize = reader.ReadUInt16(); // FS FS: compressed size in bytes
blockMappingOffset = reader.ReadUInt16(); // BM BM: relative to 0x10000
_offsetArt = reader.ReadUInt16(); // LA LA: Relative to 0x30000
offsetArt = reader.ReadUInt16(); // LA LA: Relative to 0x30000
spriteArtPage = reader.ReadByte(); // SP: Page for the below
spriteArtAddress = reader.ReadUInt16(); // SA SA: offset from start of above bank
_initPalette = reader.ReadByte(); // IP: Index of palette
PaletteCycleRate = reader.ReadByte(); // CS: Number of frames between palette cycles
_paletteCycleCount = reader.ReadByte(); // CC: Number of palette cycles in a loop
_paletteCycleIndex = reader.ReadByte(); // CP: Which cycling palette to use
_offsetObjectLayout = reader.ReadUInt16(); // OL OL: relative to 0x15580
offsetObjectLayout = reader.ReadUInt16(); // OL OL: relative to 0x15580
var flags = reader.ReadByte(); // SR
// Nothing for bit 0
DemoMode = (flags & (1 << 1)) != 0;
Expand Down Expand Up @@ -277,13 +205,13 @@ public Level(Cartridge cartridge, int offset, string label)
Palette = cartridge.GetPalette(cartridge.Memory.Word(0x627C + _initPalette*2), 2);
CyclingPalette = cartridge.GetPalette(cartridge.Memory.Word(0x628C + _paletteCycleIndex*2), _paletteCycleCount);

TileSet = cartridge.GetTileSet(_offsetArt + 0x30000, null, 16);
TileSet = cartridge.GetTileSet(offsetArt + 0x30000, null, 16);

SpriteTileSet = cartridge.GetTileSet(spriteArtAddress + spriteArtPage * 0x4000, TileSet.Groupings.Sprite, 16);

Floor = cartridge.GetFloor(
_floorAddress + 0x14000,
_floorSize,
floorAddress + 0x14000,
floorSize,
FloorWidth);

// We rewrite FloorHeight to match the data size.
Expand All @@ -308,7 +236,7 @@ public Level(Cartridge cartridge, int offset, string label)
};

BlockMapping = cartridge.GetBlockMapping(blockMappingOffset + 0x10000, blockCount, _solidityIndex, TileSet);
Objects = cartridge.GetLevelObjectSet(0x15580 + _offsetObjectLayout);
Objects = cartridge.GetLevelObjectSet(0x15580 + offsetObjectLayout);

// We generate sub-palettes for rendering
UpdateRenderingPalettes();
Expand Down

0 comments on commit af3c591

Please sign in to comment.