name: opensurge
base: core18
version: '0.5.1.1'
summary: A fun 2D retro platformer inspired by Sonic games
description: |
  Open Surge is a fun 2D retro platformer inspired by Sonic games
  and a game creation system that lets you unleash your creativity!
  Play, create & share!

grade: stable
confinement: strict
icon: opensurge.png

apps:
  opensurge:
    command: desktop-launch $SNAP/bin/opensurge --base "$SNAP/usr/share/games/opensurge"
    desktop: usr/share/applications/opensurge.desktop
    environment:
      LD_LIBRARY_PATH: "$LD_LIBRARY_PATH:/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio"
      DISABLE_WAYLAND: 1
    plugs:
      - home
      - desktop
      - desktop-legacy
      - audio-playback
      - x11
      - opengl
      - joystick

parts:
  opensurge:
    after: [desktop-glib-only, liballegro5, surgescript]
    source: https://github.com/alemart/opensurge.git
    source-tag: v0.5.1.1
    plugin: cmake
    override-build: |
      set -eu
      cd "$SNAPCRAFT_PART_BUILD"
      cmake "$SNAPCRAFT_PART_SRC" \
        "-DCMAKE_BUILD_TYPE=Release" \
        "-DBLEEDING_EDGE=OFF" \
        "-DALLEGRO_MONOLITH=OFF" \
        "-DCMAKE_LIBRARY_PATH=$SNAPCRAFT_STAGE/lib" \
        "-DCMAKE_INSTALL_PREFIX=$SNAPCRAFT_PART_INSTALL/bin" \
        "-DGAME_DATADIR=/usr/share/games/opensurge" \
        "-DDESKTOP_INSTALL=ON" \
        "-DDESKTOP_ENTRY_PATH=$SNAPCRAFT_PART_INSTALL/usr/share/applications" \
        "-DDESKTOP_ICON_PATH=$SNAPCRAFT_PART_INSTALL/usr/share/pixmaps"
      make -j2 && make install
      mkdir -p "$SNAPCRAFT_PART_INSTALL/usr/share/games"
      mv /usr/share/games/opensurge "$SNAPCRAFT_PART_INSTALL/usr/share/games"
      sed -i 's|^Icon=.*|Icon=\${SNAP}/usr/share/pixmaps/opensurge\.png|' "$SNAPCRAFT_PART_INSTALL/usr/share/applications/opensurge.desktop"
    build-packages:
      - build-essential
    stage-packages:
      - libasyncns0
      - libatk1.0-0
      - libcairo2
      - libdatrie1
      - libflac8
      - libfontconfig1
      - libfreetype6
      - libgdk-pixbuf2.0-0
      - libglvnd0
      - libglx0
      - libgraphite2-3
      - libgtk2.0-0
      - libharfbuzz0b
      - libjpeg-turbo8
      - libogg0
      - libopengl0
      - libpango-1.0-0
      - libpangocairo-1.0-0
      - libpangoft2-1.0-0
      - libpixman-1-0
      - libpng16-16
      - libpulse0
      - libsndfile1
      - libthai0
      - libvorbis0a
      - libvorbisenc2
      - libvorbisfile3
      - libx11-6
      - libxau6
      - libxcb-render0
      - libxcb-shm0
      - libxcb1
      - libxcomposite1
      - libxcursor1
      - libxdamage1
      - libxdmcp6
      - libxext6
      - libxfixes3
      - libxi6
      - libxinerama1
      - libxrandr2
      - libxrender1
      - libphysfs1

  surgescript:
    source: https://github.com/alemart/surgescript.git
    source-tag: v0.5.4.2
    plugin: cmake
    configflags:
      - -DCMAKE_BUILD_TYPE=Release
    build-packages:
      - build-essential

  liballegro5:
    source: https://github.com/liballeg/allegro5.git
    source-tag: 5.2.5.0
    plugin: cmake
    configflags:
      - -DCMAKE_BUILD_TYPE=Release
      - -DWANT_DEMO=OFF
      - -DWANT_DOCS=OFF
      - -DWANT_EXAMPLES=OFF
      - -DWANT_TESTS=OFF
    build-packages: # lean A5
      - build-essential
      - zlib1g-dev
      - libvorbis-dev
      - libogg-dev
      - libpulse-dev
      - libpng-dev
      - libjpeg8-dev
      - libfreetype6-dev
      - libphysfs-dev
      - libgtk2.0-dev
      - libglu1-mesa-dev
      - libgl1-mesa-dev

  desktop-glib-only:
    source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
    source-subdir: glib-only
    plugin: make
    build-packages:
      - libglib2.0-dev
    stage-packages:
      - libglib2.0-bin
