<commit_before>// Copyright (c) 2015, <NAME>. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

import 'package:august/august.dart';
import 'package:august/options.dart';
import 'package:august/scenes.dart';
import 'package:august/dialog.dart';
import 'package:august/prompts.dart';
import 'package:august/ui/html/html_persistence.dart';
import 'package:august/ui/html/html_ui.dart';
import 'package:rxdart/rxdart.dart';

import 'dart:html';

import 'package:pedantic/pedantic.dart';

// Instantiate modules top level for easy accessibility from script methods
final story = Story();
final scenes = Scenes();
final options = Options(
    defaultScope: () => scenes.currentScene.cast<Scope>().orElse(always));
final dialog = Dialog(story,
    defaultScope: () => scenes.currentScene.cast<Scope>().orElse(always));
final prompts = Prompts();

void main() {
  // TODO: How will users know how to do this setup for all modules they want
  // to use? How will we give feedback when not setup correctly?
  // Probably worth trimming and refactoring this so setup is very tiny, and
  // invalid setup fails at compile time.

  // Boilerplate time tracking
  var clock = Clock();

  // Need a persistence strategy
  var persistence = NoPersistence();

  var modules = {
    Options: options,
    Dialog: dialog
  };
  var events = Rx.merge([options.events, dialog.events]).asBroadcastStream();

  // Present the user interface(s) with HTML
  SimpleHtmlUi.install(querySelector('#example'), events)
      .actions
      .listen((action) {
        // TODO: intercept and save actions for replay
        action.run(modules[action.module]);
  });

  // TODO run so saved actions are replayed
  example();
}

void example() async {
  dragonStandoff();
}

void dragonStandoff() async {
  var dragonStandoff = await scenes.reentrant().enter();
  var sword = Sword();

  dialog.narrate('Something appears in the shadows...');

  await delay(seconds: 1);

  var attack = options.oneTime('Engage your curiosity and wait');
  var runAway = options.limitedUse('Run away', exclusiveWith: attack.uses);

  attack.onUse.when(() {
    attackDragon(dragonStandoff, sword);
  });

  runAway.onUse.when(() async {
    dragonStandoff.done();
    runAwayFromDragon(sword);
  });
}

void attackDragon(Scene dragonStandoff, Sword sword) async {
  await scenes.oneTime().enter();

  var beast = dialog.voice(name: '(mysterious beast)');

  dialog.narrate('It moves closer. By its size, it appears close, '
      'but you hear its purr, far away.');

  beast.say('Prrrrrr....');

  await delay(seconds: 6);

  dialog.narrate("You don't just hear the purr. A second later, you feel the "
      'walls shake at the rhythm of its rattle.');

  await delay(seconds: 6);

  dialog.narrate("Closer still. And louder. It's clearly massive now.");

  await delay(seconds: 6);

  dialog.narrate("A red and orange glow rises to the front of it: it's mouth. "
      'Illuminated from below, you see large, snake-like eyes narrow at you. '
      'It snorts a flame. You feel a rush of warm air towards you. A warning.');

  await delay(seconds: 10);

  dialog.add('(whispering to yourself) Are those whiskers?');

  await delay(seconds: 4);

  dialog.narrate("It's head rises. It's eyes do not leave you. "
      'As it does this, you feel the air behind you push you towards the '
      "creature. It's inhaling.");

  await delay(seconds: 10);

  dialog.narrate('The same glow begins rising again. Its eyes fill up with '
      'madness and delight and fire. Flame spews out with explosive force, as '
      'if its mouth were a door to a burning building, blast open.');

  var deflectWithSword = options.oneTime('Deflect the fire with your sword.');
  var deflectWithShield = options.oneTime('Deflect the fire with your shield.');
  var dash = options.oneTime('Dash toward the creature.');

  delay(seconds: 10).then((_) {

  });

  deflectWithSword.onUse.when(() async {
    dialog.narrate('You survive, but your sword has melted!',
        scope: dragonStandoff);
    options.oneTime('Throw the stub of your sword at the dragon.',
        available: dragonStandoff);
    sword.isMelted.value = true;
    await dragonStandoff.enter();
  });

  deflectWithShield.onUse.when(() async {
    await scenes.oneTime().enter();
    dialog.narrate('Your shield sets aflame and you suffer terrible burns.');
  });

  dash.onUse.when(() async {
    await scenes.oneTime().enter();
    dialog.narrate('You make it underneath the dragon, unharmed.');
  });
}

void runAwayFromDragon(Sword sword) async {
  await scenes.oneTime().enter();
<commit_msg>Go back to old example because it's quicker<commit_after>// Copyright (c) 2015, <NAME>. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

import 'dart:html';

import 'package:august/august.dart';
import 'package:august/dialog.dart';
import 'package:august/options.dart';
import 'package:august/prompts.dart';
import 'package:august/scenes.dart';
import 'package:august/ui/html/html_ui.dart';
import 'package:rxdart/rxdart.dart';

// Instantiate modules top level for easy accessibility from script methods
final story = Story();
final scenes = Scenes();
final options = Options(
    defaultScope: () => scenes.currentScene.cast<Scope>().orElse(always));
final dialog = Dialog(story,
    defaultScope: () => scenes.currentScene.cast<Scope>().orElse(always));
final prompts = Prompts();

void main() {
  // TODO: How will users know how to do this setup for all modules they want
  // to use? How will we give feedback when not setup correctly?
  // Probably worth trimming and refactoring this so setup is very tiny, and
  // invalid setup fails at compile time.

  // Boilerplate time tracking
  var clock = Clock();

  // Need a persistence strategy
  var persistence = NoPersistence();

  var modules = {Options: options, Dialog: dialog};
  var events = Rx.merge([options.events, dialog.events]).asBroadcastStream();

  // Present the user interface(s) with HTML
  SimpleHtmlUi.install(querySelector('#example'), events)
      .actions
      .listen((action) {
    // TODO: intercept and save actions for replay
    action.run(modules[action.module]);
  });

  // TODO run so saved actions are replayed
  example();
}

void example() async {
  dragonStandoff();
}

void dragonStandoff() async {
  var dragonStandoff = await scenes.reentrant().enter();
  var sword = Sword();

  dialog.narrate('A dragon stands before you!');

  await delay(seconds: 1);

  var attack = options.oneTime('Attack it!');
  var runAway = options.limitedUse('Run away!', exclusiveWith: attack.uses);

  attack.onUse.when(() {
    attackDragon(dragonStandoff, sword);
  });

  runAway.onUse.when(() async {
    dragonStandoff.done();
    runAwayFromDragon(sword);
  });
}

void attackDragon(Scene dragonStandoff, Sword sword) async {
  await scenes.oneTime().enter();

  dialog.narrate('The dragon readies its flame...');

  await delay(seconds: 1);

  var deflectWithSword = options.oneTime('Deflect the fire with your sword.');
  var deflectWithShield = options.oneTime('Deflect the fire with your shield.');
  var dash = options.oneTime('Dash toward the dragon.');

  deflectWithSword.onUse.when(() async {
    dialog.narrate('You survive, but your sword has melted!',
        scope: dragonStandoff);
    options.oneTime('Throw the stub of your sword at the dragon.',
        available: dragonStandoff);
    sword.isMelted.value = true;
    await dragonStandoff.enter();
  });

  deflectWithShield.onUse.when(() async {
    await scenes.oneTime().enter();
    dialog.narrate('Your shield sets aflame and you suffer terrible burns.');
  });

  dash.onUse.when(() async {
    await scenes.oneTime().enter();
    dialog.narrate('You make it underneath the dragon, unharmed.');
  });
}

void runAwayFromDragon(Sword sword) async {
  await scenes.oneTime().enter();

{'fraction_non_alphanumeric': 0.12573575453976205, 'fraction_numerical': 0.002629931120851597, 'mean_word_length': 3.8606208155812536, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '3185606', 'n_tokens_mistral': 2464, 'n_tokens_neox': 2385, 'n_words': 782}