This commit is contained in:
Gergely Polonkai 2015-11-03 18:26:33 +00:00
parent 3b0d244255
commit 9ee1f567a5
4 changed files with 25 additions and 12 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
*.o *.o
einstein __pycache__

7
einstein Executable file
View File

@ -0,0 +1,7 @@
#! /usr/bin/env python3
import sys
from einsteingame.main import main
main(*sys.argv)

View File

@ -1,10 +1,12 @@
from locale import setlocale, LC_ALL, LC_NUMERIC
class Locale(object): class Locale(object):
def __init__(self): def __init__(self):
self.parseLocale(setlocale(LC_ALL, "")) self.parseLocale(setlocale(LC_ALL, ""))
# hack because of numbers in Lua # hack because of numbers in Lua
setlocale(LC_NUMERIC, "C") setlocale(LC_NUMERIC, "C")
def parseLocale(name): def parseLocale(self, name):
pos = name.find('.') pos = name.find('.')
langAndCountry = None langAndCountry = None
@ -80,15 +82,17 @@ def splitFileName(fileName):
return name, ext, lang, country return name, ext, lang, country
def getScore(lang, country, locale): def getScore(lang, country, locale):
if len(country) == 0 and len(locale) == 0: if len(country) == 0 and len(lang) == 0:
return 1 return 1
score = 0 score = 0
if (locale.getCountry().length() && (locale.getCountry() == country)) if locale.getCountry() == country:
score += 2; score += 2
if (locale.getLanguage().length() && (locale.getLanguage() == lang))
score += 4;
return score; if locale.getLanguage() == lang:
} score += 4
return score
locale = Locale()

View File

@ -3,7 +3,7 @@ import struct
import io import io
from .buffer import Buffer from .buffer import Buffer
from .i18n import splitFileName, getScore from .i18n import splitFileName, getScore, locale
class ResourceError(Exception): class ResourceError(Exception):
def __init__(self, code=None): def __init__(self, code=None):
@ -88,6 +88,7 @@ class ResourcesCollection:
def __init__(self, directories): def __init__(self, directories):
self.__files = [] self.__files = []
self.__buffer = None self.__buffer = None
self.__resources = {}
self.loadResourceFiles(directories) self.loadResourceFiles(directories)
self.processFiles() self.processFiles()
@ -112,10 +113,11 @@ class ResourcesCollection:
if score > 0: if score > 0:
resName = name + '.' + ext resName = name + '.' + ext
res = resources[resName]; res = self.__resources.get(resName, None)
if not res: if not res:
res = Resource(res_file, score, de, resName) res = Resource(res_file, score, de, resName)
resources[resName] = res; self.__resources[resName] = res
if len(de.group) > 0: if len(de.group) > 0:
groups[de.group].append(res) groups[de.group].append(res)