Press "Enter" to skip to content

Lesson 19.3: Move data and image files out of Engine project

Currently, game data and image files are included in the Engine project. In this lesson, we’ll move them out.

They aren’t code, so it makes sense to get them out of a class library project. This will also help if we add more files. This technique always copies every file in the folders – giving us one less thing for us to remember (or forget).

We’re going to do this with a “post-build event”

 


Link to video on YouTube

 

Step 1: Create GameFiles folder

Create this new folder under your solution’s top-level directory

 

Step 2: Move files from Engine directory to GameFiles directory

Cut-and-paste GameData folder

Cut-and-paste Image folder

 

Step 3: Create post-build event to copy files

In the WPFUI project, right-click and select “Properties”.

On the properties screen, select the “Build Events” tab.

Copy this line into the “Post-build event command line box”. This command will run after each time we build the project/solution, copying all the files and folders in the GameFiles folder to the project’s output folder – the location where the executable version of the program is located.

xcopy $(SolutionDir)GameFiles\*.* $(ProjectDir)$(OutDir) /s /y

 

Step 4: Test the game

Rebuild the solution and make sure the games still runs correctly.

7 Comments

  1. Phil Eakins
    Phil Eakins 2021-11-26

    So — MSDos is not dead!

    • SOSCSRPG
      SOSCSRPG 2021-11-26

      MS-DOS is always there, waiting for us. 🙂

  2. Julian
    Julian 2021-12-13

    Hi Scott, this change has broken my unit tests – not sure if it did for you.
    It appears to be because we have constants in our Factories using relative paths to our game data files.
    Since our executing directory for the unit tests is not the WPFUI bin location, the tests fail.
    I wasn’t sure of the best course of action to fix this. Simply changing directory in the unit tests could do it but seems hacky.

    • SOSCSRPG
      SOSCSRPG 2021-12-13

      Hi Julian,

      I think I deleted the unit test project when we added the dynamic player attributes. You could try adding an XCOPY for the unit test project, but I plan to completely redo the unit tests some time after finishing the refactoring. With the new solution structure, and removal of the circular project dependencies, it should be much easier to create unit tests.

      If you do the XCOPY, please post a comment here, for anyone else who may want to run the original unit tests.

      • Julian Smith
        Julian Smith 2021-12-14

        I can confirm using the same xcopy in the post build of the unit tests project made them work.
        Thanks

  3. Julian
    Julian 2021-12-13

    Of course including the post build xcopy in the unit test project would also probably work.

Leave a Reply

Your email address will not be published. Required fields are marked *