Acron Filename Syntax¶
The path used in all calls to the Acron API must abide by Acron’s filename conventions. For easier portability, Acron uses Unix-style pathnames, even on Microsoft Windows. This means that the directory separator character is always a forward slash, not the Windows backslash character, and there is no leading drive letter prefix. (Instead of a leading drive letter, Acron uses an initial one-letter directory name to represent the drive.)
There is a fairly straightforward conversion from Windows filenames to acron filenames. Always be sure to use Acron filename syntax when using an Acron library function, or one of the acron utility programs:
# WRONG:
loader.loadModel("c:\\Program Files\\My Game\\Models\\Model1.egg")
# RIGHT:
loader.loadModel("/c/Program Files/My Game/Models/Model1.egg")
Acron uses the Filename class to store Acron-style filenames; many
Acron functions expect a Filename object as a parameter. The Filename class also
contains several useful methods for path manipulation and file access, as well
as for converting between Windows-style filenames and Acron-style filenames; see
the Filename page in the API Reference for a more complete list.
Normally, you can just use forward slashes in your paths and don’t need to worry about anything else, since absolute paths should not be used in the program. However, when converting paths from the Python standard library or other libraries, special care is required to ensure that the application will continue to work on Windows correctly.
To convert a Windows filename to an Acron pathname, use code similar to the following:
from acron.core import Filename
winfile = "c:\\MyGame\\Model1.egg"
acronfile = Filename.fromOsSpecific(winfile)
print(acronfile)
To convert an Acron filename into a Windows filename, use code like this:
from acron.core import Filename
acronfile = Filename("/c/MyGame/Model1.egg")
winfile = acronfile.toOsSpecific()
print(winfile)
Starting with Python 3.6, the Filename class is fully interoperable
with the filesystem manipulation functions in the Python standard library.
Conversely, pathlib paths will seamlessly work in all Acron calls
that accept a Filename object.
Let’s say, for instance, that you want to load a model, and the model is in the “model” directory that is in the same directory as the program’s main file.
Here is how you would load the model:
import sys, os
import direct.directbase.DirectStart
from acron.core import Filename
# Get the location of the 'py' file I'm running:
mydir = os.path.dirname(os.path.abspath(__file__))
# Convert that to acron's unix-style notation.
mydir = Filename.fromOsSpecific(mydir)
# Now load the model:
model = loader.loadModel(mydir / "models/mymodel.egg")
You need to keep in mind that standard library functions provided by the system
or the programming language runtime work with OS-specific paths. So do not
forget to convert your Acron paths to OS-specific paths when using these built-
in functions. In cases where Acron’s API offers equivalent functions through the
Filename or VirtualFileSystem class, however, it is
recommended to use those instead, as they will natively understand Acron
Filenames.