<commit_before>package com.galvarez.ttw.screens;

import java.util.Map.Entry;

import com.artemis.Entity;
import com.artemis.World;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.galvarez.ttw.ThingsThatWereGame;
import com.galvarez.ttw.model.DiscoverySystem;
import com.galvarez.ttw.model.Faction;
import com.galvarez.ttw.model.components.Discoveries;
import com.galvarez.ttw.model.components.Research;
import com.galvarez.ttw.model.data.Discovery;
import com.galvarez.ttw.rendering.ui.FramedMenu;
import com.galvarez.ttw.screens.overworld.OverworldScreen;

/**
 * This screen appears when player must choose his next discovery.
 * 
 * @author <NAME>
 */
public final class AskDiscoveryScreen extends AbstractPausedScreen<OverworldScreen> {

  private final FramedMenu choices;

  private final Discoveries empire;

  private final DiscoverySystem discoverySystem;

  private final Entity player;

  public AskDiscoveryScreen(ThingsThatWereGame game, World world, SpriteBatch batch, OverworldScreen gameScreen,
      Entity player, DiscoverySystem discoverySystem) {
    super(game, world, batch, gameScreen);
    this.player = player;
    this.empire = player.getComponent(Discoveries.class);
    this.discoverySystem = discoverySystem;

    choices = new FramedMenu(skin, 800, 600);
  }

  @Override
  protected void initMenu() {
    choices.clear();

    if (empire.nextPossible == null || empire.nextPossible.isEmpty()) {
      // may be displayed from discovery menu
      choices.addButton("No discoveries to combine!", this::resumeGame);
    } else {
      choices.addLabel("Which faction do you choose to make new discoveries?");
      for (Entry<Faction, Research> next : empire.nextPossible.entrySet())
        choices.addButton(action(next.getKey()), previousString(next.getValue()), () -> newDiscovery(next.getValue()),
            true);

      choices.addLabel(" ");
      choices.addButton("Choose later...", this::resumeGame);
    }

    choices.addToStage(stage, -1, -1, true);
  }

  private static String previousString(Research next) {
    if (next.previous.isEmpty())
      return "our environment";

    StringBuilder sb = new StringBuilder();
    for (Discovery previous : next.previous)
      sb.append(previous.name).append(", ");
    sb.setLength(sb.length() - 2);
    return sb.toString();
  }

  private static String action(Faction faction) {
    switch (faction) {
      case CULTURAL:
        return "Cultural faction advises to meditate on ";
      case ECONOMIC:
        return "Economic faction suggest we pursue profit in ";
      case MILITARY:
        return "Military faction commands us to investigate ";
      default:
        throw new IllegalStateException("Unknown faction " + faction);
    }
  }

  private void newDiscovery(Research next) {
    discoverySystem.discoverNew(player, empire, next);

    choices.clear();

    StringBuilder sb = new StringBuilder("We discovered " + next.target.name + "!");
    for (String effect : discoverySystem.effectsStrings(empire.last.target))
      sb.append("\n - " + effect);
    choices.addButton(sb.toString(), this::resumeGame);

    choices.addToStage(stage, -1, -1, true);
  }
}<commit_msg>@enh Show the choice made when displaying the consequence.<commit_after>package com.galvarez.ttw.screens;

import com.artemis.Entity;
import com.artemis.World;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.galvarez.ttw.ThingsThatWereGame;
import com.galvarez.ttw.model.DiscoverySystem;
import com.galvarez.ttw.model.Faction;
import com.galvarez.ttw.model.components.Discoveries;
import com.galvarez.ttw.model.components.Research;
import com.galvarez.ttw.model.data.Discovery;
import com.galvarez.ttw.rendering.ui.FramedMenu;
import com.galvarez.ttw.screens.overworld.OverworldScreen;

import java.util.Map.Entry;

/**
 * This screen appears when player must choose his next discovery.
 * 
 * @author <NAME>
 */
public final class AskDiscoveryScreen extends AbstractPausedScreen<OverworldScreen> {

  private final FramedMenu choices;

  private final Discoveries empire;

  private final DiscoverySystem discoverySystem;

  private final Entity player;

  public AskDiscoveryScreen(ThingsThatWereGame game, World world, SpriteBatch batch, OverworldScreen gameScreen,
      Entity player, DiscoverySystem discoverySystem) {
    super(game, world, batch, gameScreen);
    this.player = player;
    this.empire = player.getComponent(Discoveries.class);
    this.discoverySystem = discoverySystem;

    choices = new FramedMenu(skin, 800, 600);
  }

  @Override
  protected void initMenu() {
    choices.clear();

    if (empire.nextPossible == null || empire.nextPossible.isEmpty()) {
      // may be displayed from discovery menu
      choices.addButton("No discoveries to combine!", this::resumeGame);
    } else {
      choices.addLabel("Which faction do you choose to make new discoveries?");
      for (Entry<Faction, Research> next : empire.nextPossible.entrySet()) {
        String label = action(next.getKey()) + previousString(next.getValue());
        choices.addButton(label, () -> newDiscovery(label, next.getValue()));
      }

      choices.addLabel(" ");
      choices.addButton("Choose later...", this::resumeGame);
    }

    choices.addToStage(stage, -1, -1, true);
  }

  private static String previousString(Research next) {
    if (next.previous.isEmpty())
      return "our environment";

    StringBuilder sb = new StringBuilder();
    for (Discovery previous : next.previous)
      sb.append(previous.name).append(", ");
    sb.setLength(sb.length() - 2);
    return sb.toString();
  }

  private static String action(Faction faction) {
    switch (faction) {
      case CULTURAL:
        return "Cultural faction advises to meditate on ";
      case ECONOMIC:
        return "Economic faction suggest we pursue profit in ";
      case MILITARY:
        return "Military faction commands us to investigate ";
      default:
        throw new IllegalStateException("Unknown faction " + faction);
    }
  }

  private void newDiscovery(String label, Research next) {
    discoverySystem.discoverNew(player, empire, next);

    choices.clear();

    StringBuilder sb = new StringBuilder("We discovered " + next.target.name + "!");
    for (String effect : discoverySystem.effectsStrings(empire.last.target))
      sb.append("\n - " + effect);
    choices.addLabel(label + "...");
    choices.addButton(sb.toString(), this::resumeGame);

    choices.addToStage(stage, -1, -1, true);
  }
}
{'fraction_non_alphanumeric': 0.11344795824378262, 'fraction_numerical': 0.00368437212158428, 'mean_word_length': 3.776392961876833, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6199519', 'n_tokens_mistral': 1964, 'n_tokens_neox': 1868, 'n_words': 464}