Liberi Developer Guide: Conventions

From EQUIS Lab Wiki

Jump to: navigation, search

Design Philosophy

  • Modularity:
Making modular components is preferred to making complex class hierarchies. This leads to code that is more reusable and maintainable. If you have a quick look through the code base, you will notice that none of the avatar scripts derive from a common Avatar class, none of the mob scripts derive from a common Mob class, and so forth. This is intentional. If there is anything in common between two objects, they can simply include a common component script.
  • Configurability:
Try not to hardcode any values. Expose them in the inspector instead. For settings which are more likely to be adjusted (especially by non-technical staff), use the World Data API to store and load them. Also, the code should not contain *any* strings that will appear in the game. Use the Localization API to determine final strings, and use IDs in the code instead. See the Localization article for more details.
  • Separation of Logic and View:
When designing an object in Liberi, its logical aspects are kept separate from its observable ones. You'll find that most avatars and minigames and mobs comprise at least two scripts: a Logic script, and a View script. The idea is that the Logic script is run by the object's "owner", and contains all the data which "define" the object's current state. The View script is run by any party that needs to observe the object, and basically acts as a passive "reflector" of the object's current state.

Syntax and Naming

The best way to learn syntax and naming conventions for Liberi is to look at the source code, but here's a summary.

  • Types:
Classes, enums, structs and delegates all use Pascal case. Example:
public delegate void MyAwesomeDelegate ();

public enum MyAwesomeEnum
{
    MyAwesomeEnumValue
}

public class MyAwesomeClass : MonoBehaviour
{
    void Awake ()
    {
    }
}
  • Properties:
Properties use Pascal case like standard .NET, not like Unity properties. Example:
public int MyAwesomeProperty
{
    get { return 0; }
}
  • Public Members:
Public members use Pascal case. This applies to constants as well. Example:
public float MyAwesomePublicMember = 5;
  • Non-public Members:
Non-public members use camel case, and prefixed with an underscore. This applies to constants as well. Example:
private string _myAwesomePrivateMember = null;
  • Local Variables:
Local variables use camel case. Example:
void MyAwesomeMethod ()
{
    int myAwesomeVar = 0;
}
  • Methods:
Methods (of any visibility) use Pascal case. Example:
void MyAwesomeMethod ()
{
    print("Hello from inside my awesome method.");
}
  • Code Whitespace:
Put all braces on their own lines. Exceptions can be made for very short one-liners. Example:
public int MyAwesomeProperty
{
    get { return 0; }
}
Put a space before open parentheses in declarations and control statements, but not in invocations. Example:
public void MyAwesomeMethod (int x)
{
    for (int i = 0; i < x; i++)
    {
        print(i);
    }
}
  • IDs:
Player IDs, item IDs, object IDs, skill IDs, and any other kind of ID use lowercase with underscore spacing. Example:
my_awesome_item_id
  • Unity Scripts:
Unity scripts use Pascal case, and should match the main types defined in them. Example:
MyAwesomeScript.cs
  • Other Unity Assets and Objects:
All non-script Unity assets and scene objects use lowercase with underscore spacing. Example:
my_awesome_texture.png
my_awesome_camera
  • Unity Folders:
Unity folders use capitalized, space-separated words. Example:
My Awesome Folder
  • Configuration Files:
Configuration files use Pascal case. Example:
MyAwesomeConfig.ini
  • Data Files:
Data files, such as world data pages and logs, use lowercase with underscore spacing. Example:
my_awesome_data_file.dat

Artistic

In the latest version of Liberi, assets have been created using Adobe Flash CC. Flash is a vector based authoring tool and then sheets of sprites are exported as .PNG files to maintain transparency and full color accuracy. Sprites in Liberi are typically authored with a Line Weight of 3 for lines, and a weight of 1.5.