mirror of
https://codeberg.org/fairyglade/ly.git
synced 2026-08-20 12:34:19 +02:00
fix(DurFile): resolve review issues
This commit is contained in:
parent
8a4fdd2e7e
commit
d1a34dc4db
1 changed files with 20 additions and 16 deletions
|
|
@ -77,17 +77,17 @@ const DurFormatRaw = struct {
|
|||
pub fn validate(self: *DurFormatRaw) !DurFormat {
|
||||
// v8 may have breaking changes like changing the colormap xy direction
|
||||
// (https://github.com/cmang/durdraw/issues/24)
|
||||
const formatVersion = self.formatVersion orelse return error.MissingFieldVersion;
|
||||
if (formatVersion != 7) return error.UnsupportedVersion;
|
||||
const format_version = self.formatVersion orelse return error.MissingFieldVersion;
|
||||
if (format_version != 7) return error.UnsupportedVersion;
|
||||
|
||||
const colorFormatStr = self.colorFormat orelse return error.MissingFieldColorFormat;
|
||||
const color_format_str = self.colorFormat orelse return error.MissingFieldColorFormat;
|
||||
// Code currently only supports 16 and 256 color format only
|
||||
const colorFormat: DurColorFormat =
|
||||
if (eql(u8, colorFormatStr, "16")) .@"16" else if (eql(u8, colorFormatStr, "256")) .@"256" else return error.UnsupportedColorFormat;
|
||||
const color_format: DurColorFormat =
|
||||
if (eql(u8, color_format_str, "16")) .@"16" else if (eql(u8, color_format_str, "256")) .@"256" else return error.UnsupportedColorFormat;
|
||||
|
||||
const encodingStr = self.encoding orelse return error.MissingFieldEncoding;
|
||||
const encoding_str = self.encoding orelse return error.MissingFieldEncoding;
|
||||
// Code currently supports only utf-8 encoding
|
||||
const encoding: DurEncoding = if (eql(u8, encodingStr, "utf-8")) .utf_8 else return error.UnsupportedEncoding;
|
||||
const encoding: DurEncoding = if (eql(u8, encoding_str, "utf-8")) .utf_8 else return error.UnsupportedEncoding;
|
||||
|
||||
if (self.framerate == null) return error.MissingFieldFramerate;
|
||||
if (self.framerate.? <= 0) return error.InvalidFramerate;
|
||||
|
|
@ -98,13 +98,13 @@ const DurFormatRaw = struct {
|
|||
const columns = std.math.cast(u32, self.columns.?) orelse return error.InvalidColumnCount;
|
||||
const lines = std.math.cast(u32, self.lines.?) orelse return error.InvalidLineCount;
|
||||
|
||||
// transfer ownership
|
||||
if (self.frames.items.len == 0) return error.NoFrames;
|
||||
const frames = self.frames;
|
||||
|
||||
return .{
|
||||
.allocator = self.allocator,
|
||||
.formatVersion = formatVersion,
|
||||
.colorFormat = colorFormat,
|
||||
.formatVersion = format_version,
|
||||
.colorFormat = color_format,
|
||||
.encoding = encoding,
|
||||
.framerate = framerate,
|
||||
.columns = columns,
|
||||
|
|
@ -428,15 +428,15 @@ pub fn init(
|
|||
return err;
|
||||
},
|
||||
error.UnsupportedVersion => {
|
||||
try log_file.err(io, "tui", "dur_file loaded was invalid: unsupported version!", .{});
|
||||
try log_file.err(io, "tui", "dur_file loaded was invalid: unsupported version ({?})!", .{dur_movie_raw.formatVersion});
|
||||
return err;
|
||||
},
|
||||
error.MissingFieldColorFormat => {
|
||||
try log_file.err(io, "tui", "dur_file loaded was invalid: missing field formatVersion!", .{});
|
||||
try log_file.err(io, "tui", "dur_file loaded was invalid: missing field colorFormat!", .{});
|
||||
return err;
|
||||
},
|
||||
error.UnsupportedColorFormat => {
|
||||
try log_file.err(io, "tui", "dur_file loaded was invalid: unsupported colorFormat!", .{});
|
||||
try log_file.err(io, "tui", "dur_file loaded was invalid: unsupported colorFormat ({?})!", .{dur_movie_raw.colorFormat});
|
||||
return err;
|
||||
},
|
||||
error.MissingFieldEncoding => {
|
||||
|
|
@ -444,7 +444,7 @@ pub fn init(
|
|||
return err;
|
||||
},
|
||||
error.UnsupportedEncoding => {
|
||||
try log_file.err(io, "tui", "dur_file loaded was invalid: unsupported encoding!", .{});
|
||||
try log_file.err(io, "tui", "dur_file loaded was invalid: unsupported encoding ({?})!", .{dur_movie_raw.encoding});
|
||||
return err;
|
||||
},
|
||||
error.MissingFieldFramerate => {
|
||||
|
|
@ -460,11 +460,15 @@ pub fn init(
|
|||
return err;
|
||||
},
|
||||
error.InvalidColumnCount => {
|
||||
try log_file.err(io, "tui", "dur_file loaded was invalid: columns value falls outside of supported range!", .{});
|
||||
try log_file.err(io, "tui", "dur_file loaded was invalid: columns value falls outside of supported range ({?})!", .{dur_movie_raw.columns});
|
||||
return err;
|
||||
},
|
||||
error.InvalidLineCount => {
|
||||
try log_file.err(io, "tui", "dur_file loaded was invalid: lines value falls outside of supported range!", .{});
|
||||
try log_file.err(io, "tui", "dur_file loaded was invalid: lines value falls outside of supported range ({?})!", .{dur_movie_raw.lines});
|
||||
return err;
|
||||
},
|
||||
error.NoFrames => {
|
||||
try log_file.err(io, "tui", "dur_file loaded was invalid: animation has no frames!", .{});
|
||||
return err;
|
||||
},
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue