summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-09-03 23:03:48 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-09-03 23:03:48 +0000
commit7d98c7d5f50f54d764cf0e1fdeba29c107222882 (patch)
treee9a55cd5bd0ec7245959ec5cb6c2b375bd48732f
etrophy: add library to manage game scores
ETrophy is a library that manages scores, trophies and unlockables. It will store them and provide views to display them. Could be used by games based on EFL. Right now it just stores on EET, but a remote backend is planned. SVN revision: 76084
-rw-r--r--.gitignore40
-rw-r--r--AUTHORS1
-rw-r--r--COPYING26
-rw-r--r--ChangeLog3
-rw-r--r--INSTALL365
-rw-r--r--Makefile.am45
-rw-r--r--NEWS3
-rw-r--r--README38
-rw-r--r--TODO6
-rwxr-xr-xautogen.sh39
-rw-r--r--configure.ac206
-rw-r--r--data/Makefile.am3
-rw-r--r--data/theme/Makefile.am22
-rw-r--r--data/theme/etrophy.edc30
-rw-r--r--etrophy.pc.in12
-rw-r--r--m4/ac_attribute.m447
-rw-r--r--m4/efl_compiler_flag.m457
-rw-r--r--m4/efl_doxygen.m497
-rw-r--r--src/Makefile.am3
-rw-r--r--src/lib/Etrophy.h140
-rw-r--r--src/lib/Makefile.am24
-rw-r--r--src/lib/etrophy.c932
-rw-r--r--src/lib/etrophy_layouts.c154
23 files changed, 2293 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a404579
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,40 @@
1*~
2*.o
3*.lo
4*.la
5.libs
6.deps
7*.pc
8Makefile
9Makefile.in
10*.so
11/aclocal.m4
12/autom4te.cache/
13/compile
14/config.cache
15/config.guess
16/config.h
17/config.h.in
18/config.log
19/config.status
20/config.sub
21/configure
22/depcomp
23/install-sh
24/libtool
25/ltmain.sh
26/missing
27/stamp-h1
28/ABOUT-NLS
29/config.cache-env
30doc/Doxyfile
31m4/libtool.m4
32m4/ltoptions.m4
33m4/ltsugar.m4
34m4/ltversion.m4
35m4/lt~obsolete.m4
36doc/html/
37doc/latex/
38doc/man/
39etrophy-*-doc.tar.bz2
40data/theme/etrophy.edj
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..5019971
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
Bruno Dilly <bdilly@profusion.mobi>
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..d29883c
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,26 @@
1Copyright notice for ETrophy:
2
3Copyright (C) 2012 ProFUSION Embedded Systems and various
4 contributors (see AUTHORS).
5
6All rights reserved.
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are met:
10
11 1. Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
16
17THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
18INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/ChangeLog b/ChangeLog
new file mode 100644
index 0000000..844eb07
--- /dev/null
+++ b/ChangeLog
@@ -0,0 +1,3 @@
12012-09-03 Bruno Dilly
2
3 Initial version
diff --git a/INSTALL b/INSTALL
new file mode 100644
index 0000000..7d1c323
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,365 @@
1Installation Instructions
2*************************
3
4Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
52006, 2007, 2008, 2009 Free Software Foundation, Inc.
6
7 Copying and distribution of this file, with or without modification,
8are permitted in any medium without royalty provided the copyright
9notice and this notice are preserved. This file is offered as-is,
10without warranty of any kind.
11
12Basic Installation
13==================
14
15 Briefly, the shell commands `./configure; make; make install' should
16configure, build, and install this package. The following
17more-detailed instructions are generic; see the `README' file for
18instructions specific to this package. Some packages provide this
19`INSTALL' file but do not implement all of the features documented
20below. The lack of an optional feature in a given package is not
21necessarily a bug. More recommendations for GNU packages can be found
22in *note Makefile Conventions: (standards)Makefile Conventions.
23
24 The `configure' shell script attempts to guess correct values for
25various system-dependent variables used during compilation. It uses
26those values to create a `Makefile' in each directory of the package.
27It may also create one or more `.h' files containing system-dependent
28definitions. Finally, it creates a shell script `config.status' that
29you can run in the future to recreate the current configuration, and a
30file `config.log' containing compiler output (useful mainly for
31debugging `configure').
32
33 It can also use an optional file (typically called `config.cache'
34and enabled with `--cache-file=config.cache' or simply `-C') that saves
35the results of its tests to speed up reconfiguring. Caching is
36disabled by default to prevent problems with accidental use of stale
37cache files.
38
39 If you need to do unusual things to compile the package, please try
40to figure out how `configure' could check whether to do them, and mail
41diffs or instructions to the address given in the `README' so they can
42be considered for the next release. If you are using the cache, and at
43some point `config.cache' contains results you don't want to keep, you
44may remove or edit it.
45
46 The file `configure.ac' (or `configure.in') is used to create
47`configure' by a program called `autoconf'. You need `configure.ac' if
48you want to change it or regenerate `configure' using a newer version
49of `autoconf'.
50
51 The simplest way to compile this package is:
52
53 1. `cd' to the directory containing the package's source code and type
54 `./configure' to configure the package for your system.
55
56 Running `configure' might take a while. While running, it prints
57 some messages telling which features it is checking for.
58
59 2. Type `make' to compile the package.
60
61 3. Optionally, type `make check' to run any self-tests that come with
62 the package, generally using the just-built uninstalled binaries.
63
64 4. Type `make install' to install the programs and any data files and
65 documentation. When installing into a prefix owned by root, it is
66 recommended that the package be configured and built as a regular
67 user, and only the `make install' phase executed with root
68 privileges.
69
70 5. Optionally, type `make installcheck' to repeat any self-tests, but
71 this time using the binaries in their final installed location.
72 This target does not install anything. Running this target as a
73 regular user, particularly if the prior `make install' required
74 root privileges, verifies that the installation completed
75 correctly.
76
77 6. You can remove the program binaries and object files from the
78 source code directory by typing `make clean'. To also remove the
79 files that `configure' created (so you can compile the package for
80 a different kind of computer), type `make distclean'. There is
81 also a `make maintainer-clean' target, but that is intended mainly
82 for the package's developers. If you use it, you may have to get
83 all sorts of other programs in order to regenerate files that came
84 with the distribution.
85
86 7. Often, you can also type `make uninstall' to remove the installed
87 files again. In practice, not all packages have tested that
88 uninstallation works correctly, even though it is required by the
89 GNU Coding Standards.
90
91 8. Some packages, particularly those that use Automake, provide `make
92 distcheck', which can by used by developers to test that all other
93 targets like `make install' and `make uninstall' work correctly.
94 This target is generally not run by end users.
95
96Compilers and Options
97=====================
98
99 Some systems require unusual options for compilation or linking that
100the `configure' script does not know about. Run `./configure --help'
101for details on some of the pertinent environment variables.
102
103 You can give `configure' initial values for configuration parameters
104by setting variables in the command line or in the environment. Here
105is an example:
106
107 ./configure CC=c99 CFLAGS=-g LIBS=-lposix
108
109 *Note Defining Variables::, for more details.
110
111Compiling For Multiple Architectures
112====================================
113
114 You can compile the package for more than one kind of computer at the
115same time, by placing the object files for each architecture in their
116own directory. To do this, you can use GNU `make'. `cd' to the
117directory where you want the object files and executables to go and run
118the `configure' script. `configure' automatically checks for the
119source code in the directory that `configure' is in and in `..'. This
120is known as a "VPATH" build.
121
122 With a non-GNU `make', it is safer to compile the package for one
123architecture at a time in the source code directory. After you have
124installed the package for one architecture, use `make distclean' before
125reconfiguring for another architecture.
126
127 On MacOS X 10.5 and later systems, you can create libraries and
128executables that work on multiple system types--known as "fat" or
129"universal" binaries--by specifying multiple `-arch' options to the
130compiler but only a single `-arch' option to the preprocessor. Like
131this:
132
133 ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
134 CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
135 CPP="gcc -E" CXXCPP="g++ -E"
136
137 This is not guaranteed to produce working output in all cases, you
138may have to build one architecture at a time and combine the results
139using the `lipo' tool if you have problems.
140
141Installation Names
142==================
143
144 By default, `make install' installs the package's commands under
145`/usr/local/bin', include files under `/usr/local/include', etc. You
146can specify an installation prefix other than `/usr/local' by giving
147`configure' the option `--prefix=PREFIX', where PREFIX must be an
148absolute file name.
149
150 You can specify separate installation prefixes for
151architecture-specific files and architecture-independent files. If you
152pass the option `--exec-prefix=PREFIX' to `configure', the package uses
153PREFIX as the prefix for installing programs and libraries.
154Documentation and other data files still use the regular prefix.
155
156 In addition, if you use an unusual directory layout you can give
157options like `--bindir=DIR' to specify different values for particular
158kinds of files. Run `configure --help' for a list of the directories
159you can set and what kinds of files go in them. In general, the
160default for these options is expressed in terms of `${prefix}', so that
161specifying just `--prefix' will affect all of the other directory
162specifications that were not explicitly provided.
163
164 The most portable way to affect installation locations is to pass the
165correct locations to `configure'; however, many packages provide one or
166both of the following shortcuts of passing variable assignments to the
167`make install' command line to change installation locations without
168having to reconfigure or recompile.
169
170 The first method involves providing an override variable for each
171affected directory. For example, `make install
172prefix=/alternate/directory' will choose an alternate location for all
173directory configuration variables that were expressed in terms of
174`${prefix}'. Any directories that were specified during `configure',
175but not in terms of `${prefix}', must each be overridden at install
176time for the entire installation to be relocated. The approach of
177makefile variable overrides for each directory variable is required by
178the GNU Coding Standards, and ideally causes no recompilation.
179However, some platforms have known limitations with the semantics of
180shared libraries that end up requiring recompilation when using this
181method, particularly noticeable in packages that use GNU Libtool.
182
183 The second method involves providing the `DESTDIR' variable. For
184example, `make install DESTDIR=/alternate/directory' will prepend
185`/alternate/directory' before all installation names. The approach of
186`DESTDIR' overrides is not required by the GNU Coding Standards, and
187does not work on platforms that have drive letters. On the other hand,
188it does better at avoiding recompilation issues, and works well even
189when some directory options were not specified in terms of `${prefix}'
190at `configure' time.
191
192Optional Features
193=================
194
195 If the package supports it, you can cause programs to be installed
196with an extra prefix or suffix on their names by giving `configure' the
197option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
198
199 Some packages pay attention to `--enable-FEATURE' options to
200`configure', where FEATURE indicates an optional part of the package.
201They may also pay attention to `--with-PACKAGE' options, where PACKAGE
202is something like `gnu-as' or `x' (for the X Window System). The
203`README' should mention any `--enable-' and `--with-' options that the
204package recognizes.
205
206 For packages that use the X Window System, `configure' can usually
207find the X include and library files automatically, but if it doesn't,
208you can use the `configure' options `--x-includes=DIR' and
209`--x-libraries=DIR' to specify their locations.
210
211 Some packages offer the ability to configure how verbose the
212execution of `make' will be. For these packages, running `./configure
213--enable-silent-rules' sets the default to minimal output, which can be
214overridden with `make V=1'; while running `./configure
215--disable-silent-rules' sets the default to verbose, which can be
216overridden with `make V=0'.
217
218Particular systems
219==================
220
221 On HP-UX, the default C compiler is not ANSI C compatible. If GNU
222CC is not installed, it is recommended to use the following options in
223order to use an ANSI C compiler:
224
225 ./configure CC="cc -Ae -D_XOPEN_SOURCE=500"
226
227and if that doesn't work, install pre-built binaries of GCC for HP-UX.
228
229 On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot
230parse its `<wchar.h>' header file. The option `-nodtk' can be used as
231a workaround. If GNU CC is not installed, it is therefore recommended
232to try
233
234 ./configure CC="cc"
235
236and if that doesn't work, try
237
238 ./configure CC="cc -nodtk"
239
240 On Solaris, don't put `/usr/ucb' early in your `PATH'. This
241directory contains several dysfunctional programs; working variants of
242these programs are available in `/usr/bin'. So, if you need `/usr/ucb'
243in your `PATH', put it _after_ `/usr/bin'.
244
245 On Haiku, software installed for all users goes in `/boot/common',
246not `/usr/local'. It is recommended to use the following options:
247
248 ./configure --prefix=/boot/common
249
250Specifying the System Type
251==========================
252
253 There may be some features `configure' cannot figure out
254automatically, but needs to determine by the type of machine the package
255will run on. Usually, assuming the package is built to be run on the
256_same_ architectures, `configure' can figure that out, but if it prints
257a message saying it cannot guess the machine type, give it the
258`--build=TYPE' option. TYPE can either be a short name for the system
259type, such as `sun4', or a canonical name which has the form:
260
261 CPU-COMPANY-SYSTEM
262
263where SYSTEM can have one of these forms:
264
265 OS
266 KERNEL-OS
267
268 See the file `config.sub' for the possible values of each field. If
269`config.sub' isn't included in this package, then this package doesn't
270need to know the machine type.
271
272 If you are _building_ compiler tools for cross-compiling, you should
273use the option `--target=TYPE' to select the type of system they will
274produce code for.
275
276 If you want to _use_ a cross compiler, that generates code for a
277platform different from the build platform, you should specify the
278"host" platform (i.e., that on which the generated programs will
279eventually be run) with `--host=TYPE'.
280
281Sharing Defaults
282================
283
284 If you want to set default values for `configure' scripts to share,
285you can create a site shell script called `config.site' that gives
286default values for variables like `CC', `cache_file', and `prefix'.
287`configure' looks for `PREFIX/share/config.site' if it exists, then
288`PREFIX/etc/config.site' if it exists. Or, you can set the
289`CONFIG_SITE' environment variable to the location of the site script.
290A warning: not all `configure' scripts look for a site script.
291
292Defining Variables
293==================
294
295 Variables not defined in a site shell script can be set in the
296environment passed to `configure'. However, some packages may run
297configure again during the build, and the customized values of these
298variables may be lost. In order to avoid this problem, you should set
299them in the `configure' command line, using `VAR=value'. For example:
300
301 ./configure CC=/usr/local2/bin/gcc
302
303causes the specified `gcc' to be used as the C compiler (unless it is
304overridden in the site shell script).
305
306Unfortunately, this technique does not work for `CONFIG_SHELL' due to
307an Autoconf bug. Until the bug is fixed you can use this workaround:
308
309 CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
310
311`configure' Invocation
312======================
313
314 `configure' recognizes the following options to control how it
315operates.
316
317`--help'
318`-h'
319 Print a summary of all of the options to `configure', and exit.
320
321`--help=short'
322`--help=recursive'
323 Print a summary of the options unique to this package's
324 `configure', and exit. The `short' variant lists options used
325 only in the top level, while the `recursive' variant lists options
326 also present in any nested packages.
327
328`--version'
329`-V'
330 Print the version of Autoconf used to generate the `configure'
331 script, and exit.
332
333`--cache-file=FILE'
334 Enable the cache: use and save the results of the tests in FILE,
335 traditionally `config.cache'. FILE defaults to `/dev/null' to
336 disable caching.
337
338`--config-cache'
339`-C'
340 Alias for `--cache-file=config.cache'.
341
342`--quiet'
343`--silent'
344`-q'
345 Do not print messages saying which checks are being made. To
346 suppress all normal output, redirect it to `/dev/null' (any error
347 messages will still be shown).
348
349`--srcdir=DIR'
350 Look for the package's source code in directory DIR. Usually
351 `configure' can determine that directory automatically.
352
353`--prefix=DIR'
354 Use DIR as the installation prefix. *note Installation Names::
355 for more details, including other options available for fine-tuning
356 the installation locations.
357
358`--no-create'
359`-n'
360 Run the configure checks, but stop before creating any output
361 files.
362
363`configure' also accepts some other, not widely useful, options. Run
364`configure --help' for more details.
365
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..dd31d65
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,45 @@
1ACLOCAL_AMFLAGS = -I m4
2
3SUBDIRS = src data
4
5MAINTAINERCLEANFILES = \
6Makefile.in \
7aclocal.m4 \
8compile \
9config.guess \
10config.h.in \
11config.h.in~ \
12config.sub \
13configure \
14depcomp \
15install-sh \
16ltmain.sh \
17missing \
18$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar.gz \
19$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).tar.bz2 \
20$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)-doc.tar.bz2 \
21m4/libtool.m4 \
22m4/lt~obsolete.m4 \
23m4/ltoptions.m4 \
24m4/ltsugar.m4 \
25m4/ltversion.m4
26
27bin_SCRIPTS =
28
29EXTRA_DIST = \
30AUTHORS \
31COPYING \
32autogen.sh \
33etrophy.pc.in \
34README
35
36pkgconfigdir = $(libdir)/pkgconfig
37pkgconfig_DATA = etrophy.pc
38
39.PHONY: doc
40
41# Documentation
42
43doc:
44 @echo "entering doc/"
45 make -C doc doc
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..fa0b965
--- /dev/null
+++ b/NEWS
@@ -0,0 +1,3 @@
1ETrophy 0.1.0
2
3 * Initial version
diff --git a/README b/README
new file mode 100644
index 0000000..b3ec0cf
--- /dev/null
+++ b/README
@@ -0,0 +1,38 @@
1ETrophy 0.1.0
2
3******************************************************************************
4
5 FOR ANY ISSUES PLEASE EMAIL:
6 enlightenment-devel@lists.sourceforge.net
7
8******************************************************************************
9
10Requirements:
11-------------
12
13Must:
14 libc
15 elementary 1.7
16
17ETrophy is a library that manages scores, trophies and unlockables. It will
18store them and provide views to display them. Could be used by games based
19on EFL.
20
21------------------------------------------------------------------------------
22
23COMPILING AND INSTALLING:
24
25 $ ./configure
26 $ make
27(as root unless you are installing in your users directories):
28 $ make install
29
30----
31
32DOCS
33
34To generate documentation, doxygen is required.
35
36 $ make doc
37
38will create a etrophy/doc/html directory. You could start looking at index.html.
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..82a22be
--- /dev/null
+++ b/TODO
@@ -0,0 +1,6 @@
1* add test
2* add GUI elements
3* add test for GUI elements
4* add docs
5* add version to gamescore
6* add remote backend
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..00116ea
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,39 @@
1#!/bin/sh
2
3rm -rf autom4te.cache
4rm -f aclocal.m4 ltmain.sh
5
6touch README
7touch ABOUT-NLS
8
9echo "Running aclocal..." ; aclocal $ACLOCAL_FLAGS -I m4 || exit 1
10echo "Running autoheader..." ; autoheader || exit 1
11echo "Running autoconf..." ; autoconf || exit 1
12echo "Running libtoolize..." ; (libtoolize --copy --automake || glibtoolize --automake) || exit 1
13echo "Running automake..." ; automake --add-missing --copy --gnu || exit 1
14
15W=0
16
17rm -f config.cache-env.tmp
18echo "OLD_PARM=\"$@\"" >> config.cache-env.tmp
19echo "OLD_CFLAGS=\"$CFLAGS\"" >> config.cache-env.tmp
20echo "OLD_PATH=\"$PATH\"" >> config.cache-env.tmp
21echo "OLD_PKG_CONFIG_PATH=\"$PKG_CONFIG_PATH\"" >> config.cache-env.tmp
22echo "OLD_LDFLAGS=\"$LDFLAGS\"" >> config.cache-env.tmp
23
24cmp config.cache-env.tmp config.cache-env >> /dev/null
25if [ $? -ne 0 ]; then
26 W=1;
27fi
28
29if [ $W -ne 0 ]; then
30 echo "Cleaning configure cache...";
31 rm -f config.cache config.cache-env
32 mv config.cache-env.tmp config.cache-env
33else
34 rm -f config.cache-env.tmp
35fi
36
37if [ -z "$NOCONFIGURE" ]; then
38 ./configure -C "$@"
39fi
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..c24ab19
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,206 @@
1##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
2##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
3m4_define([v_maj], [0])
4m4_define([v_min], [1])
5m4_define([v_mic], [0])
6m4_define([v_rev], m4_esyscmd([(svnversion "${SVN_REPO_PATH:-.}" | grep -v '\(export\|Unversioned directory\)' || echo 0) | awk -F : '{printf("%s\n", $1);}' | tr -d ' :MSP\n']))
7m4_if(v_rev, [0], [m4_define([v_rev], m4_esyscmd([git log 2> /dev/null | (grep -m1 git-svn-id || echo 0) | sed -e 's/.*@\([0-9]*\).*/\1/' | tr -d '\n']))])
8##-- When released, remove the dnl on the below line
9dnl m4_undefine([v_rev])
10##-- When doing snapshots - change soname. remove dnl on below line
11dnl m4_define([relname], [ver-pre-svn-07])
12dnl m4_define([v_rel], [-release relname])
13##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
14m4_ifdef([v_rev], [m4_define([v_ver], [v_maj.v_min.v_mic.v_rev])], [m4_define([v_ver], [v_maj.v_min.v_mic])])
15m4_define([lt_cur], m4_eval(v_maj + v_min))
16m4_define([lt_rev], v_mic)
17m4_define([lt_age], v_min)
18##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
19##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
20
21AC_INIT([etrophy], [v_ver], [enlightenment-devel@lists.sourceforge.net])
22AC_PREREQ([2.52])
23AC_CONFIG_SRCDIR([configure.ac])
24AC_CONFIG_MACRO_DIR([m4])
25
26AC_CONFIG_HEADERS([config.h])
27AH_TOP([
28#ifndef EFL_CONFIG_H__
29#define EFL_CONFIG_H__
30])
31AH_BOTTOM([
32#endif /* EFL_CONFIG_H__ */
33])
34
35AM_INIT_AUTOMAKE([1.6 dist-bzip2])
36m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
37
38AC_LIBTOOL_WIN32_DLL
39define([AC_LIBTOOL_LANG_F77_CONFIG], [:])dnl
40AC_PROG_LIBTOOL
41
42##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
43##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
44m4_ifdef([v_rev], , [m4_define([v_rev], [0])])
45m4_ifdef([v_rel], , [m4_define([v_rel], [])])
46AC_DEFINE_UNQUOTED(VMAJ, [v_maj], [Major version])
47AC_DEFINE_UNQUOTED(VMIN, [v_min], [Minor version])
48AC_DEFINE_UNQUOTED(VMIC, [v_mic], [Micro version])
49AC_DEFINE_UNQUOTED(VREV, [v_rev], [Revison])
50version_info="lt_cur:lt_rev:lt_age"
51release_info="v_rel"
52AC_SUBST(version_info)
53AC_SUBST(release_info)
54##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
55##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
56VMAJ=v_maj
57AC_SUBST(VMAJ)
58
59AC_DEFINE_UNQUOTED([SHARED_LIB_SUFFIX], ["$shrext_cmds"], [Suffix for shared objects])
60
61### Default options with respect to host
62AC_CANONICAL_BUILD
63AC_CANONICAL_HOST
64
65
66requirement_etrophy=""
67
68AC_SUBST(MODULE_ARCH)
69AC_DEFINE_UNQUOTED(MODULE_ARCH, "${MODULE_ARCH}", "Module architecture")
70
71m4_ifdef([v_mic],
72 [
73 EFL_COMPILER_FLAG([-Wshadow])
74 EFL_COMPILER_FLAG([-Wall])
75 EFL_COMPILER_FLAG([-Wextra])
76 EFL_COMPILER_FLAG([-W])
77 ])
78
79### Checks for programs
80AC_PROG_CC
81
82# doxygen program for documentation building
83
84EFL_CHECK_DOXYGEN([build_doc="yes"], [build_doc="no"])
85
86# python
87
88AM_PATH_PYTHON([2.5], , [:])
89AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != : ])
90
91# pkg-config
92
93PKG_PROG_PKG_CONFIG
94
95# Check whether pkg-config supports Requires.private
96
97if $PKG_CONFIG --atleast-pkgconfig-version 0.22; then
98 pkgconfig_requires_private="Requires.private"
99else
100 pkgconfig_requires_private="Requires"
101fi
102AC_SUBST(pkgconfig_requires_private)
103
104
105### Checks for libraries
106
107# Evil library for compilation on Windows
108
109EFL_ETROPHY_BUILD=""
110case "$host_os" in
111 mingw*)
112 PKG_CHECK_MODULES([EVIL], [evil >= 1.0.0])
113 AC_DEFINE([HAVE_EVIL], [1], [Set to 1 if Evil library is installed])
114 requirement_etrophy="evil ${requirement_etrophy}"
115 EFL_ETROPHY_BUILD="-DEFL_ETROPHY_BUILD"
116 ;;
117esac
118AC_SUBST(EFL_ETROPHY_BUILD)
119
120# Dependencies for the library
121
122PKG_CHECK_MODULES([ELEMENTARY],
123 [
124 elementary >= 1.7.0
125 evas >= 1.7.0
126 ecore-file >= 1.7.0
127 eet >= 1.7.0
128 eina >= 1.7.0
129 ])
130
131if test "x$HAVE_GENEET" = "xfalse"; then
132AC_MSG_ERROR([*** Geneet not found, make sure geneet.py is in your PATH])
133fi
134
135AC_ARG_WITH([edje-cc],
136 [AC_HELP_STRING([--with-edje-cc=PATH],
137 [specify a specific path to edje_cc])],
138 [edje_cc=$withval;
139 AC_MSG_NOTICE([edje_cc explicitly set to $edje_cc])
140 ],[edje_cc=$(pkg-config --variable=prefix edje)/bin/edje_cc])
141AC_SUBST(edje_cc)
142
143requirement_etrophy="elementary >= 1.7.0 evas >= 1.7.0 ecore-file >= 1.7.0 eet >= 1.7.0 eina >= 1.7.0 ${requirement_etrophy}"
144
145### Checks for header files
146AC_CHECK_HEADERS([locale.h sys/resource.h])
147
148EFL_CHECK_PATH_MAX
149
150### Checks for compiler characteristics
151AM_PROG_CC_C_O
152AC_C_CONST
153AC_PROG_CC_STDC
154AC_HEADER_STDC
155AC_C___ATTRIBUTE__
156
157case "$host_os" in
158 mingw32ce*)
159 ETROPHY_CFLAGS="${ETROPHY_CFLAGS} -D_WIN32_WCE=0x0420"
160 ;;
161esac
162
163
164### Checks for linker characteristics
165
166lt_enable_auto_import=""
167case "$host_os" in
168 mingw*)
169 lt_enable_auto_import="-Wl,--enable-auto-import"
170 ;;
171esac
172AC_SUBST(lt_enable_auto_import)
173
174AC_SUBST(requirement_etrophy)
175
176AC_OUTPUT([
177etrophy.pc
178Makefile
179src/Makefile
180src/lib/Makefile
181data/Makefile
182data/theme/Makefile
183])
184
185
186#####################################################################
187## Info
188
189echo
190echo
191echo
192echo "------------------------------------------------------------------------"
193echo "$PACKAGE $VERSION"
194echo "------------------------------------------------------------------------"
195echo
196echo "Configuration Options Summary:"
197echo
198echo " Documentation........: ${build_doc}"
199echo
200echo "Compilation............: make (or gmake)"
201echo " CFLAGS...............: $CFLAGS"
202echo " LDFLAGS..............: $LDFLAGS"
203echo
204echo "Installation...........: make install (as root if needed, with 'su' or 'sudo')"
205echo " prefix...............: $prefix"
206echo
diff --git a/data/Makefile.am b/data/Makefile.am
new file mode 100644
index 0000000..43c161a
--- /dev/null
+++ b/data/Makefile.am
@@ -0,0 +1,3 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3SUBDIRS = theme
diff --git a/data/theme/Makefile.am b/data/theme/Makefile.am
new file mode 100644
index 0000000..293dab5
--- /dev/null
+++ b/data/theme/Makefile.am
@@ -0,0 +1,22 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3EDJE_CC = @edje_cc@
4EDJE_FLAGS_VERBOSE_ =
5EDJE_FLAGS_VERBOSE_0 =
6EDJE_FLAGS_VERBOSE_1 = -v
7EDJE_FLAGS = $(EDJE_FLAGS_$(V)) -id $(top_srcdir)/data/theme/images -fd $(top_srcdir)/data/theme/fonts
8
9filesdir = $(datadir)/etrophy/
10
11files_DATA = etrophy.edj
12
13EXTRA_DIST = \
14 etrophy.edc
15
16etrophy.edj: Makefile $(EXTRA_DIST)
17 $(EDJE_CC) $(EDJE_FLAGS) \
18 $(top_srcdir)/data/theme/etrophy.edc \
19 $(top_builddir)/data/theme/etrophy.edj
20
21clean-local:
22 rm -f *.edj
diff --git a/data/theme/etrophy.edc b/data/theme/etrophy.edc
new file mode 100644
index 0000000..6b53090
--- /dev/null
+++ b/data/theme/etrophy.edc
@@ -0,0 +1,30 @@
1collections {
2 group {
3 name: "etrophy/scores/default";
4
5 parts {
6 part {
7 name: "selector";
8 type: SWALLOW;
9 description {
10 state: "default" 0.0;
11 fixed: 1 1;
12 rel1.relative: 0 0;
13 rel2.relative: 1 0;
14 align: 0.5 0;
15 }
16 }
17
18 part {
19 name: "list";
20 type: SWALLOW;
21 description {
22 state: "default" 0.0;
23 min: 80 160;
24 rel1.to_y: "selector";
25 rel1.relative: 0 1;
26 }
27 }
28 }
29 }
30}
diff --git a/etrophy.pc.in b/etrophy.pc.in
new file mode 100644
index 0000000..ba8d7f7
--- /dev/null
+++ b/etrophy.pc.in
@@ -0,0 +1,12 @@
1prefix=@prefix@
2exec_prefix=@exec_prefix@
3libdir=@libdir@
4includedir=@includedir@
5vmaj=@VMAJ@
6
7Name: etrophy
8Description: Etrophy is library to manage scores, trophies and unlockables for games.
9@pkgconfig_requires_private@: @requirement_etrophy@
10Version: @VERSION@
11Libs: -L${libdir} -letrophy
12Cflags: -I${includedir}/etrophy-@VMAJ@
diff --git a/m4/ac_attribute.m4 b/m4/ac_attribute.m4
new file mode 100644
index 0000000..23479a9
--- /dev/null
+++ b/m4/ac_attribute.m4
@@ -0,0 +1,47 @@
1dnl Copyright (C) 2004-2008 Kim Woelders
2dnl Copyright (C) 2008 Vincent Torri <vtorri at univ-evry dot fr>
3dnl That code is public domain and can be freely used or copied.
4dnl Originally snatched from somewhere...
5
6dnl Macro for checking if the compiler supports __attribute__
7
8dnl Usage: AC_C___ATTRIBUTE__
9dnl call AC_DEFINE for HAVE___ATTRIBUTE__ and __UNUSED__
10dnl if the compiler supports __attribute__, HAVE___ATTRIBUTE__ is
11dnl defined to 1 and __UNUSED__ is defined to __attribute__((unused))
12dnl otherwise, HAVE___ATTRIBUTE__ is not defined and __UNUSED__ is
13dnl defined to nothing.
14
15AC_DEFUN([AC_C___ATTRIBUTE__],
16[
17
18AC_MSG_CHECKING([for __attribute__])
19
20AC_CACHE_VAL([ac_cv___attribute__],
21 [AC_TRY_COMPILE(
22 [
23#include <stdlib.h>
24
25int func(int x);
26int foo(int x __attribute__ ((unused)))
27{
28 exit(1);
29}
30 ],
31 [],
32 [ac_cv___attribute__="yes"],
33 [ac_cv___attribute__="no"]
34 )])
35
36AC_MSG_RESULT($ac_cv___attribute__)
37
38if test "x${ac_cv___attribute__}" = "xyes" ; then
39 AC_DEFINE([HAVE___ATTRIBUTE__], [1], [Define to 1 if your compiler has __attribute__])
40 AC_DEFINE([__UNUSED__], [__attribute__((unused))], [Macro declaring a function argument to be unused])
41 else
42 AC_DEFINE([__UNUSED__], [], [Macro declaring a function argument to be unused])
43fi
44
45])
46
47dnl End of ac_attribute.m4
diff --git a/m4/efl_compiler_flag.m4 b/m4/efl_compiler_flag.m4
new file mode 100644
index 0000000..25c285d
--- /dev/null
+++ b/m4/efl_compiler_flag.m4
@@ -0,0 +1,57 @@
1dnl Copyright (C) 2010 Vincent Torri <vtorri at univ-evry dot fr>
2dnl and Albin Tonnerre <albin dot tonnerre at gmail dot com>
3dnl That code is public domain and can be freely used or copied.
4
5dnl Macro that checks if a compiler flag is supported by the compiler.
6
7dnl Usage: EFL_COMPILER_FLAG(flag)
8dnl flag is added to CFLAGS if supported.
9
10AC_DEFUN([EFL_COMPILER_FLAG],
11[
12
13CFLAGS_save="${CFLAGS}"
14CFLAGS="${CFLAGS} $1"
15
16AC_LANG_PUSH([C])
17AC_MSG_CHECKING([whether the compiler supports $1])
18
19AC_COMPILE_IFELSE(
20 [AC_LANG_PROGRAM([[]])],
21 [have_flag="yes"],
22 [have_flag="no"])
23AC_MSG_RESULT([${have_flag}])
24
25if test "x${have_flag}" = "xno" ; then
26 CFLAGS="${CFLAGS_save}"
27fi
28AC_LANG_POP([C])
29
30])
31
32dnl Macro that checks if a linker flag is supported by the compiler.
33
34dnl Usage: EFL_LINKER_FLAG(flag)
35dnl flag is added to LDFLAGS if supported (will be passed to ld anyway).
36
37AC_DEFUN([EFL_LINKER_FLAG],
38[
39
40LDFLAGS_save="${LDFLAGS}"
41LDFLAGS="${LDFLAGS} $1"
42
43AC_LANG_PUSH([C])
44AC_MSG_CHECKING([whether the compiler supports $1])
45
46AC_LINK_IFELSE(
47 [AC_LANG_PROGRAM([[]])],
48 [have_flag="yes"],
49 [have_flag="no"])
50AC_MSG_RESULT([${have_flag}])
51
52if test "x${have_flag}" = "xno" ; then
53 LDFLAGS="${LDFLAGS_save}"
54fi
55AC_LANG_POP([C])
56
57])
diff --git a/m4/efl_doxygen.m4 b/m4/efl_doxygen.m4
new file mode 100644
index 0000000..d83ed68
--- /dev/null
+++ b/m4/efl_doxygen.m4
@@ -0,0 +1,97 @@
1dnl Copyright (C) 2008 Vincent Torri <vtorri at univ-evry dot fr>
2dnl That code is public domain and can be freely used or copied.
3
4dnl Macro that check if doxygen is available or not.
5
6dnl EFL_CHECK_DOXYGEN([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
7dnl Test for the doxygen program
8dnl Defines efl_doxygen
9dnl Defines the automake conditionnal EFL_BUILD_DOC
10dnl
11AC_DEFUN([EFL_CHECK_DOXYGEN],
12[
13
14dnl
15dnl Disable the build of the documentation
16dnl
17AC_ARG_ENABLE([doc],
18 [AC_HELP_STRING(
19 [--disable-doc],
20 [Disable documentation build @<:@default=enabled@:>@])],
21 [
22 if test "x${enableval}" = "xyes" ; then
23 efl_enable_doc="yes"
24 else
25 efl_enable_doc="no"
26 fi
27 ],
28 [efl_enable_doc="yes"])
29
30AC_MSG_CHECKING([whether to build documentation])
31AC_MSG_RESULT([${efl_enable_doc}])
32
33if test "x${efl_enable_doc}" = "xyes" ; then
34
35dnl Specify the file name, without path
36
37 efl_doxygen="doxygen"
38
39 AC_ARG_WITH([doxygen],
40 [AC_HELP_STRING(
41 [--with-doxygen=FILE],
42 [doxygen program to use @<:@default=doxygen@:>@])],
43
44dnl Check the given doxygen program.
45
46 [efl_doxygen=${withval}
47 AC_CHECK_PROG([efl_have_doxygen],
48 [${efl_doxygen}],
49 [yes],
50 [no])
51 if test "x${efl_have_doxygen}" = "xno" ; then
52 echo "WARNING:"
53 echo "The doxygen program you specified:"
54 echo "${efl_doxygen}"
55 echo "was not found. Please check the path and make sure "
56 echo "the program exists and is executable."
57 AC_MSG_WARN([no doxygen detected. Documentation will not be built])
58 fi
59 ],
60 [AC_CHECK_PROG([efl_have_doxygen],
61 [${efl_doxygen}],
62 [yes],
63 [no])
64 if test "x${efl_have_doxygen}" = "xno" ; then
65 echo "WARNING:"
66 echo "The doxygen program was not found in your execute path."
67 echo "You may have doxygen installed somewhere not covered by your path."
68 echo ""
69 echo "If this is the case make sure you have the packages installed, AND"
70 echo "that the doxygen program is in your execute path (see your"
71 echo "shell manual page on setting the \$PATH environment variable), OR"
72 echo "alternatively, specify the program to use with --with-doxygen."
73 AC_MSG_WARN([no doxygen detected. Documentation will not be built])
74 fi
75 ])
76fi
77
78dnl
79dnl Substitution
80dnl
81AC_SUBST([efl_doxygen])
82
83if ! test "x${efl_have_doxygen}" = "xyes" ; then
84 efl_enable_doc="no"
85fi
86
87AM_CONDITIONAL(EFL_BUILD_DOC, test "x${efl_enable_doc}" = "xyes")
88
89if test "x${efl_enable_doc}" = "xyes" ; then
90 m4_default([$1], [:])
91else
92 m4_default([$2], [:])
93fi
94
95])
96
97dnl End of efl_doxygen.m4
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..2433e6c
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,3 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3SUBDIRS = lib
diff --git a/src/lib/Etrophy.h b/src/lib/Etrophy.h
new file mode 100644
index 0000000..cd83072
--- /dev/null
+++ b/src/lib/Etrophy.h
@@ -0,0 +1,140 @@
1#ifndef __ETROPHY_H__
2#define __ETROPHY_H__
3
4#include <Eina.h>
5#include <Eet.h>
6#include <Evas.h>
7
8#ifdef EAPI
9# undef EAPI
10#endif
11
12#ifdef _WIN32
13# ifdef EFL_ETROPHY_BUILD
14# ifdef DLL_EXPORT
15# define EAPI __declspec(dllexport)
16# else
17# define EAPI
18# endif /* ! DLL_EXPORT */
19# else
20# define EAPI __declspec(dllimport)
21# endif /* ! EFL_ETROPHY_BUILD */
22#else
23# ifdef __GNUC__
24# if __GNUC__ >= 4
25# define EAPI __attribute__ ((visibility("default")))
26# else
27# define EAPI
28# endif
29# else
30# define EAPI
31# endif
32#endif /* ! _WIN32 */
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38typedef struct _Etrophy_Trophy Etrophy_Trophy;
39typedef enum {
40 ETROPHY_TROPHY_STATE_HIDDEN = 0,
41 ETROPHY_TROPHY_STATE_VISIBLE,
42 ETROPHY_TROPHY_STATE_EARNED,
43 ETROPHY_TROPHY_STATE_LAST_VALUE
44} Etrophy_Trophy_State;
45
46typedef struct _Etrophy_Lock Etrophy_Lock;
47typedef enum {
48 ETROPHY_LOCK_STATE_LOCKED = 0,
49 ETROPHY_LOCK_STATE_UNLOCKED,
50 ETROPHY_LOCK_STATE_LAST_VALUE
51} Etrophy_Lock_State;
52
53typedef struct _Etrophy_Score Etrophy_Score;
54typedef struct _Etrophy_Level Etrophy_Level;
55typedef struct _Etrophy_Gamescore Etrophy_Gamescore;
56
57/* Etrophy_Trophy */
58EAPI Etrophy_Trophy *etrophy_trophy_new(const char *name, const char *description, Etrophy_Trophy_State state, int date);
59EAPI void etrophy_trophy_free(Etrophy_Trophy *trophy);
60
61EAPI const char *etrophy_trophy_name_get(const Etrophy_Trophy *trophy);
62EAPI const char *etrophy_trophy_description_get(const Etrophy_Trophy *trophy);
63EAPI void etrophy_trophy_state_set(Etrophy_Trophy *trophy, Etrophy_Trophy_State state);
64EAPI Etrophy_Trophy_State etrophy_trophy_state_get(const Etrophy_Trophy *trophy);
65EAPI void etrophy_trophy_date_set(Etrophy_Trophy *trophy, int date);
66EAPI int etrophy_trophy_date_get(const Etrophy_Trophy *trophy);
67
68/* Etrophy_Lock */
69EAPI Etrophy_Lock *etrophy_lock_new(const char *name, Etrophy_Lock_State state, int date);
70EAPI void etrophy_lock_free(Etrophy_Lock *lock);
71
72EAPI const char *etrophy_lock_name_get(const Etrophy_Lock *lock);
73EAPI void etrophy_lock_state_set(Etrophy_Lock *lock, Etrophy_Lock_State state);
74EAPI Etrophy_Lock_State etrophy_lock_state_get(const Etrophy_Lock *lock);
75EAPI void etrophy_lock_date_set(Etrophy_Lock *lock, int date);
76EAPI int etrophy_lock_date_get(const Etrophy_Lock *lock);
77
78/* Etrophy_Score */
79EAPI Etrophy_Score *etrophy_score_new(const char *player_name, int score, int date);
80EAPI void etrophy_score_free(Etrophy_Score *escore);
81
82EAPI const char *etrophy_score_player_name_get(const Etrophy_Score *escore);
83EAPI int etrophy_score_score_get(const Etrophy_Score *escore);
84EAPI int etrophy_score_date_get(const Etrophy_Score *escore);
85
86/* Etrophy_Level */
87EAPI Etrophy_Level *etrophy_level_new(const char *name);
88EAPI void etrophy_level_free(Etrophy_Level *level);
89
90EAPI const char *etrophy_level_name_get(const Etrophy_Level *level);
91EAPI void etrophy_level_score_add(Etrophy_Level *level, Etrophy_Score *escore);
92EAPI void etrophy_level_score_del(Etrophy_Level *level, Etrophy_Score *escore);
93EAPI Eina_List *etrophy_level_scores_list_get(const Etrophy_Level *level);
94EAPI void etrophy_level_scores_list_clear(Etrophy_Level *level);
95
96/* Etrophy_Gamescore */
97EAPI Etrophy_Gamescore *etrophy_gamescore_new(const char *gamename);
98EAPI void etrophy_gamescore_free(Etrophy_Gamescore *gamescore);
99EAPI Etrophy_Gamescore *etrophy_gamescore_path_load(const char *filename);
100EAPI Etrophy_Gamescore *etrophy_gamescore_load(const char *gamename);
101EAPI Eina_Bool etrophy_gamescore_save(Etrophy_Gamescore *gamescore, const char *filename);
102
103EAPI void etrophy_gamescore_level_add(Etrophy_Gamescore *gamescore, Etrophy_Level *level);
104EAPI void etrophy_gamescore_level_del(Etrophy_Gamescore *gamescore, Etrophy_Level *level);
105EAPI Etrophy_Level *etrophy_gamescore_level_get(Etrophy_Gamescore *gamescore, const char *name);
106EAPI Eina_List *etrophy_gamescore_levels_list_get(const Etrophy_Gamescore *gamescore);
107EAPI void etrophy_gamescore_levels_list_clear(Etrophy_Gamescore *gamescore);
108
109EAPI void etrophy_gamescore_trophy_add(Etrophy_Gamescore *gamescore, Etrophy_Trophy *trophy);
110EAPI void etrophy_gamescore_trophy_del(Etrophy_Gamescore *gamescore, Etrophy_Trophy *trophy);
111EAPI Etrophy_Trophy *etrophy_gamescore_trophy_get(Etrophy_Gamescore *gamescore, const char *name);
112EAPI Eina_List *etrophy_gamescore_trophies_list_get(const Etrophy_Gamescore *gamescore);
113EAPI void etrophy_gamescore_trophies_list_clear(Etrophy_Gamescore *gamescore);
114
115EAPI void etrophy_gamescore_lock_add(Etrophy_Gamescore *gamescore, Etrophy_Lock *lock);
116EAPI void etrophy_gamescore_lock_del(Etrophy_Gamescore *gamescore, Etrophy_Lock *lock);
117EAPI Etrophy_Lock *etrophy_gamescore_lock_get(Etrophy_Gamescore *gamescore, const char *name);
118EAPI Eina_List *etrophy_gamescore_locks_list_get(const Etrophy_Gamescore *gamescore);
119EAPI void etrophy_gamescore_locks_list_clear(Etrophy_Gamescore *gamescore);
120
121EAPI void etrophy_gamescore_clear(Etrophy_Gamescore *gamescore);
122
123EAPI int etrophy_gamescore_level_hi_score_get(const Etrophy_Gamescore *gamescore, const char *level_name);
124EAPI int etrophy_gamescore_level_low_score_get(const Etrophy_Gamescore *gamescore, const char *level_name);
125EAPI Etrophy_Score *etrophy_gamescore_level_score_add(Etrophy_Gamescore *gamescore, const char *level_name, const char *player_name, int score, int date);
126
127/* Layouts */
128EAPI Evas_Object *etrophy_score_layout_add(Evas_Object *parent, Etrophy_Gamescore *gamescore);
129EAPI Evas_Object *etrophy_trophies_layout_add(Evas_Object *parent, Etrophy_Gamescore *gamescore);
130EAPI Evas_Object *etrophy_locks_layout_add(Evas_Object *parent, Etrophy_Gamescore *gamescore);
131
132/* Global initializer / shutdown functions */
133EAPI int etrophy_init(void);
134EAPI int etrophy_shutdown(void);
135
136#ifdef __cplusplus
137}
138#endif
139
140#endif /* __ETROPHY_H__ */
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
new file mode 100644
index 0000000..c8d1e80
--- /dev/null
+++ b/src/lib/Makefile.am
@@ -0,0 +1,24 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3AM_CPPFLAGS = \
4-I. \
5-I$(top_srcdir) \
6-I$(top_srcdir)/src/lib \
7-DPACKAGE_LIB_DIR=\"$(libdir)\" \
8-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
9@EVIL_CFLAGS@ \
10@ELEMENTARY_CFLAGS@
11
12lib_LTLIBRARIES = libetrophy.la
13
14includes_HEADERS = Etrophy.h
15includesdir = $(includedir)/etrophy-@VMAJ@
16
17base_sources = \
18 etrophy_layouts.c \
19 etrophy.c
20
21libetrophy_la_SOURCES = $(base_sources)
22
23libetrophy_la_LIBADD = @ELEMENTARY_LIBS@ @EVIL_LIBS@ -lm
24libetrophy_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@ @release_info@
diff --git a/src/lib/etrophy.c b/src/lib/etrophy.c
new file mode 100644
index 0000000..ee036d6
--- /dev/null
+++ b/src/lib/etrophy.c
@@ -0,0 +1,932 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <limits.h>
6#include <stdio.h>
7#include <sys/stat.h>
8#include <sys/types.h>
9#include <unistd.h>
10
11#include <Ecore_File.h>
12#include <Eet.h>
13#include <Eina.h>
14
15#include "Etrophy.h"
16
17#ifdef ERR
18# undef ERR
19#endif
20#define ERR(...) EINA_LOG_DOM_ERR(_etrophy_log_dom, __VA_ARGS__)
21
22#ifdef DBG
23# undef DBG
24#endif
25#define DBG(...) EINA_LOG_DOM_DBG(_etrophy_log_dom, __VA_ARGS__)
26
27#ifdef INF
28# undef INF
29#endif
30#define INF(...) EINA_LOG_DOM_INFO(_etrophy_log_dom, __VA_ARGS__)
31
32#ifdef WRN
33# undef WRN
34#endif
35#define WRN(...) EINA_LOG_DOM_WARN(_etrophy_log_dom, __VA_ARGS__)
36
37#ifdef CRIT
38# undef CRIT
39#endif
40#define CRIT(...) EINA_LOG_DOM_CRIT(_etrophy_log_dom, __VA_ARGS__)
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46int _etrophy_log_dom = -1;
47static int _etrophy_init_count = 0;
48
49struct _Etrophy_Trophy
50{
51 const char *name;
52 const char *description;
53 Etrophy_Trophy_State state;
54 int date;
55};
56
57struct _Etrophy_Lock
58{
59 const char *name;
60 Etrophy_Lock_State state;
61 int date;
62};
63
64struct _Etrophy_Score
65{
66 const char *player_name;
67 int score;
68 int date;
69};
70
71struct _Etrophy_Level
72{
73 const char *name;
74 Eina_List *scores;
75};
76
77struct _Etrophy_Gamescore
78{
79 Eina_List *levels;
80 Eina_List *trophies;
81 Eina_List *locks;
82 const char *__eet_filename;
83};
84
85static const char GAMESCORE_ENTRY[] = "gamescore";
86
87static Eet_Data_Descriptor *_trophy_descriptor = NULL;
88static Eet_Data_Descriptor *_lock_descriptor = NULL;
89static Eet_Data_Descriptor *_score_descriptor = NULL;
90static Eet_Data_Descriptor *_level_descriptor = NULL;
91static Eet_Data_Descriptor *_gamescore_descriptor = NULL;
92
93static inline void
94_trophy_init(void)
95{
96 Eet_Data_Descriptor_Class eddc;
97
98 if (_trophy_descriptor) return;
99
100 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Etrophy_Trophy);
101 _trophy_descriptor = eet_data_descriptor_stream_new(&eddc);
102
103 EET_DATA_DESCRIPTOR_ADD_BASIC(_trophy_descriptor, Etrophy_Trophy,
104 "name", name, EET_T_STRING);
105 EET_DATA_DESCRIPTOR_ADD_BASIC(_trophy_descriptor, Etrophy_Trophy,
106 "description", description, EET_T_STRING);
107 EET_DATA_DESCRIPTOR_ADD_BASIC(_trophy_descriptor, Etrophy_Trophy,
108 "state", state, EET_T_UINT);
109 EET_DATA_DESCRIPTOR_ADD_BASIC(_trophy_descriptor, Etrophy_Trophy,
110 "date", date, EET_T_INT);
111}
112
113static inline void
114_trophy_shutdown(void)
115{
116 if (!_trophy_descriptor) return;
117 eet_data_descriptor_free(_trophy_descriptor);
118 _trophy_descriptor = NULL;
119}
120
121EAPI Etrophy_Trophy *
122etrophy_trophy_new(const char *name, const char *description, Etrophy_Trophy_State state, int date)
123{
124 Etrophy_Trophy *trophy = calloc(1, sizeof(Etrophy_Trophy));
125
126 if (!trophy)
127 {
128 ERR("Could not calloc Etrophy_Trophy.");
129 return NULL;
130 }
131
132 trophy->name = eina_stringshare_add(name);
133 trophy->description = eina_stringshare_add(description);
134 trophy->state = state;
135 trophy->date = date;
136
137 return trophy;
138}
139
140EAPI void
141etrophy_trophy_free(Etrophy_Trophy *trophy)
142{
143 eina_stringshare_del(trophy->name);
144 eina_stringshare_del(trophy->description);
145 free(trophy);
146}
147
148EAPI inline const char *
149etrophy_trophy_name_get(const Etrophy_Trophy *trophy)
150{
151 return trophy->name;
152}
153
154EAPI inline const char *
155etrophy_trophy_description_get(const Etrophy_Trophy *trophy)
156{
157 return trophy->description;
158}
159
160EAPI inline Etrophy_Trophy_State
161etrophy_trophy_state_get(const Etrophy_Trophy *trophy)
162{
163 return trophy->state;
164}
165
166EAPI inline void
167etrophy_trophy_state_set(Etrophy_Trophy *trophy, Etrophy_Trophy_State state)
168{
169 EINA_SAFETY_ON_NULL_RETURN(trophy);
170 if (state >= ETROPHY_TROPHY_STATE_LAST_VALUE) return;
171 trophy->state = state;
172}
173
174EAPI inline int
175etrophy_trophy_date_get(const Etrophy_Trophy *trophy)
176{
177 return trophy->date;
178}
179
180EAPI inline void
181etrophy_trophy_date_set(Etrophy_Trophy *trophy, int date)
182{
183 EINA_SAFETY_ON_NULL_RETURN(trophy);
184 trophy->date = date;
185}
186
187static inline void
188_lock_init(void)
189{
190 Eet_Data_Descriptor_Class eddc;
191
192 if (_lock_descriptor) return;
193
194 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Etrophy_Lock);
195 _lock_descriptor = eet_data_descriptor_stream_new(&eddc);
196
197 EET_DATA_DESCRIPTOR_ADD_BASIC(_lock_descriptor, Etrophy_Lock, "name",
198 name, EET_T_STRING);
199 EET_DATA_DESCRIPTOR_ADD_BASIC(_lock_descriptor, Etrophy_Lock, "state",
200 state, EET_T_UINT);
201 EET_DATA_DESCRIPTOR_ADD_BASIC(_lock_descriptor, Etrophy_Lock, "date",
202 date, EET_T_INT);
203}
204
205static inline void
206_lock_shutdown(void)
207{
208 if (!_lock_descriptor) return;
209 eet_data_descriptor_free(_lock_descriptor);
210 _lock_descriptor = NULL;
211}
212
213EAPI Etrophy_Lock *
214etrophy_lock_new(const char *name, Etrophy_Lock_State state, int date)
215{
216 Etrophy_Lock *lock = calloc(1, sizeof(Etrophy_Lock));
217
218 if (!lock)
219 {
220 ERR("Could not calloc Etrophy_Lock.");
221 return NULL;
222 }
223
224 lock->name = eina_stringshare_add(name);
225 lock->state = state;
226 lock->date = date;
227
228 return lock;
229}
230
231EAPI void
232etrophy_lock_free(Etrophy_Lock *lock)
233{
234 eina_stringshare_del(lock->name);
235 free(lock);
236}
237
238EAPI inline const char *
239etrophy_lock_name_get(const Etrophy_Lock *lock)
240{
241 return lock->name;
242}
243
244EAPI inline Etrophy_Lock_State
245etrophy_lock_state_get(const Etrophy_Lock *lock)
246{
247 return lock->state;
248}
249
250EAPI inline void
251etrophy_lock_state_set(Etrophy_Lock *lock, Etrophy_Lock_State state)
252{
253 EINA_SAFETY_ON_NULL_RETURN(lock);
254 if (state >= ETROPHY_LOCK_STATE_LAST_VALUE) return;
255 lock->state = state;
256}
257
258EAPI inline int
259etrophy_lock_date_get(const Etrophy_Lock *lock)
260{
261 return lock->date;
262}
263
264EAPI inline void
265etrophy_lock_date_set(Etrophy_Lock *lock, int date)
266{
267 EINA_SAFETY_ON_NULL_RETURN(lock);
268 lock->date = date;
269}
270
271static inline void
272_score_init(void)
273{
274 Eet_Data_Descriptor_Class eddc;
275
276 if (_score_descriptor) return;
277
278 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Etrophy_Score);
279 _score_descriptor = eet_data_descriptor_stream_new(&eddc);
280
281 EET_DATA_DESCRIPTOR_ADD_BASIC(_score_descriptor, Etrophy_Score,
282 "player_name", player_name, EET_T_STRING);
283 EET_DATA_DESCRIPTOR_ADD_BASIC(_score_descriptor, Etrophy_Score,
284 "score", score, EET_T_INT);
285 EET_DATA_DESCRIPTOR_ADD_BASIC(_score_descriptor, Etrophy_Score,
286 "date", date, EET_T_INT);
287}
288
289static inline void
290_score_shutdown(void)
291{
292 if (!_score_descriptor) return;
293 eet_data_descriptor_free(_score_descriptor);
294 _score_descriptor = NULL;
295}
296
297EAPI Etrophy_Score *
298etrophy_score_new(const char *player_name, int score, int date)
299{
300 Etrophy_Score *escore = calloc(1, sizeof(Etrophy_Score));
301
302 if (!escore)
303 {
304 ERR("Could not calloc Etrophy_Score.");
305 return NULL;
306 }
307
308 escore->player_name = eina_stringshare_add(player_name);
309 escore->score = score;
310 escore->date = date;
311
312 DBG("Score created. Player: %s, score: %i", player_name, score);
313
314 return escore;
315}
316
317EAPI void
318etrophy_score_free(Etrophy_Score *escore)
319{
320 eina_stringshare_del(escore->player_name);
321 free(escore);
322}
323
324EAPI inline const char *
325etrophy_score_player_name_get(const Etrophy_Score *escore)
326{
327 return escore->player_name;
328}
329
330EAPI inline int
331etrophy_score_score_get(const Etrophy_Score *escore)
332{
333 return escore->score;
334}
335
336EAPI inline int
337etrophy_score_date_get(const Etrophy_Score *escore)
338{
339 return escore->date;
340}
341
342static inline void
343_level_init(void)
344{
345 Eet_Data_Descriptor_Class eddc;
346
347 if (_level_descriptor) return;
348
349 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Etrophy_Level);
350 _level_descriptor = eet_data_descriptor_stream_new(&eddc);
351
352 EET_DATA_DESCRIPTOR_ADD_BASIC(_level_descriptor, Etrophy_Level,
353 "name", name, EET_T_STRING);
354 EET_DATA_DESCRIPTOR_ADD_LIST(_level_descriptor, Etrophy_Level,
355 "scores", scores, _score_descriptor);
356}
357
358static inline void
359_level_shutdown(void)
360{
361 if (!_level_descriptor) return;
362 eet_data_descriptor_free(_level_descriptor);
363 _level_descriptor = NULL;
364}
365
366EAPI Etrophy_Level *
367etrophy_level_new(const char *name)
368{
369 Etrophy_Level *level = calloc(1, sizeof(Etrophy_Level));
370
371 if (!level)
372 {
373 ERR("Could not calloc Etrophy_Level.");
374 return NULL;
375 }
376
377 level->name = eina_stringshare_add(name);
378 DBG("Level created: %s", name);
379
380 return level;
381}
382
383EAPI void
384etrophy_level_free(Etrophy_Level *level)
385{
386 eina_stringshare_del(level->name);
387 if (level->scores)
388 {
389 Etrophy_Score *scores_elem;
390 EINA_LIST_FREE (level->scores, scores_elem)
391 etrophy_score_free(scores_elem);
392 }
393 free(level);
394}
395
396EAPI inline const char *
397etrophy_level_name_get(const Etrophy_Level *level)
398{
399 return level->name;
400}
401
402static int
403_score_cmp(const void *data1, const void *data2)
404{
405 const Etrophy_Score *escore1 = data1;
406 const Etrophy_Score *escore2 = data2;
407 return escore2->score - escore1->score;
408}
409
410EAPI inline void
411etrophy_level_score_add(Etrophy_Level *level, Etrophy_Score *escore)
412{
413 EINA_SAFETY_ON_NULL_RETURN(level);
414 level->scores = eina_list_sorted_insert(level->scores, _score_cmp, escore);
415}
416
417EAPI inline void
418etrophy_level_score_del(Etrophy_Level *level, Etrophy_Score *escore)
419{
420 EINA_SAFETY_ON_NULL_RETURN(level);
421 level->scores = eina_list_remove(level->scores, escore);
422}
423
424EAPI void
425etrophy_level_scores_list_clear(Etrophy_Level *level)
426{
427 EINA_SAFETY_ON_NULL_RETURN(level);
428 Etrophy_Score *data;
429 EINA_LIST_FREE (level->scores, data)
430 etrophy_score_free(data);
431}
432
433EAPI inline Eina_List *
434etrophy_level_scores_list_get(const Etrophy_Level *level)
435{
436 EINA_SAFETY_ON_NULL_RETURN_VAL(level, NULL);
437 return level->scores;
438}
439
440static inline void
441_gamescore_init(void)
442{
443 Eet_Data_Descriptor_Class eddc;
444
445 if (_gamescore_descriptor) return;
446
447 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Etrophy_Gamescore);
448 _gamescore_descriptor = eet_data_descriptor_stream_new(&eddc);
449
450 EET_DATA_DESCRIPTOR_ADD_LIST(_gamescore_descriptor, Etrophy_Gamescore,
451 "levels", levels, _level_descriptor);
452 EET_DATA_DESCRIPTOR_ADD_LIST(_gamescore_descriptor, Etrophy_Gamescore,
453 "trophies", trophies, _trophy_descriptor);
454 EET_DATA_DESCRIPTOR_ADD_LIST(_gamescore_descriptor, Etrophy_Gamescore,
455 "locks", locks, _lock_descriptor);
456}
457
458static inline void
459_gamescore_shutdown(void)
460{
461 if (!_gamescore_descriptor) return;
462 eet_data_descriptor_free(_gamescore_descriptor);
463 _gamescore_descriptor = NULL;
464}
465
466EAPI Etrophy_Gamescore *
467etrophy_gamescore_new(const char *gamename)
468{
469 Etrophy_Gamescore *gamescore;
470 char filename[1024];
471 char tmp[5] = "/tmp";
472 char *home;
473
474 EINA_SAFETY_ON_NULL_RETURN_VAL(gamename, NULL);
475 gamescore = calloc(1, sizeof(Etrophy_Gamescore));
476 EINA_SAFETY_ON_NULL_RETURN_VAL(gamescore, NULL);
477
478 home = getenv("ETROPHY_PATH");
479 if (!home)
480 {
481 home = getenv("HOME");
482 if (!home)
483 home = tmp;
484 }
485
486 if (!ecore_file_is_dir(home))
487 {
488 ERR("Couldn't find a place to store it. Set $ETROPHY_PATH.");
489 return NULL;
490 }
491
492 snprintf(filename, sizeof(filename), "%s/.etrophy/", home);
493
494 if (!ecore_file_is_dir(filename))
495 {
496 if (!ecore_file_mkdir(filename))
497 {
498 ERR("Failed to create %s.", filename);
499 return NULL;
500 }
501 INF("Directory %s created.", filename);
502 }
503 else
504 INF("Base directory: %s.", filename);
505
506 snprintf(filename, sizeof(filename), "%s/.etrophy/%s.eet", home, gamename);
507 gamescore->__eet_filename = eina_stringshare_add(filename);
508
509 return gamescore;
510}
511
512EAPI void
513etrophy_gamescore_free(Etrophy_Gamescore *gamescore)
514{
515 if (gamescore->levels)
516 {
517 Etrophy_Level *levels_elem;
518 EINA_LIST_FREE (gamescore->levels, levels_elem)
519 etrophy_level_free(levels_elem);
520 }
521 if (gamescore->trophies)
522 {
523 Etrophy_Trophy *trophies_elem;
524 EINA_LIST_FREE (gamescore->trophies, trophies_elem)
525 etrophy_trophy_free(trophies_elem);
526 }
527 if (gamescore->locks)
528 {
529 Etrophy_Lock *locks_elem;
530 EINA_LIST_FREE (gamescore->locks, locks_elem)
531 etrophy_lock_free(locks_elem);
532 }
533 free(gamescore);
534}
535
536EAPI inline void
537etrophy_gamescore_level_add(Etrophy_Gamescore *gamescore, Etrophy_Level *level)
538{
539 EINA_SAFETY_ON_NULL_RETURN(gamescore);
540 gamescore->levels = eina_list_append(gamescore->levels, level);
541}
542
543EAPI inline void
544etrophy_gamescore_level_del(Etrophy_Gamescore *gamescore, Etrophy_Level *level)
545{
546 EINA_SAFETY_ON_NULL_RETURN(gamescore);
547 gamescore->levels = eina_list_remove(gamescore->levels, level);
548}
549
550EAPI Etrophy_Level *
551etrophy_gamescore_level_get(Etrophy_Gamescore *gamescore, const char *name)
552{
553 Etrophy_Level *level;
554 Eina_List *l;
555
556 EINA_SAFETY_ON_NULL_RETURN_VAL(gamescore, NULL);
557 EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
558
559 EINA_LIST_FOREACH(gamescore->levels, l, level)
560 if (!strcmp(name, level->name))
561 return level;
562
563 return NULL;
564}
565
566EAPI void
567etrophy_gamescore_levels_list_clear(Etrophy_Gamescore *gamescore)
568{
569 EINA_SAFETY_ON_NULL_RETURN(gamescore);
570 Etrophy_Level *data;
571 EINA_LIST_FREE (gamescore->levels, data)
572 etrophy_level_free(data);
573}
574
575EAPI inline Eina_List *
576etrophy_gamescore_levels_list_get(const Etrophy_Gamescore *gamescore)
577{
578 EINA_SAFETY_ON_NULL_RETURN_VAL(gamescore, NULL);
579 return gamescore->levels;
580}
581
582EAPI inline void
583etrophy_gamescore_trophy_add(Etrophy_Gamescore *gamescore, Etrophy_Trophy *trophy)
584{
585 EINA_SAFETY_ON_NULL_RETURN(gamescore);
586 gamescore->trophies = eina_list_append(gamescore->trophies, trophy);
587}
588
589EAPI inline void
590etrophy_gamescore_trophy_del(Etrophy_Gamescore *gamescore, Etrophy_Trophy *trophy)
591{
592 EINA_SAFETY_ON_NULL_RETURN(gamescore);
593 gamescore->trophies = eina_list_remove(gamescore->trophies, trophy);
594}
595
596EAPI Etrophy_Trophy *
597etrophy_gamescore_trophy_get(Etrophy_Gamescore *gamescore, const char *name)
598{
599 Etrophy_Trophy *trophy;
600 Eina_List *l;
601
602 EINA_SAFETY_ON_NULL_RETURN_VAL(gamescore, NULL);
603 EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
604
605 EINA_LIST_FOREACH(gamescore->trophies, l, trophy)
606 if (!strcmp(name, trophy->name))
607 return trophy;
608
609 return NULL;
610}
611
612EAPI void
613etrophy_gamescore_trophies_list_clear(Etrophy_Gamescore *gamescore)
614{
615 EINA_SAFETY_ON_NULL_RETURN(gamescore);
616 Etrophy_Trophy *data;
617 EINA_LIST_FREE (gamescore->trophies, data)
618 etrophy_trophy_free(data);
619}
620
621EAPI inline Eina_List *
622etrophy_gamescore_trophies_list_get(const Etrophy_Gamescore *gamescore)
623{
624 EINA_SAFETY_ON_NULL_RETURN_VAL(gamescore, NULL);
625 return gamescore->trophies;
626}
627
628EAPI inline void
629etrophy_gamescore_lock_add(Etrophy_Gamescore *gamescore, Etrophy_Lock *lock)
630{
631 EINA_SAFETY_ON_NULL_RETURN(gamescore);
632 gamescore->locks = eina_list_append(gamescore->locks, lock);
633}
634
635EAPI inline void
636etrophy_gamescore_lock_del(Etrophy_Gamescore *gamescore, Etrophy_Lock *lock)
637{
638 EINA_SAFETY_ON_NULL_RETURN(gamescore);
639 gamescore->locks = eina_list_remove(gamescore->locks, lock);
640}
641
642EAPI Etrophy_Lock *
643etrophy_gamescore_lock_get(Etrophy_Gamescore *gamescore, const char *name)
644{
645 Etrophy_Lock *lock;
646 Eina_List *l;
647
648 EINA_SAFETY_ON_NULL_RETURN_VAL(gamescore, NULL);
649 EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
650
651 EINA_LIST_FOREACH(gamescore->locks, l, lock)
652 if (!strcmp(name, lock->name))
653 return lock;
654
655 return NULL;
656}
657
658EAPI void
659etrophy_gamescore_locks_list_clear(Etrophy_Gamescore *gamescore)
660{
661 EINA_SAFETY_ON_NULL_RETURN(gamescore);
662 Etrophy_Lock *data;
663 EINA_LIST_FREE (gamescore->locks, data)
664 etrophy_lock_free(data);
665}
666
667EAPI void
668etrophy_gamescore_clear(Etrophy_Gamescore *gamescore)
669{
670 EINA_SAFETY_ON_NULL_RETURN(gamescore);
671 etrophy_gamescore_levels_list_clear(gamescore);
672 etrophy_gamescore_locks_list_clear(gamescore);
673 etrophy_gamescore_trophies_list_clear(gamescore);
674}
675
676EAPI inline Eina_List *
677etrophy_gamescore_locks_list_get(const Etrophy_Gamescore *gamescore)
678{
679 EINA_SAFETY_ON_NULL_RETURN_VAL(gamescore, NULL);
680 return gamescore->locks;
681}
682
683EAPI int
684etrophy_gamescore_level_hi_score_get(const Etrophy_Gamescore *gamescore, const char *level_name)
685{
686 Etrophy_Score *escore;
687 Etrophy_Level *level;
688 Eina_List *l;
689
690 EINA_SAFETY_ON_NULL_RETURN_VAL(gamescore, -1);
691
692 EINA_LIST_FOREACH(gamescore->levels, l, level)
693 {
694 if (!strcmp(level->name, level_name))
695 break;
696 }
697
698 if (!level)
699 return -1;
700
701 if (!level->scores)
702 return -1;
703
704 escore = eina_list_data_get(level->scores);
705 return escore->score;
706}
707
708EAPI int
709etrophy_gamescore_level_low_score_get(const Etrophy_Gamescore *gamescore, const char *level_name)
710{
711 Etrophy_Score *escore;
712 Etrophy_Level *level;
713 Eina_List *l;
714
715 EINA_SAFETY_ON_NULL_RETURN_VAL(gamescore, -1);
716
717 EINA_LIST_FOREACH(gamescore->levels, l, level)
718 {
719 if (!strcmp(level->name, level_name))
720 break;
721 }
722
723 if (!level)
724 return -1;
725
726 if (!level->scores)
727 return -1;
728
729 escore = eina_list_data_get(eina_list_last(level->scores));
730 return escore->score;
731}
732
733EAPI Etrophy_Score *
734etrophy_gamescore_level_score_add(Etrophy_Gamescore *gamescore, const char *level_name, const char *player_name, int score, int date)
735{
736 Etrophy_Score *escore;
737 Etrophy_Level *level;
738 Eina_List *l;
739
740 escore = etrophy_score_new(player_name, score, date);
741 if (!escore) return NULL;
742
743 EINA_LIST_FOREACH(gamescore->levels, l, level)
744 {
745 if (!strcmp(level->name, level_name))
746 break;
747 }
748
749 if (!level)
750 {
751 level = etrophy_level_new(level_name);
752 if (!level)
753 {
754 etrophy_score_free(escore);
755 return NULL;
756 }
757 gamescore->levels = eina_list_append(gamescore->levels, level);
758 }
759
760 level->scores = eina_list_sorted_insert(level->scores, _score_cmp, escore);
761
762 return escore;
763}
764
765EAPI Etrophy_Gamescore *
766etrophy_gamescore_path_load(const char *filename)
767{
768 Etrophy_Gamescore *gamescore = NULL;
769 Eet_File *ef;
770
771 DBG("Trying to load from %s", filename);
772
773 ef = eet_open(filename, EET_FILE_MODE_READ);
774 if (!ef)
775 {
776 WRN("Could not open '%s' for read.", filename);
777 return NULL;
778 }
779
780 gamescore = eet_data_read(ef, _gamescore_descriptor, GAMESCORE_ENTRY);
781 if (!gamescore) goto end;
782 gamescore->__eet_filename = eina_stringshare_add(filename);
783
784end:
785 eet_close(ef);
786
787 if (gamescore)
788 INF("Gamescore loaded from %s", filename);
789 else
790 ERR("Gamescore failed to load from %s", filename);
791
792 return gamescore;
793}
794
795EAPI Eina_Bool
796etrophy_gamescore_save(Etrophy_Gamescore *gamescore, const char *filename)
797{
798 Eet_File *ef;
799 Eina_Bool ret;
800
801 DBG("Trying to save %p to %s", gamescore, filename);
802
803 if (filename)
804 eina_stringshare_replace(&(gamescore->__eet_filename), filename);
805 else if (gamescore->__eet_filename)
806 filename = gamescore->__eet_filename;
807 else
808 return EINA_FALSE;
809
810 ef = eet_open(filename, EET_FILE_MODE_READ_WRITE);
811 if (!ef)
812 {
813 ERR("Could not open '%s' for write.", filename);
814 return EINA_FALSE;
815 }
816
817 ret = !!eet_data_write(ef, _gamescore_descriptor, GAMESCORE_ENTRY,
818 gamescore, EINA_TRUE);
819 eet_close(ef);
820
821 if (ret)
822 INF("Gamescore saved to %s", filename);
823 else
824 ERR("Gamescore failed to save to %s", filename);
825
826 return ret;
827}
828
829EAPI Etrophy_Gamescore *
830etrophy_gamescore_load(const char *gamename)
831{
832 char filename[1024];
833 char tmp[5] = "/tmp";
834 char *home;
835
836 if (!gamename)
837 {
838 ERR("You need to provide a gamename");
839 return NULL;
840 }
841
842 home = getenv("ETROPHY_PATH");
843 if (!home)
844 {
845 home = getenv("HOME");
846 if (!home)
847 home = tmp;
848 }
849
850 snprintf(filename, sizeof(filename), "%s/.etrophy/%s.eet", home, gamename);
851
852 return etrophy_gamescore_path_load(filename);
853}
854
855EAPI int
856etrophy_init(void)
857{
858 if (++_etrophy_init_count != 1)
859 return _etrophy_init_count;
860
861 if (!eina_init())
862 {
863 EINA_LOG_CRIT("Couldn't init eina.");
864 return --_etrophy_init_count;
865 }
866
867 _etrophy_log_dom = eina_log_domain_register("etrophy", EINA_COLOR_CYAN);
868 if (_etrophy_log_dom < 0)
869 {
870 EINA_LOG_CRIT("Couldn't create a log domain for etrophy.");
871 goto no_log;
872 }
873
874 if (!eet_init())
875 {
876 ERR("Couldn't init eet.");
877 goto no_eet;
878 }
879
880 if (!ecore_file_init())
881 {
882 ERR("Couldn't init ecore file.");
883 goto no_ecore_file;
884 }
885
886 _trophy_init();
887 _lock_init();
888 _score_init();
889 _level_init();
890 _gamescore_init();
891
892 INF("Etrophy initialized.");
893
894 return _etrophy_init_count;
895
896no_ecore_file:
897 eet_shutdown();
898no_eet:
899 eina_log_domain_unregister(_etrophy_log_dom);
900 _etrophy_log_dom = -1;
901no_log:
902 eina_shutdown();
903 return --_etrophy_init_count;
904}
905
906EAPI int
907etrophy_shutdown(void)
908{
909 if (--_etrophy_init_count != 0)
910 return _etrophy_init_count;
911
912 _gamescore_shutdown();
913 _level_shutdown();
914 _score_shutdown();
915 _lock_shutdown();
916 _trophy_shutdown();
917
918 INF("Etrophy shutdown.");
919
920 eina_log_domain_unregister(_etrophy_log_dom);
921 _etrophy_log_dom = -1;
922
923 ecore_file_shutdown();
924 eet_shutdown();
925 eina_shutdown();
926
927 return _etrophy_init_count;
928}
929
930#ifdef __cplusplus
931}
932#endif
diff --git a/src/lib/etrophy_layouts.c b/src/lib/etrophy_layouts.c
new file mode 100644
index 0000000..932e184
--- /dev/null
+++ b/src/lib/etrophy_layouts.c
@@ -0,0 +1,154 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <Elementary.h>
6
7#include "Etrophy.h"
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13static Elm_Genlist_Item_Class itc_group;
14static Elm_Genlist_Item_Class itc;
15
16static char *
17_group_text_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
18{
19 const Etrophy_Level *level = data;
20 char buf[128];
21
22 snprintf(buf, sizeof(buf), "Level %s", etrophy_level_name_get(level));
23 return strdup(buf);
24}
25
26static char *
27_text_get(void *data, Evas_Object *obj __UNUSED__, const char *part)
28{
29 const Etrophy_Score *score = data;
30 char buf[128];
31
32 if (!strcmp(part, "elm.text"))
33 {
34 const char *name = etrophy_score_player_name_get(score);
35 if (name)
36 return strdup(name);
37 return NULL;
38 }
39
40 snprintf(buf, sizeof(buf), "%i", etrophy_score_score_get(score));
41 return strdup(buf);
42}
43
44static void
45_score_level_changed_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
46{
47 Evas_Object *genlist = data;
48 Elm_Object_Item *item;
49 int value, i = 0;
50
51 value = elm_spinner_value_get(obj);
52 item = elm_genlist_first_item_get(genlist);
53 while (item)
54 {
55 if (elm_genlist_item_item_class_get(item) == &itc_group)
56 if (value == i++)
57 elm_genlist_item_bring_in(item, ELM_GENLIST_ITEM_SCROLLTO_TOP);
58 item = elm_genlist_item_next_get(item);
59 }
60}
61
62EAPI Evas_Object *
63etrophy_score_layout_add(Evas_Object *parent, Etrophy_Gamescore *gamescore)
64{
65 Evas_Object *layout, *spinner, *genlist;
66 Eina_List *levels, *l;
67 Etrophy_Level *level;
68 int i = 0;
69
70 layout = elm_layout_add(parent);
71 elm_layout_file_set(layout, PACKAGE_DATA_DIR "/etrophy.edj",
72 "etrophy/scores/default");
73 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
74 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
75
76 genlist = elm_genlist_add(layout);
77 elm_genlist_homogeneous_set(genlist, EINA_TRUE);
78 evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND,
79 EVAS_HINT_EXPAND);
80 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
81 elm_layout_content_set(layout, "list", genlist);
82
83 spinner = elm_spinner_add(layout);
84 elm_spinner_wrap_set(spinner, EINA_TRUE);
85 elm_spinner_step_set(spinner, 1);
86 elm_spinner_editable_set(spinner, EINA_FALSE);
87 evas_object_smart_callback_add(spinner, "delay,changed",
88 _score_level_changed_cb, genlist);
89 evas_object_size_hint_weight_set(spinner, EVAS_HINT_EXPAND,
90 EVAS_HINT_EXPAND);
91 evas_object_size_hint_align_set(spinner, EVAS_HINT_FILL, EVAS_HINT_FILL);
92 elm_layout_content_set(layout, "selector", spinner);
93
94 itc_group.item_style = "group_index";
95 itc_group.func.text_get = _group_text_get;
96 itc_group.func.content_get = NULL;
97 itc_group.func.state_get = NULL;
98 itc_group.func.del = NULL;
99
100 itc.item_style = "double_label";
101 itc.func.text_get = _text_get;
102 itc.func.content_get = NULL;
103 itc.func.state_get = NULL;
104 itc.func.del = NULL;
105
106 levels = etrophy_gamescore_levels_list_get(gamescore);
107 elm_spinner_min_max_set(spinner, 0, eina_list_count(levels) - 1);
108
109 EINA_LIST_FOREACH(levels, l, level)
110 {
111 Elm_Object_Item *group;
112 Eina_List *scores, *s;
113 Etrophy_Score *score;
114 char buf[128];
115
116 snprintf(buf, sizeof(buf), "Level %s", etrophy_level_name_get(level));
117 elm_spinner_special_value_add(spinner, i++, buf);
118
119 group = elm_genlist_item_append(genlist, &itc_group, level, NULL,
120 ELM_GENLIST_ITEM_GROUP, NULL, NULL);
121 elm_genlist_item_select_mode_set(group,
122 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
123
124 scores = etrophy_level_scores_list_get(level);
125 EINA_LIST_FOREACH(scores, s, score)
126 {
127 Elm_Object_Item *item;
128 item = elm_genlist_item_append(genlist, &itc, score, NULL,
129 ELM_GENLIST_ITEM_NONE, NULL, NULL);
130 elm_genlist_item_select_mode_set(
131 item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
132 }
133 }
134
135 return layout;
136}
137
138EAPI Evas_Object *
139etrophy_trophies_layout_add(Evas_Object *parent __UNUSED__, Etrophy_Gamescore *gamescore __UNUSED__)
140{
141 /* TODO */
142 return NULL;
143}
144
145EAPI Evas_Object *
146etrophy_locks_layout_add(Evas_Object *parent __UNUSED__, Etrophy_Gamescore *gamescore __UNUSED__)
147{
148 /* TODO */
149 return NULL;
150}
151
152#ifdef __cplusplus
153}
154#endif