A SpaceTraders Agent
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

custom ship pretty printing

Altagos a92c5b1f 04cfde05

+106 -22
+106 -22
src/st/models/ships.zig
··· 1 1 const m = @import("../models.zig"); 2 2 const Cooldown = m.Cooldown; 3 3 4 + const prettym = @import("pretty"); 5 + 4 6 pub const Ship = struct { 5 7 symbol: []const u8, 6 8 registration: Registration, ··· 14 16 cargo: m.inventory.Cargo, 15 17 fuel: Fuel, 16 18 cooldown: Cooldown, 19 + 20 + pub fn pretty( 21 + this: *const @This(), 22 + comptime ctx: prettym.Context, 23 + run: *const prettym.Runtime, 24 + ) error{WriteFailed}!void { 25 + run.setColor(ctx, .dim); 26 + try run.write("<#Ship:"); 27 + run.resetColor(); 28 + 29 + run.setColor(ctx, .string); 30 + try run.write(this.symbol); 31 + run.setColor(ctx, .dim); 32 + try run.print("[{s}] ", .{@tagName(this.registration.role)}); 33 + run.resetColor(); 34 + 35 + try this.nav.pretty(ctx, run); 36 + 37 + run.setColor(ctx, .field); 38 + try run.write("fuel="); 39 + run.resetColor(); 40 + 41 + run.setColor(ctx, .value); 42 + try run.print("{}/{} ", .{ this.fuel.current, this.fuel.capacity }); 43 + run.resetColor(); 44 + 45 + run.setColor(ctx, .field); 46 + try run.write("cargo="); 47 + run.resetColor(); 48 + 49 + run.setColor(ctx, .value); 50 + try run.print("{}/{} ", .{ this.cargo.units, this.cargo.capacity }); 51 + run.resetColor(); 52 + 53 + run.setColor(ctx, .dim); 54 + try run.write("#>"); 55 + run.resetColor(); 56 + } 17 57 }; 18 58 19 59 pub const Registration = struct { ··· 51 91 origin: Waypoint, 52 92 departureTime: []const u8, 53 93 arrival: []const u8, 94 + }; 54 95 55 - pub const Waypoint = struct { 56 - symbol: []const u8, 57 - type: Type, 58 - systemSymbol: []const u8, 59 - x: i64, 60 - y: i64, 96 + pub const Waypoint = struct { 97 + symbol: []const u8, 98 + type: Type, 99 + systemSymbol: []const u8, 100 + x: i64, 101 + y: i64, 61 102 62 - pub const Type = enum { 63 - PLANET, 64 - GAS_GIANT, 65 - MOON, 66 - ORBITAL_STATION, 67 - JUMP_GATE, 68 - ASTEROID_FIELD, 69 - ASTEROID, 70 - ENGINEERED_ASTEROID, 71 - ASTEROID_BASE, 72 - NEBULA, 73 - DEBRIS_FIELD, 74 - GRAVITY_WELL, 75 - ARTIFICIAL_GRAVITY_WELL, 76 - FUEL_STATION, 77 - }; 103 + pub const Type = enum { 104 + PLANET, 105 + GAS_GIANT, 106 + MOON, 107 + ORBITAL_STATION, 108 + JUMP_GATE, 109 + ASTEROID_FIELD, 110 + ASTEROID, 111 + ENGINEERED_ASTEROID, 112 + ASTEROID_BASE, 113 + NEBULA, 114 + DEBRIS_FIELD, 115 + GRAVITY_WELL, 116 + ARTIFICIAL_GRAVITY_WELL, 117 + FUEL_STATION, 78 118 }; 119 + 120 + pub fn pretty( 121 + this: *const @This(), 122 + comptime ctx: prettym.Context, 123 + run: *const prettym.Runtime, 124 + ) error{WriteFailed}!void { 125 + run.setColor(ctx, .value); 126 + try run.write(this.symbol); 127 + run.setColor(ctx, .dim); 128 + try run.print("[{s}] ", .{@tagName(this.type)}); 129 + run.resetColor(); 130 + } 79 131 }; 80 132 81 133 pub const Status = enum { ··· 90 142 CRUISE, 91 143 BURN, 92 144 }; 145 + 146 + pub fn pretty( 147 + this: *const @This(), 148 + comptime ctx: prettym.Context, 149 + run: *const prettym.Runtime, 150 + ) error{WriteFailed}!void { 151 + switch (this.status) { 152 + .IN_TRANSIT => { 153 + run.setColor(ctx, .field); 154 + try run.write("in transit="); 155 + run.resetColor(); 156 + 157 + run.setColor(ctx, .value); 158 + try this.route.origin.pretty(ctx, run); 159 + run.setColor(ctx, .dim); 160 + try run.write(" -> "); 161 + run.resetColor(); 162 + }, 163 + .IN_ORBIT => { 164 + run.setColor(ctx, .field); 165 + try run.write("orbiting="); 166 + run.resetColor(); 167 + }, 168 + .DOCKED => { 169 + run.setColor(ctx, .field); 170 + try run.write("docked at="); 171 + run.resetColor(); 172 + }, 173 + } 174 + 175 + try this.route.destination.pretty(ctx, run); 176 + } 93 177 }; 94 178 95 179 pub const Crew = struct {