# Quickstart: run the example apps

| Counters | Frontier |
| --- | --- |
| ![Counters index](screenshots/counters.jpg) | ![Frontier multiplayer map](screenshots/frontier.jpg) |

## Prerequisites

- Git and access to the FoW repository. Clone it and enter the checkout:

  ```sh
  git clone git@github.com:mrluc/fow.git
  cd fow
  ```
- Elixir 1.20.4 and Erlang/OTP 29.0.6, as pinned in `.tool-versions`. Run `mix local.hex` from the checkout if Hex is missing.
- For macOS builds, install Rust and the Xcode command-line tools. The generated build runs `cargo tauri`. If `cargo tauri --version` fails, install it once with `cargo install tauri-cli --version '^2' --locked`. Both Cargo commands can run from any directory.
- For Android builds, install Android Studio, its Android SDK and Platform Tools, and the [Mob toolchain](https://mob.hexdocs.pm/getting_started.html). From the FoW checkout, run `mix archive.install hex mob_new` once to install the Mix generator. The generated app fetches the public WebView dependency over HTTPS.


For either Android example, open Android Studio’s Device Manager and create
a virtual device if you need one. List and start it from a terminal with the
Android SDK tools on your PATH:

```sh
emulator -list-avds
emulator -avd YOUR_AVD_NAME
```

Choose a name from the list. When Android finishes booting, check
`adb devices` in a second terminal. The examples below assume one connected
device. If you have several, use `adb -s SERIAL reverse …` and add
`--device SERIAL` to `mix fow.mobile`.


## Example: Counters app

Counters has three routes with increment buttons. Visit One, increment it, and return to the list. Open the Fog of War panel and pause the socket. One still opens at the saved value, and its increment button is disabled. Three stays unavailable until you visit it online. The Cache tab shows the saved route and its payload. Resume the socket to use the counter again.

![Counters offline with the DevTools cache open](screenshots/counters-offline.jpg)

The integration is in these files under `examples/basic/`:

- `mix.exs` adds the checkout as a path dependency.
- `assets/js/app.js` registers the FoW hook and installs the coordinator before connecting LiveSocket.
- `lib/fog_of_war_basic_web/components/layouts.ex` wraps routed content with `FogOfWar.region` and renders `FogOfWar.dev_tools`.
- `.fow.json` makes the index the startup document and preloads One and Two in native builds. `config/dev.exs` enables the DevTools locally.

### Run Counters locally

From the repository root:

```sh
cd examples/basic
mix setup
mix phx.server
```

Open [the local Counters demo](http://127.0.0.1:47180/). Keep Phoenix running for the following builds.

### Build and run Counters on macOS

In a second terminal, from `examples/basic`:

```sh
mix fow.desktop
```

Press **⌘ Space** and search for **Counters**. The app is installed in
`~/Applications`. Use `mix fow.desktop --force` to rebuild and replace it.

### Build and run Counters on Android

With Phoenix and the emulator running, use a second terminal from `examples/basic`:

```sh
adb reverse tcp:47180 tcp:47180
mix fow.mobile --env android-dev --platform android
```

Open **Counters** from the emulator’s launcher. Add `--force` to refresh the
prepared bundle and replace the generated project. After the first build,
you can open `.fow/android-dev/projects/mobile/android/` in Android Studio.

## Example: Frontier multiplayer app

Frontier is an isometric multiplayer game. Move around online to explore, then toggle offline and revisit explored squares. Reconnect to resume the game. The native bundle ships the startup document and its artwork.

### Run Frontier locally

From the repository root:

```sh
cd examples/frontier
mix setup
mix phx.server
```

Open [the local Frontier demo](http://127.0.0.1:47190/multi/lat/0/lon/0). Keep Phoenix running for the following builds.

### Build and run Frontier on macOS

In a second terminal, from `examples/frontier`:

```sh
mix fow.desktop
```

Press **⌘ Space** and search for **Frontier**. The app is installed in
`~/Applications`. Use `mix fow.desktop --force` to rebuild and replace it.

### Build and run Frontier on Android

With Phoenix and the emulator running, use a second terminal from `examples/frontier`:

```sh
adb reverse tcp:47190 tcp:47190
mix fow.mobile --env android-dev --platform android
```

Open **Frontier** from the emulator’s launcher. Add `--force` to refresh the
prepared bundle and replace the generated project. After the first build,
you can open `.fow/android-dev/projects/mobile/android/` in Android Studio.
