Source

pyGAP / game / engine / text / language.cpp

#include "text/language.h"

#include <cstdio>

#include "text/pack.h"
#include "io/fs/base.h"

#include "formats/text.h"


namespace text {


Language::Language() :
    fs_(NULL),
    pack_(NULL)
{}


Language::~Language() {
    delete fs_;
    delete pack_;
}


void Language::set(const char* language) {
    if (!language)
        return;

    char buffer[32];
    sprintf(buffer, "assets/text_%s.pak", language);

    delete fs_;
    delete pack_;

    fs_ = ::io::fs::open(buffer);
    pack_ = NULL;
}


void Language::open(const char* filename, const char* language) {
    set(language);

    if (!fs_)
        return;

    uint8_t* buffer = fs_->read(filename);
    if (!buffer)
        return;

    if (pack_)
        delete pack_;
    pack_ = new Pack();
    pack_->init(formats::text::Pack::allocate(buffer));
}


String* Language::create_string(uint16_t id) {
    return pack_ ? pack_->create_string(id) : NULL;
}


} /* namespace text */