]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/resources.cpp
Rework exceptions and use maputils
[libs/gltk.git] / source / resources.cpp
index 7415beb5473312e57fcabb29d6691114aa733fc1..869885fecd97e77ae3719399c8fd53d6690baef7 100644 (file)
@@ -1,11 +1,4 @@
-/* $Id$
-
-This file is part of libmspgltk
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
-#include <msp/core/except.h>
+#include <msp/fs/utils.h>
 #include "resources.h"
 
 using namespace std;
@@ -16,6 +9,20 @@ namespace GLtk {
 Resources::Resources():
        path("."),
        default_font(0)
+{
+       init();
+}
+
+Resources::Resources(const FS::Path &fn):
+       path(FS::dirname(fn)),
+       default_font(0)
+{
+       init();
+
+       DataFile::load(*this, fn.str());
+}
+
+void Resources::init()
 {
        add_keyword<Graphic>("graphic");
        add_keyword<GL::Texture2D>("texture");
@@ -26,13 +33,15 @@ Resources::Resources():
 
 void Resources::set_path(const FS::Path &p)
 {
+       /* XXX bad, should change Collection API to allow creators to form paths
+       relative to the datafile location */
        path = p;
 }
 
 const GL::Font &Resources::get_default_font() const
 {
        if(!default_font)
-               throw InvalidState("No default font");
+               throw logic_error("!default_font");
 
        return *default_font;
 }