From 9ed7d7ab2fc70f971aa18d61f5ea04b346c836a3 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sun, 6 Nov 2022 21:44:56 +0100 Subject: render planet names --- web/planetwars-rs/src/lib.rs | 5 ++++- web/pw-visualizer/assets/shaders/frag/msdf.glsl | 3 ++- web/pw-visualizer/src/index.ts | 29 +++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 4 deletions(-) (limited to 'web') diff --git a/web/planetwars-rs/src/lib.rs b/web/planetwars-rs/src/lib.rs index f2ba7e1..85a1d8f 100644 --- a/web/planetwars-rs/src/lib.rs +++ b/web/planetwars-rs/src/lib.rs @@ -150,7 +150,6 @@ pub struct Game { planet_map: HashMap<(String, String), Circle>, - /* put extra shit here */ view_box: Vec, planets: Vec, @@ -240,6 +239,10 @@ impl Game { self.current_planet_colours.clone() } + pub fn get_planet_name(&self, planet_idx: usize) -> String { + self.states[self.turn].planets[planet_idx].name.clone() + } + pub fn turn_count(&self) -> usize { self.states.len() } diff --git a/web/pw-visualizer/assets/shaders/frag/msdf.glsl b/web/pw-visualizer/assets/shaders/frag/msdf.glsl index 5d2325b..23bacfc 100644 --- a/web/pw-visualizer/assets/shaders/frag/msdf.glsl +++ b/web/pw-visualizer/assets/shaders/frag/msdf.glsl @@ -24,6 +24,7 @@ void main() { float sd = median(msd.r, msd.g, msd.b); float screenPxRange = max(u_distanceRange, scale); float screenPxDistance = screenPxRange*(sd - 0.5); - float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0); + // float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0); + float opacity = clamp(0.0, 1.0, screenPxDistance + 0.5); gl_FragColor = vec4(u_fgColor.rgb, u_fgColor.a * opacity); } \ No newline at end of file diff --git a/web/pw-visualizer/src/index.ts b/web/pw-visualizer/src/index.ts index 97bdb3d..4c99311 100644 --- a/web/pw-visualizer/src/index.ts +++ b/web/pw-visualizer/src/index.ts @@ -140,6 +140,7 @@ export class GameInstance { renderer: Renderer; planet_count: number; + planet_names: string[]; vor_builder: VoronoiBuilder; @@ -162,7 +163,12 @@ export class GameInstance { ) { this.game = game; const planets = game.get_planets(); - this.planet_count = planets.length; + this.planet_count = planets.length / 3; + + this.planet_names = []; + for (let i = 0; i < this.planet_count; i++) { + this.planet_names.push(this.game.get_planet_name(i)); + } this.shader = shaders["normal"].create_shader(GL, { MAX_CIRCLES: "" + planets.length, @@ -285,7 +291,7 @@ export class GameInstance { 1, 0, -planets[i * 3], - -planets[i * 3 + 1] - 1.171875, + -planets[i * 3 + 1] + 0.2 - 2*1.171875, 1, ]); @@ -293,6 +299,24 @@ export class GameInstance { this.planet_labels.push(label); this.renderer.addRenderable(label.getRenderable(), LAYERS.planet_label); } + + { + const transform = new UniformMatrix3fv([ + 1, + 0, + 0, + 0, + 1, + 0, + -planets[i * 3], + -planets[i * 3 + 1] + 0.2 - 1*1.171875, + 1, + ]); + + const label = this.msdf_text_factory.build(GL, transform); + label.setText(GL, this.planet_names[i], Align.Middle, Align.Begin); + this.renderer.addRenderable(label.getRenderable(), LAYERS.planet_label); + } } } @@ -337,6 +361,7 @@ export class GameInstance { this.planet_labels[i].setText( GL, + // this.planet_names[i] + " " + "" + planet_ships[i], Align.Middle, Align.Begin -- cgit v1.2.3