diff --git a/src/editor/g_map.pas b/src/editor/g_map.pas
index d6e71a0f263f97e33b7ab55f01e57b98c6cf5010..e63e97479d133e20df090a6228fc8e8576907c22 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;
fn := fn + Res;
end
else
- fn := EditorDir + 'wads/' + Res;
+ fn := WadsDir + DirectorySeparator + Res;
g_CreateTextureWAD(SKY_TEXTURE, fn);
end;
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);
function LoadMap(Res: String): Boolean;
var
+ WAD: TWADEditor_1;
MapReader: TMapReader_1;
Header: TMapHeaderRec_1;
textures: TTexturesRec1Array;
NH := 0;
MainForm.pbLoad.Position := 0;
- MainForm.lLoad.Caption := _lc[I_LOAD_WAD];
+ 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();
- MainForm.lLoad.Caption := _lc[I_LOAD_MAP];
+ MainForm.lLoad.Caption := MsgLoadMap;
Application.ProcessMessages();
MapReader.LoadMap(pData);
begin
MainForm.pbLoad.Position := 0;
MainForm.pbLoad.Max := Length(textures);
- MainForm.lLoad.Caption := _lc[I_LOAD_TEXTURES];
+ MainForm.lLoad.Caption := MsgLoadTextures;
for a := 0 to High(textures) do
begin
if _fn = '' then
TextureRes := FileName + ustr
else
- TextureRes := EditorDir+'wads/'+ustr;
+ TextureRes := WadsDir + DirectorySeparator + ustr;
Error := False;
begin
MainForm.pbLoad.Position := 0;
MainForm.pbLoad.Max := Length(panels);
- MainForm.lLoad.Caption := _lc[I_LOAD_PANELS];
+ MainForm.lLoad.Caption := MsgLoadPanels;
for a := 0 to High(panels) do
begin
begin
MainForm.pbLoad.Position := 0;
MainForm.pbLoad.Max := Length(items);
- MainForm.lLoad.Caption := _lc[I_LOAD_ITEMS];
+ MainForm.lLoad.Caption := MsgLoadItems;
for a := 0 to High(items) do
begin
begin
MainForm.pbLoad.Position := 0;
MainForm.pbLoad.Max := Length(monsters);
- MainForm.lLoad.Caption := _lc[I_LOAD_MONSTERS];
+ MainForm.lLoad.Caption := MsgLoadMonsters;
for a := 0 to High(monsters) do
begin
begin
MainForm.pbLoad.Position := 0;
MainForm.pbLoad.Max := Length(areas);
- MainForm.lLoad.Caption := _lc[I_LOAD_AREAS];
+ MainForm.lLoad.Caption := MsgLoadAreas;
for a := 0 to High(areas) do
begin
begin
MainForm.pbLoad.Position := 0;
MainForm.pbLoad.Max := Length(triggers);
- MainForm.lLoad.Caption := _lc[I_LOAD_TRIGGERS];
+ MainForm.lLoad.Caption := MsgLoadTriggers;
for a := 0 to High(triggers) do
begin
// Открытие карты:
MainForm.pbLoad.Position := 0;
- MainForm.lLoad.Caption := _lc[I_LOAD_MAP];;
+ MainForm.lLoad.Caption := MsgLoadMap;;
Application.ProcessMessages();
map := TConfig.CreateFile(_FileName);
MainForm.pbLoad.Max := i;
MainForm.pbLoad.Position := 0;
- MainForm.lLoad.Caption := _lc[I_LOAD_TEXTURES];
+ MainForm.lLoad.Caption := MsgLoadTextures;
for a := 1 to i do
begin
Continue;
// Нет такой текстуры - ищем в WAD карты:
- if not g_CreateTextureWAD(s, EditorDir+'wads/'+s) then
+ if not g_CreateTextureWAD(s, WadsDir + DirectorySeparator + s) then
begin
s := ExtractFileName(_FileName);
Delete(s, Length(s)-3, 4);
s := UpperCase(s) + '.WAD:TEXTURES\'+ UpperCase(win2utf(map.ReadStr('Textures', 'TextureName'+IntToStr(a), '')));
- if not g_CreateTextureWAD(s, EditorDir+'wads/'+s) then
+ if not g_CreateTextureWAD(s, WadsDir + DirectorySeparator + s) then
Continue;
end;
MainForm.pbLoad.Max := i;
MainForm.pbLoad.Position := 0;
- MainForm.lLoad.Caption := _lc[I_LOAD_PANELS];
+ MainForm.lLoad.Caption := MsgLoadPanels;
for a := 1 to i do
begin
MainForm.pbLoad.Max := i;
MainForm.pbLoad.Position := 0;
- MainForm.lLoad.Caption := _lc[I_LOAD_ITEMS];
+ MainForm.lLoad.Caption := MsgLoadItems;
for a := 1 to i do
begin
MainForm.pbLoad.Max := i;
MainForm.pbLoad.Position := 0;
- MainForm.lLoad.Caption := _lc[I_LOAD_AREAS];
+ MainForm.lLoad.Caption := MsgLoadAreas;
for a := 1 to i do
begin