Game Development Reference
In-Depth Information
The second helper method is GetRelativeUri() , which constructs a properly for-
matted filename to be included into the Zip file. It requires the filename to be relative
to the root of the Zip file and not contain any illegal characters.
private static Uri GetRelativeUri(string currentFile)
{
string pastBackslashes = currentFile.Substring(currentFile.IndexOf(
'
\\
'
));
string nukeDoubleBackslash = pastBackslashes.Replace(
'
\\
'
,
'
/
'
);
string nukeSpaces = nukeDoubleBackslash.Replace(
“'
,
'
_
'
);
return new Uri(RemoveAccents(relPath), UriKind.Relative);
}
private static string RemoveAccents(string input)
{
string normalized = input.Normalize(NormalizationForm.FormKD);
Encoding removal = Encoding.GetEncoding(Encoding.ASCII.CodePage,
new EncoderReplacementFallback(
“”
),
));
byte[] bytes = removal.GetBytes(normalized);
return Encoding.ASCII.GetString(bytes);
new DecoderReplacementFallback(
“”
}
Always Use Relative Path Names
Learning from someone else
s mistakes is vastly better than learning from your
own. Did you notice the code in the GetRelativeUri() previous code
example? Not only is this important for making well-formed Zip files, but it
also enables your entire project to be stored in a way that a game developer
likes. Not everyone stores his development projects on his C:\ drive, and it can
be extremely inconvenient to assume a specific location for the project root
directory. Store your filenames as relative to the project root, and everyone
will be much happier.
'
The ActorComponentEditor Class
So far you
ve seen the basic framework of the C# editor, but nothing yet has actually
been able to view or modify all of the properties of an actor, such as its color, posi-
tion, or texture filename. This is the job of the ActorComponentEditor class,
shown in Figure 22.4.
Before jumping in to the code, it makes some sense to explain the idea behind the
design. If you remember from Chapter 6,
'
Game Actors and Component Architec-
ture,
actors are containers for components. These components are represented by
 
 
Search WWH ::




Custom Search