comparison api/Objects/WarFoundryStagedLoadingObject.cs @ 8:613bc5eaac59

Re #9 - Make WarFoundry loading granular * Remove specific staged loading classes * Rework category loading for GameSystem and Race to make it use AddCategory(Category) method * Promote staged loading from Native Factory to all Factories level * Refactor XML Factory to use smaller methods Also removed some commented code that isn't used any more
author IBBoard <dev@ibboard.co.uk>
date Sun, 04 Jan 2009 19:24:13 +0000
parents
children 306558904c2a
comparison
equal deleted inserted replaced
7:895c8a2378a1 8:613bc5eaac59
1 // WarFoundryStagedLoadingObject.cs is a part of the IBBoard.WarFoundry.API library (referred to from here as "this program")
2 //
3 // Copyright (C) 2009 IBBoard
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18
19 using System;
20 using System.IO;
21 using IBBoard.WarFoundry.API.Factories;
22
23 namespace IBBoard.WarFoundry.API.Objects
24 {
25 public class WarFoundryStagedLoadingObject : WarFoundryObject, IWarFoundryStagedLoadObject
26 {
27 private bool isFullyLoaded;
28 private IWarFoundryFactory creatingFactory;
29 private FileInfo sourceFile;
30
31 protected WarFoundryStagedLoadingObject(IWarFoundryFactory creatingFactory) : this (null, creatingFactory)
32 {
33 }
34
35 protected WarFoundryStagedLoadingObject(string objName, IWarFoundryFactory creatingFactory) : this(null, objName, creatingFactory)
36 {
37 }
38
39 protected WarFoundryStagedLoadingObject(string objId, string objName, IWarFoundryFactory creatingFactory) : base(objId, objName)
40 {
41 this.creatingFactory = creatingFactory;
42 isFullyLoaded = false;
43 }
44
45 public FileInfo SourceFile
46 {
47 get { return sourceFile; }
48 set { sourceFile = value; }
49 }
50
51 public void EnsureFullyLoaded ()
52 {
53 if (!IsFullyLoaded)
54 {
55 if (Factory == null)
56 {
57 throw new InvalidOperationException("No factory set for partially loaded object with ID "+ID);
58 }
59
60 Factory.CompleteLoading(this);
61 }
62 }
63
64 public IWarFoundryFactory Factory
65 {
66 get { return creatingFactory; }
67 }
68
69 public bool IsFullyLoaded
70 {
71 get { return isFullyLoaded; }
72 }
73
74 public void SetAsFullyLoaded()
75 {
76 isFullyLoaded = true;
77 }
78 }
79 }