diff --git a/src/editor/g_map.pas b/src/editor/g_map.pas
index 0c35d481384f5164798248af97a007c9244106b7..5b2cc5f54ce11899881a12d1d89592b90b20adfc 100644 (file)
--- a/src/editor/g_map.pas
+++ b/src/editor/g_map.pas
function SpecialTextureID(TextureName: String): DWORD;
procedure ClearMap();
-function SaveMap(Res: String): Pointer;
+function SaveMap(Res, ArchiveFormat: String): Pointer;
function LoadMap(Res: String): Boolean;
function LoadMapOld(_FileName: String): Boolean;
procedure DrawMap();
uses
BinEditor, g_textures, Dialogs, SysUtils, CONFIG, f_main,
- Forms, Math, f_addresource_texture, WADEDITOR, g_language, g_resources, g_options;
+ Forms, Math, f_addresource_texture, WADEDITOR, g_language, g_options;
const
OLD_ITEM_MEDKIT_SMALL = 1;
Result := TEXTURE_SPECIAL_ACID2;
end;
-function SaveMap(Res: String): Pointer;
+function SaveMap(Res, ArchiveFormat: String): Pointer;
var
+ WAD: TWADEditor;
MapWriter: TMapWriter_1;
textures: TTexturesRec1Array;
panels: TPanelsRec1Array;
Len: LongWord;
begin
+ WAD := nil;
textures := nil;
panels := nil;
items := nil;
Data := nil;
Len := 0;
+// Открываем WAD, если надо:
+ if Res <> '' then
+ begin
+ g_ProcessResourceStr(Res, FileName, SectionName, ResName);
+
+ if ArchiveFormat = '' then
+ begin
+ // format not specified -> try open automatically and append to it (or create new default)
+ WAD := gWADEditorFactory.OpenFile(FileName);
+ if WAD = nil then
+ WAD := gWADEditorFactory.CreateDefaultEditor();
+ end
+ else
+ begin
+ // format specified -> append using exactly this format (overwrite if not compatible)
+ WAD := gWADEditorFactory.CreateEditor(ArchiveFormat);
+ if WAD.ReadFile(FileName) = False then
+ WAD.FreeWAD();
+ end;
+ WAD.CreateImage();
+ end;
+
MapWriter := TMapWriter_1.Create();
// Сохраняем заголовок:
// Записываем в WAD, если надо:
if Res <> '' then
- begin
- g_ProcessResourceStr(Res, FileName, SectionName, ResName);
- g_AddResource(FileName, SectionName, ResName, Data, Len, a);
- ASSERT(a = 0);
- FreeMem(Data);
- Result := nil
- end
+ begin
+ s := utf2win(ResName);
+ WAD.RemoveResource('', s);
+ WAD.AddResource(Data, Len, s, '');
+ WAD.SaveTo(FileName);
+
+ FreeMem(Data);
+ WAD.Free();
+
+ Result := nil;
+ end
else
- begin
- Result := Data
- end
+ Result := Data;
end;
procedure AddTexture(res: String; Error: Boolean);
end;
end;
+function map_CreateAnimTexture(TextureName, Resource: String): Boolean;
+var
+ Data: Pointer = nil;
+ FrameLen: Integer = 0;
+ Width: Word = 0;
+ Height: Word = 0;
+begin
+ Result := GetFrame(Resource, Data, FrameLen, Width, Height);
+ if not Result then // Кадры
+ e_WriteLog(Format('GetFrame() error, res=%s', [TextureName]), MSG_WARNING)
+ else
+ begin
+ Result := g_CreateTextureMemorySize(Data, FrameLen, TextureName, 0, 0, Width, Height, 1);
+ if not Result then // Сама текстура
+ e_WriteLog(Format('g_CreateTextureMemorySize() error, res=%s', [TextureName]), MSG_WARNING);
+ end;
+end;
+
function LoadMap(Res: String): Boolean;
var
+ WAD: TWADEditor_1;
MapReader: TMapReader_1;
Header: TMapHeaderRec_1;
textures: TTexturesRec1Array;
area: TArea;
trigger: TTrigger;
a: Integer;
- Data: Pointer;
- Width, Height, m: Word;
+ m: Word;
FileName, SectionName, ResName, _fn: String;
TextureRes, ustr: String;
pData: Pointer;
- Len, FrameLen: Integer;
- Error: Boolean;
+ Len: Integer;
+ Success: Boolean;
NoTextureID: DWORD;
NW, NH: Word;
begin
Result := False;
pData := nil;
Len := 0;
- Data := nil;
- FrameLen := 0;
- Width := 0;
- Height := 0;
NoTextureID := 0;
NW := 0;
NH := 0;
MainForm.lLoad.Caption := MsgLoadWad;
Application.ProcessMessages();
-// Читаем ресурс карты
+// Открываем WAD:
+ WAD := TWADEditor_1.Create();
g_ProcessResourceStr(Res, FileName, SectionName, ResName);
- g_ReadResource(FileName, SectionName, ResName, pData, Len);
- if pData = nil then Exit;
+
+ if not WAD.ReadFile(FileName) then
+ begin
+ WAD.Free();
+ Exit;
+ end;
+
+// Читаем ресурс карты:
+ if not WAD.GetResource('', utf2win(ResName), pData, Len) then
+ begin
+ WAD.Free();
+ Exit;
+ end;
+
+ WAD.Free();
MapReader := TMapReader_1.Create();
Application.ProcessMessages();
ustr := win2utf(textures[a].Resource);
- if IsSpecialTexture(ustr) then
+ Success := True;
+ if not IsSpecialTexture(ustr) then
begin
- AddTexture(ustr, False);
- Continue;
- end;
-
- g_ProcessResourceStr(ustr, @_fn, nil, nil);
-
- if _fn = '' then
- TextureRes := FileName + ustr
- else
- TextureRes := WadsDir + DirectorySeparator + ustr;
+ g_ProcessResourceStr(ustr, @_fn, nil, nil);
- Error := False;
+ if _fn = ''
+ then TextureRes := FileName + ustr
+ else TextureRes := WadsDir + DirectorySeparator + ustr;
- if not ByteBool(textures[a].Anim) then
+ if not Boolean(textures[a].Anim) then
begin // Обычная текстура
if not g_CreateTextureWAD(ustr, TextureRes) then
begin
- e_WriteLog(Format('g_CreateTextureWAD() error, res=%s',
- [ustr]), MSG_WARNING);
- Error := True;
+ e_WriteLog(Format('g_CreateTextureWAD() error, res=%s', [ustr]), MSG_WARNING);
+ Success := map_CreateAnimTexture(ustr, TextureRes);
+ if Success then
+ begin
+ textures[a].Anim := Byte(ByteBool(True));
+ e_WriteLog(Format(' wrong (outdated?) anim flag hint - texture #%d is actually animated: %s', [a, ustr]), MSG_WARNING);
+ end;
end;
-
- AddTexture(ustr, Error);
end
- else // Anim
+ else
begin // Анимированная текстура
- if not GetFrame(TextureRes, Data, FrameLen, Width, Height) then
- begin // Кадры
- e_WriteLog(Format('GetFrame() error, res=%s',
- [ustr]), MSG_WARNING);
- Error := True;
- end;
-
- if not g_CreateTextureMemorySize(Data, FrameLen, ustr, 0, 0, Width, Height, 1) then
- begin // Сама текстура
- e_WriteLog(Format('g_CreateTextureMemorySize() error, res=%s',
- [ustr]), MSG_WARNING);
- Error := True;
+ if not map_CreateAnimTexture(ustr, TextureRes) then
+ begin
+ Success := g_CreateTextureWAD(ustr, TextureRes);
+ if Success then
+ begin
+ textures[a].Anim := Byte(ByteBool(False));
+ e_WriteLog(Format(' wrong (outdated?) anim flag hint - texture #%d is actually static: %s', [a, ustr]), MSG_WARNING);
+ end;
end;
-
- AddTexture(ustr, Error);
end;
+ end;
+
+ AddTexture(ustr, not Success);
end;
end;