-
Notifications
You must be signed in to change notification settings - Fork 3
/
Xact.cs
130 lines (116 loc) · 4.37 KB
/
Xact.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* Idmr.LfdReader.dll, Library file to read and write LFD resource files
* Copyright (C) 2009-2021 Michael Gaisser (mjgaisser@gmail.com)
* Licensed under the MPL v2.0 or later
*
* Full notice in help/Idmr.LfdReader.chm
* Version: 1.2
*/
/* CHANGE LOG
* v1.2, 160712
* [ADD] _isModified edits
* v1.1, 141215
* [UPD] changed license to MPL
* v1.0
*/
using System;
using System.Drawing;
using System.IO;
using Idmr.Common;
using Idmr.ImageFormat.Act;
namespace Idmr.LfdReader
{
/// <summary>Object for "XACT" backdrop resources.</summary>
/// <remarks><para>The Xact resource is deprecated in favor of separate *.ACT files.<br/>
/// For detailed ACT information refer to Idmr.ImageFormat.Act.chm.</para>
/// <b>*** Requires Idmr.ImageFormat.Act.dll v2.0 or later. ***</b></remarks>
public class Xact : Resource
{
ActImage _act;
#region constructors
/// <summary>Blank constructor.</summary>
public Xact()
{
_type = ResourceType.Xact;
}
/// <summary>Creates a new instance from an existing opened file.</summary>
/// <param name="stream">The opened LFD file.</param>
/// <param name="filePosition">The offset of the beginning of the resource.</param>
/// <exception cref="LoadFileException">Typically due to file corruption.</exception>
public Xact(FileStream stream, long filePosition)
{
read(stream, filePosition);
}
/// <summary>Creates a new instance from an exsiting file.</summary>
/// <param name="path">The full path to the unopened LFD file.</param>
/// <param name="filePosition">The offset of the beginning of the resource.</param>
/// <exception cref="LoadFileException">Typically due to file corruption.</exception>
public Xact(string path, long filePosition)
{
FileStream stream = File.OpenRead(path);
read(stream, filePosition);
stream.Close();
}
#endregion
void read(FileStream stream, long filePosition)
{
try { _process(stream, filePosition); }
catch (Exception x) { throw new LoadFileException(x); }
}
#region public methods
/// <summary>Processes raw data to populate the resource.</summary>
/// <param name="raw">Raw byte data.</param>
/// <param name="containsHeader">Whether or not <paramref name="raw"/> contains the resource Header information.</param>
/// <exception cref="ArgumentException">Header-defined <see cref="Type"/> is not <see cref="Resource.ResourceType.Xact"/>.</exception>
public override void DecodeResource(byte[] raw, bool containsHeader)
{
_decodeResource(raw, containsHeader);
if (_type != ResourceType.Xact) throw new ArgumentException("Raw header is not for a Xact resource");
_act = new ActImage(_rawData);
}
/// <summary>Prepares the resource for writing and updates <see cref="Resource.RawData"/>.</summary>
public override void EncodeResource()
{
string tempActFile = _fileName + ".act";
_act.Save(tempActFile);
FileStream stream = File.OpenRead(tempActFile);
_rawData = new BinaryReader(stream).ReadBytes((int)stream.Length);
stream.Close();
File.Delete(tempActFile);
}
#endregion public methods
#region public properties
// Provides pass-through access to necessary properties
/// <summary>Gets or sets the collection of <see cref="Frame">Frames</see> contained within the Act.</summary>
public FrameCollection Frames
{
get { return _act.Frames; }
set
{
_act.Frames = value;
_isModifed = true;
}
}
/// <summary>Gets or sets the pixel location used to "pin" the object in-game.</summary>
/// <exception cref="BoundaryException"><i>value</i> does not fall within <see cref="Size"/>.</exception>
/// <remarks><see cref="Frame.Location"/> values will update as necessary.</remarks>
public Point Center
{
get { return _act.Center; }
set
{
_act.Center = value;
_isModifed = true;
}
}
/// <summary>Gets the overall height of the object.</summary>
public int Height { get { return _act.Height; } }
/// <summary>Gets the number of images contained within the resource.</summary>
public int NumberOfFrames { get { return _act.NumberOfFrames; } }
/// <summary>Gets the overall size of the object.</summary>
public Size Size { get { return _act.Size; } }
/// <summary>Gets the overall width of the object.</summary>
public int Width { get { return _act.Width; } }
#endregion public properties
}
}