@@ -5,29 +5,26 @@ const ziggy = @import("ziggy");
55const network_data = @import ("network_data.zig" );
66const utils = @import ("utils.zig" );
77
8- const macro_mappings = [_ ]struct { base : []const u8 , replace : []const u8 }{
9- .{ .base = "$hptxt" , .replace = "&type=\" bold_it\" &col=\" 20AC20\" " },
10- .{ .base = "$mptxt" , .replace = "&type=\" bold_it\" &col=\" 1C40FF\" " },
11- .{ .base = "$strtxt" , .replace = "&type=\" bold_it\" &col=\" FF6C32\" " },
12- .{ .base = "$deftxt" , .replace = "&type=\" bold_it\" &col=\" FF9670\" " },
13- .{ .base = "$wittxt" , .replace = "&type=\" bold_it\" &col=\" A15AFF\" " },
14- .{ .base = "$restxt" , .replace = "&type=\" bold_it\" &col=\" D65BFF\" " },
15- .{ .base = "$statxt" , .replace = "&type=\" bold_it\" &col=\" C45860\" " },
16- .{ .base = "$inttxt" , .replace = "&type=\" bold_it\" &col=\" 6080FF\" " },
17- .{ .base = "$spdtxt" , .replace = "&type=\" bold_it\" &col=\" C45860\" " },
18- .{ .base = "$hsttxt" , .replace = "&type=\" bold_it\" &col=\" 60FFAC\" " },
19- .{ .base = "$multitxt" , .replace = "&type=\" bold_it\" &col=\" FFE770\" " },
20- .{ .base = "$footnotetxt" , .replace = "&type=\" med_it\" &size=\" 10\" &col=\" 736562\" " },
21- .{ .base = "$hpicon" , .replace = "&space" ++ StatIncreaseData .toControlCode (.{ .max_hp = undefined }) },
22- .{ .base = "$mpicon" , .replace = "&space" ++ StatIncreaseData .toControlCode (.{ .max_mp = undefined }) },
23- .{ .base = "$stricon" , .replace = "&space" ++ StatIncreaseData .toControlCode (.{ .strength = undefined }) },
24- .{ .base = "$deficon" , .replace = "&space" ++ StatIncreaseData .toControlCode (.{ .defense = undefined }) },
25- .{ .base = "$witicon" , .replace = "&space" ++ StatIncreaseData .toControlCode (.{ .wit = undefined }) },
26- .{ .base = "$resicon" , .replace = "&space" ++ StatIncreaseData .toControlCode (.{ .resistance = undefined }) },
27- .{ .base = "$staicon" , .replace = "&space" ++ StatIncreaseData .toControlCode (.{ .stamina = undefined }) },
28- .{ .base = "$inticon" , .replace = "&space" ++ StatIncreaseData .toControlCode (.{ .intelligence = undefined }) },
29- .{ .base = "$spdicon" , .replace = "&space" ++ StatIncreaseData .toControlCode (.{ .speed = undefined }) },
30- .{ .base = "$hsticon" , .replace = "&space" ++ StatIncreaseData .toControlCode (.{ .haste = undefined }) },
8+ const ReplacePair = struct { base : []const u8 , replace : []const u8 };
9+ const macro_mappings = b : {
10+ var ret : []const ReplacePair = &.{};
11+ for (@typeInfo (Stat ).@"enum" .fields ) | field | {
12+ const stat = @field (Stat , field .name );
13+ const shorthand = stat .shorthand ();
14+ ret = ret ++ &[_ ]ReplacePair {.{
15+ .base = "$" ++ shorthand ++ "txt" ,
16+ .replace = std .fmt .comptimePrint ("&type=\" bold_it\" &col=\" {X:0>6}\" " , .{stat .color ()}),
17+ }};
18+ ret = ret ++ &[_ ]ReplacePair {.{
19+ .base = "$" ++ shorthand ++ "icon" ,
20+ .replace = "&space" ++ stat .icon ().comptimeControlCode (),
21+ }};
22+ }
23+ ret = ret ++ &[_ ]ReplacePair {
24+ .{ .base = "$multitxt" , .replace = "&type=\" bold_it\" &col=\" FFE770\" " },
25+ .{ .base = "$footnotetxt" , .replace = "&type=\" med_it\" &size=\" 10\" &col=\" 736562\" " },
26+ };
27+ break :b ret ;
3128};
3229
3330pub var resource : Maps (ResourceData ) = .{};
@@ -232,6 +229,14 @@ pub const TextureData = struct {
232229 sheet : []const u8 ,
233230 index : u16 ,
234231
232+ pub fn controlCode (self : TextureData , buf : []u8 ) ! []const u8 {
233+ return try std .fmt .bufPrint (buf , "&img=\" {s},{d}\" " , .{ self .sheet , self .index });
234+ }
235+
236+ pub fn comptimeControlCode (self : TextureData ) []const u8 {
237+ return std .fmt .comptimePrint ("&img=\" {s},{d}\" " , .{ self .sheet , self .index });
238+ }
239+
235240 pub const ziggy_options = struct {
236241 pub fn parse (parser : * ziggy.Parser , first_tok : ziggy.Tokenizer.Token ) ziggy.Parser.Error ! TextureData {
237242 const map = try parser .parseValue (ziggy .dynamic .Map (u16 ), first_tok );
@@ -508,19 +513,19 @@ pub const GroundData = struct {
508513 animations : ? []const FrameData = null ,
509514};
510515
511- pub const StatIncreaseData = union ( enum ) {
512- max_hp : struct { amount : u16 } ,
513- max_mp : struct { amount : u16 } ,
514- strength : struct { amount : u16 } ,
515- wit : struct { amount : u16 } ,
516- defense : struct { amount : u16 } ,
517- resistance : struct { amount : u16 } ,
518- speed : struct { amount : u16 } ,
519- stamina : struct { amount : u16 } ,
520- intelligence : struct { amount : u16 } ,
521- haste : struct { amount : u16 } ,
522-
523- pub fn toString (self : StatIncreaseData ) []const u8 {
516+ pub const Stat = enum ( u8 ) {
517+ max_hp = 0 ,
518+ max_mp = 1 ,
519+ strength = 2 ,
520+ wit = 3 ,
521+ defense = 4 ,
522+ resistance = 5 ,
523+ speed = 6 ,
524+ stamina = 7 ,
525+ intelligence = 8 ,
526+ haste = 9 ,
527+
528+ pub fn name (self : Stat ) []const u8 {
524529 return switch (self ) {
525530 .max_hp = > "Max HP" ,
526531 .max_mp = > "Max MP" ,
@@ -535,26 +540,63 @@ pub const StatIncreaseData = union(enum) {
535540 };
536541 }
537542
538- pub fn toControlCode (self : StatIncreaseData ) []const u8 {
543+ pub fn shorthand (self : Stat ) []const u8 {
539544 return switch (self ) {
540- .max_hp = > "&img= \" misc_big,0 \" " ,
541- .max_mp = > "&img= \" misc_big,1 \" " ,
542- .strength = > "&img= \" misc_big,2 \" " ,
543- .wit = > "&img= \" misc_big,3 \" " ,
544- .defense = > "&img= \" misc_big,4 \" " ,
545- .resistance = > "&img= \" misc_big,5 \" " ,
546- .stamina = > "&img= \" misc_big,6 \" " ,
547- .intelligence = > "&img= \" misc_big,7 \" " ,
548- .speed = > "&img= \" misc_big,8 \" " ,
549- .haste = > "&img= \" misc_big,9 \" " ,
545+ .max_hp = > "hp " ,
546+ .max_mp = > "mp " ,
547+ .strength = > "str " ,
548+ .wit = > "wit " ,
549+ .defense = > "def " ,
550+ .resistance = > "res " ,
551+ .speed = > "spd " ,
552+ .stamina = > "sta " ,
553+ .intelligence = > "int " ,
554+ .haste = > "hst " ,
550555 };
551556 }
552557
553- pub fn amount (self : StatIncreaseData ) u16 {
558+ pub fn color (self : Stat ) u24 {
554559 return switch (self ) {
555- inline else = > | inner | inner .amount ,
560+ .max_hp = > 0x20AC20 ,
561+ .max_mp = > 0x1C40FF ,
562+ .strength = > 0xFF6C32 ,
563+ .wit = > 0xA15AFF ,
564+ .defense = > 0xFF9670 ,
565+ .resistance = > 0xD65BFF ,
566+ .speed = > 0xC45860 ,
567+ .stamina = > 0xC45860 ,
568+ .intelligence = > 0x6080FF ,
569+ .haste = > 0x60FFAC ,
556570 };
557571 }
572+
573+ pub fn icon (self : Stat ) TextureData {
574+ return switch (self ) {
575+ .max_hp = > .{ .sheet = "misc_big" , .index = 0 },
576+ .max_mp = > .{ .sheet = "misc_big" , .index = 1 },
577+ .strength = > .{ .sheet = "misc_big" , .index = 2 },
578+ .wit = > .{ .sheet = "misc_big" , .index = 3 },
579+ .defense = > .{ .sheet = "misc_big" , .index = 4 },
580+ .resistance = > .{ .sheet = "misc_big" , .index = 5 },
581+ .stamina = > .{ .sheet = "misc_big" , .index = 6 },
582+ .intelligence = > .{ .sheet = "misc_big" , .index = 7 },
583+ .speed = > .{ .sheet = "misc_big" , .index = 8 },
584+ .haste = > .{ .sheet = "misc_big" , .index = 9 },
585+ };
586+ }
587+ };
588+
589+ pub const StatIncreaseData = union (Stat ) {
590+ max_hp : struct { amount : u16 },
591+ max_mp : struct { amount : u16 },
592+ strength : struct { amount : u16 },
593+ wit : struct { amount : u16 },
594+ defense : struct { amount : u16 },
595+ resistance : struct { amount : u16 },
596+ speed : struct { amount : u16 },
597+ stamina : struct { amount : u16 },
598+ intelligence : struct { amount : u16 },
599+ haste : struct { amount : u16 },
558600};
559601
560602pub const StatIncreaseDataPerc = union (enum ) {
0 commit comments