diff options
| author | Jedidiah Barber <contact@jedbarber.id.au> | 2025-04-16 15:22:40 +1200 | 
|---|---|---|
| committer | Jedidiah Barber <contact@jedbarber.id.au> | 2025-04-16 15:22:40 +1200 | 
| commit | b3455e502f4491af22e190a14aba9565f534bb59 (patch) | |
| tree | 23b823b177e8639fb5d42e17311bdc2d70a016b2 /src | |
| parent | e62c2e2403d072640f0400c499f1dfd99e938c16 (diff) | |
Sokoban can now find itself to find shared data after install
Diffstat (limited to 'src')
| -rw-r--r-- | src/displays.ads | 5 | ||||
| -rw-r--r-- | src/misc.ads | 28 | ||||
| -rw-r--r-- | src/sokoban.adb | 12 | ||||
| -rw-r--r-- | src/squares.ads | 24 | ||||
| -rw-r--r-- | src/things.ads | 12 | 
5 files changed, 48 insertions, 33 deletions
| diff --git a/src/displays.ads b/src/displays.ads index 22f3bed..b278b6f 100644 --- a/src/displays.ads +++ b/src/displays.ads @@ -7,6 +7,7 @@ with  private with +    Ada.Directories,      FLTK.Widgets.Boxes,      FLTK.Images.RGB.PNG,      Misc; @@ -108,8 +109,8 @@ private      end record; -    Logo : FLTK.Images.RGB.PNG.PNG_Image := -        FLTK.Images.RGB.PNG.Forge.Create (Misc.Origin & "/../share/sokoban/img/man.png"); +    Logo : FLTK.Images.RGB.PNG.PNG_Image := FLTK.Images.RGB.PNG.Forge.Create +        (Ada.Directories.Compose (Misc.Image_Path, "man.png"));      Text_Size : constant FLTK.Font_Size := 12; diff --git a/src/misc.ads b/src/misc.ads index fb99d95..ad64b46 100644 --- a/src/misc.ads +++ b/src/misc.ads @@ -1,22 +1,21 @@ -with +private with -    Ada.Command_Line, -    Ada.Directories; +    Ada.Directories, +    Here_I_Am;  package Misc is -    Origin : constant String; +    Origin, Image_Path, Level_Path : constant String;      function Max             (A, B : in Integer)          return Integer; -      function Min             (A, B : in Integer)          return Integer; @@ -25,9 +24,24 @@ package Misc is  private -    Origin : constant String := Ada.Directories.Containing_Directory -        (Ada.Directories.Full_Name (Ada.Command_Line.Command_Name)); +    package ADir renames Ada.Directories; + + +    Origin : constant String := ADir.Containing_Directory (Here_I_Am.Executable); + +    Image_Path : constant String := +        ADir.Compose +       (ADir.Compose +       (ADir.Compose +       (ADir.Compose (Origin, ".."), "share"), "sokoban"), "img"); + +    Level_Path : constant String := +        ADir.Compose +       (ADir.Compose +       (ADir.Compose +       (ADir.Compose (Origin, ".."), "share"), "sokoban"), "level");  end Misc; + diff --git a/src/sokoban.adb b/src/sokoban.adb index ad17090..8b7ecdb 100644 --- a/src/sokoban.adb +++ b/src/sokoban.adb @@ -2,6 +2,7 @@  with +    Ada.Directories,      FLTK.Widgets,      Displays,      Grids, @@ -22,6 +23,11 @@ use  package body Sokoban is +    package ADir renames Ada.Directories; + + + +      --  Forward declarations of helper functions.      procedure Add_New_Grid_Item @@ -40,8 +46,6 @@ package body Sokoban is      type Game_State is (Loading, Play, Complete); -    Level_Dir : String := Misc.Origin & "/../share/sokoban/level"; -      Loading_Message : String := "Loading...";      Play_Message : String := "Move with the arrow keys. Press u for undo." & ASCII.LF & @@ -84,8 +88,8 @@ package body Sokoban is          use Ada.Strings, Ada.Strings.Fixed, Ada.Strings.Maps;          Data_File : File_Type; -        Filename : String := -            Level_Dir & "/level" & Trim (LevelID'Image (Number), Both) & ".data"; +        Filename : String := ADir.Compose +            (Misc.Level_Path, "level" & Trim (LevelID'Image (Number), Both) & ".data");          Rows, Cols : Natural;      begin diff --git a/src/squares.ads b/src/squares.ads index 8ab911e..8a1f053 100644 --- a/src/squares.ads +++ b/src/squares.ads @@ -6,6 +6,7 @@ with  private with +    Ada.Directories,      FLTK.Images.RGB.PNG,      Misc; @@ -64,30 +65,27 @@ private      end record; -    Image_Dir : String := Misc.Origin & "/../share/sokoban/img"; - - -    Wall_Image : aliased FLTK.Images.RGB.PNG.PNG_Image := -        FLTK.Images.RGB.PNG.Forge.Create (Image_Dir & "/wall.png"); -    Space_Image : aliased FLTK.Images.RGB.PNG.PNG_Image := -        FLTK.Images.RGB.PNG.Forge.Create (Image_Dir & "/space.png"); -    Empty_Image : aliased FLTK.Images.RGB.PNG.PNG_Image := -        FLTK.Images.RGB.PNG.Forge.Create (Image_Dir & "/empty.png"); -    Goal_Image : aliased FLTK.Images.RGB.PNG.PNG_Image := -        FLTK.Images.RGB.PNG.Forge.Create (Image_Dir & "/goal.png"); +    Wall_Image  : aliased FLTK.Images.RGB.PNG.PNG_Image := FLTK.Images.RGB.PNG.Forge.Create +        (Ada.Directories.Compose (Misc.Image_Path, "wall.png")); +    Space_Image : aliased FLTK.Images.RGB.PNG.PNG_Image := FLTK.Images.RGB.PNG.Forge.Create +        (Ada.Directories.Compose (Misc.Image_Path, "space.png")); +    Empty_Image : aliased FLTK.Images.RGB.PNG.PNG_Image := FLTK.Images.RGB.PNG.Forge.Create +        (Ada.Directories.Compose (Misc.Image_Path, "empty.png")); +    Goal_Image  : aliased FLTK.Images.RGB.PNG.PNG_Image := FLTK.Images.RGB.PNG.Forge.Create +        (Ada.Directories.Compose (Misc.Image_Path, "goal.png"));      Void : constant Square :=          (Walkable => False, Contents => Things.Nothing, Self_Image => null); -    Wall : constant Square := +    Wall  : constant Square :=          (Walkable => False, Contents => Things.Nothing, Self_Image => Wall_Image'Access);      Space : constant Square :=          (Walkable => False, Contents => Things.Nothing, Self_Image => Space_Image'Access);      Empty : constant Square :=          (Walkable => True, Contents => Things.Nothing, Self_Image => Empty_Image'Access); -    Goal : constant Square := +    Goal  : constant Square :=          (Walkable => True, Contents => Things.Nothing, Self_Image => Goal_Image'Access); diff --git a/src/things.ads b/src/things.ads index 7257029..97889ba 100644 --- a/src/things.ads +++ b/src/things.ads @@ -2,6 +2,7 @@  private with +    Ada.Directories,      FLTK.Images.RGB.PNG,      Misc; @@ -36,13 +37,10 @@ private      end record; -    Image_Dir : String := Misc.Origin & "/../share/sokoban/img"; - - -    Man_Image : aliased FLTK.Images.RGB.PNG.PNG_Image := -        FLTK.Images.RGB.PNG.Forge.Create (Image_Dir & "/man.png"); -    Treasure_Image : aliased FLTK.Images.RGB.PNG.PNG_Image := -        FLTK.Images.RGB.PNG.Forge.Create (Image_Dir & "/treasure.png"); +    Man_Image : aliased FLTK.Images.RGB.PNG.PNG_Image := FLTK.Images.RGB.PNG.Forge.Create +        (Ada.Directories.Compose (Misc.Image_Path, "man.png")); +    Treasure_Image : aliased FLTK.Images.RGB.PNG.PNG_Image := FLTK.Images.RGB.PNG.Forge.Create +        (Ada.Directories.Compose (Misc.Image_Path, "treasure.png"));      Nothing : constant Thing := | 
