* Change version in about window and installer name * Change version in about window and installer name * Cmake get version updates * dev snapshot format changed * alignment changes
9 KiB
Style Guide
Compatibility
Cockatrice is compiled on all platform using C++11, even if the majority of the code is written in C++03.
For consistency, use Qt data structures where possible, such as QString
over
std::string
or QList
over std::vector
.
Header files
Use header files with the extension .h
and source files with the extension
.cpp
.
Use header guards in the form of FILE_NAME_H
.
Simple functions, such as getters, may be written inline in the header file, but other functions should be written in the source file.
Keep library includes and project includes grouped together. So this is okay:
// Good:
#include <QList>
#include <QString>
#include "card.h"
#include "deck.h"
// Good:
#include "card.h"
#include "deck.h"
#include <QList>
#include <QString>
// Bad:
#include <QList>
#include "card.h"
#include <QString>
#include "deck.h"
Naming
Use UpperCamelCase
for classes, structs, enums, etc. and lowerCamelCase
for
function and variable names.
Member variables aren't decorated in any way. Don't prefix or suffix with underscores, etc.
For arguments to constructors which have the same names as member variables, prefix those arguments with underscores:
MyClass::MyClass(int _myData)
: myData(_myData)
{}
Pointers and references should be denoted with the *
or &
going with the
variable name:
// Good:
Foo *foo1 = new Foo;
Foo &foo2 = *foo1;
// Bad:
Bar* bar1 = new Bar;
Bar& bar2 = *bar1;
Use nullptr
instead of NULL
(or 0
) for null pointers.
If you find any usage of the old keywords, we encourage you to fix it.
Braces
Use K&R-style braces. Braces for function implementations go on their own lines, but they go on the same line everywhere else:
int main()
{
if (someCondition) {
doSomething();
} else {
while (someOtherCondition) {
doSomethingElse();
}
}
}
Braces can be omitted for single-statement if's and the like, as long as it is still legible.
Tabs
Use only spaces. Four spaces per tab.
Lines
Do not have trailing whitespace in your lines.
Lines should be 80 characters or less, as a soft limit.
Memory Management
New code should be written using references over pointers and stack allocation over heap allocation wherever possible.
// Good: uses stack allocation and references
void showCard(const Card &card);
int main()
{
Card card;
showCard(card);
}
// Bad: relies on manual memory management and doesn't give us much
// null-safety.
void showCard(const Card *card);
int main()
{
Card *card = new Card;
showCard(card);
delete card;
}
(Remember to pass by const
reference wherever possible, to avoid accidentally
mutating objects.)
When pointers can't be avoided, try to use a smart pointer of some sort, such
as QScopedPointer
, or, less preferably, QSharedPointer
.
Database migrations
The servatrice database's schema can be found at servatrice/servatrice.sql
.
Everytime the schema gets modified, some other steps are due:
- Increment the value of
cockatrice_schema_version
inservatrice.sql
; - Increment the value of
DATABASE_SCHEMA_VERSION
inservatrice_database_interface.h
accordingly; - Create a new migration file inside the
servatrice/migrations
directory named after the new schema version. - Run the
servatrice/check_schema_version.sh
script to ensure everything is fine.
The migration file should include the sql statements needed to migrate the database schema and data from the previous to the new version, and an additional statement that updates cockatrice_schema_version
to the correct value.
Protocol buffer
Cockatrice and Servatrice exchange data using binary messages. The syntax of these messages is defined in the proto
files in the common/pb
folder. These files defines the way data contained in each message is serialized using Google's protocol buffer.
Any change to the proto
file should be taken with caution and tested intensively before being merged, becaus a change to the protocol could make new clients incompatible to the old server and vice versa.
Translations: introduction
Basic workflow for translations:
- developer adds a
tr("foo")
string in the code; - every few days, a maintainer updates the
*_en.ts files
adding the new strings; - Transifex picks up the new files from github every 24 hours;
- translators translate the new untraslated strings on Transifex;
- before a release, a maintainer fetches the updated translations from Transifex.
Translations (for developers)
All the user-interface strings inside Cockatrice's source code must be written in english language. Translations to other languages are managed using Transifex.
If you're about to propose a change that adds or modifies any translatable string in the code, you don't need to take care of adding the new strings to the translation files. Every few days, or when a lot of new strings have been added, someone from the development team will take care of extracing all the new strings, adding them to the english translation files and making them available to translators on Transifex.
Translations (for maintainers)
Step 2: updating *_en.ts files
When new translatable strings have been added to the code, it would be nice to make them available to translators on Transifex. Every few days, or when a lot of new strings have been added, a maintainer should take care of extracing all the new strings and add them to the english translation files.
To update the english translation files, re-run cmake enabling the appropriate parameter and then run make:
cd cockatrice/build
cmake .. -DUPDATE_TRANSLATIONS=ON
make
If the parameter has been enabled correctly, when running "make" you should see a line similar to this one (the numbers may vary):
[ 76%] Generating ../../cockatrice/translations/cockatrice_en.ts
Updating '../../cockatrice/translations/cockatrice_en.ts'...
Found 857 source text(s) (8 new and 849 already existing)
You should then notice that the following files have uncommitted changes:
cockatrice/translations/cockatrice_en.ts
oracle/translations/oracle_en.ts
It's now suggested to disable the parameter using:
cmake .. -DUPDATE_TRANSLATIONS=OFF
Now you are ready to propose your change. Once your change gets merged, Transifex will pick up the modified files automatically (checks every 24 hours) and update the interface where translators will be able to translate the new strings.
Step 5: fetch new translations from Transifex
Before rushing out a new release, it would be nice to fetch the most up to date translations from Transifex and commit them into the Cockatrice source code. This can be done manually from the Transifex web interface, but it's quite time consuming.
As an alternative, you can install the Transifex CLI:
http://docs.transifex.com/developer/client/
You'll then be able to use a git-like cli command to push and pull translations from Transifex to the source code and vice versa.
Translations (for translators)
Please have a look at the specific FAQ for translators.
Publish A New Development Snapshot
TravisCI and Appveyor have been configured to upload files to GitHub whenever a tag is pushed. Usually, tags are created through publishing a full release, but there's a way around that.
To trigger TravisCI and Appveyor, simply do the following:
cd $COCKATRICE_REPO
git checkout master
git remote update -p
git pull
git tag $TAG_NAME
git push upstream $TAG_NAME
You should define the variables as such:
upstream - git@github.com:Cockatrice/Cockatrice.git
$COCKATRICE_REPO - /Location/of/repository/cockatrice.git
$TAG_NAME
- If full release, YYYY-MM-DD-Release-MAJ.MIN.PATCH
- If dev snapshot, YYYY-MM-DD-Development-MAJ.MIN.PATCH-betaXYZ
- MAJ.MIN.PATCH will be the NEXT release version
This will cause a tag release to be established on the GitHub repository, which will then lead to the upload of binaries. If you use this method, the tags (releases) that you create will be marked as a "pre-release" build. The /latest
URL will not be impacted (For stable branch downloads) so that's good.
If you accidentally push a tag incorrectly (the tag is outdated (you didn't pull in the latest branch accidentally), you named the tag wrong, etc) you can revoke the tag by doing the following:
git push --delete upstream $TAG_NAME
git tag -d $TAG_NAME
NOTE: Unfortunately, due to the method of how TravisCI and Appveyor work, to publish a full release you will need to make a copy of the release notes locally and then paste them into the GitHub GUI once the binaries have been uploaded. These build sites will automatically change the name of the release (to $TAG_NAME from whatever it was), the status of the release (to pre-release), and the body (to "Dev build of Cockatrice").