DEADSOFTWARE

Revert to old wad read/write method
[d2df-editor.git] / src / editor / g_map.pas
index 10160e4ac0b6a679d1caa2f7934d123e1d5130c9..a93a75af45ac2396fb8f48f8849aeb24d50824eb 100644 (file)
@@ -246,7 +246,7 @@ implementation
 
 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;
@@ -366,7 +366,7 @@ begin
       fn := fn + Res;
     end
   else
-    fn := EditorDir + 'wads/' + Res;
+    fn := WadsDir + DirectorySeparator + Res;
 
   g_CreateTextureWAD(SKY_TEXTURE, fn);
 end;
@@ -1053,6 +1053,7 @@ end;
 
 function SaveMap(Res: String): Pointer;
 var
+  WAD: TWADEditor_1;
   MapWriter: TMapWriter_1;
   textures: TTexturesRec1Array;
   panels: TPanelsRec1Array;
@@ -1070,6 +1071,7 @@ var
   Len: LongWord;
 
 begin
+  WAD := nil;
   textures := nil;
   panels := nil;
   items := nil;
@@ -1081,6 +1083,17 @@ begin
   Data := nil;
   Len := 0;
 
+// Открываем WAD, если надо:
+  if Res <> '' then
+  begin
+    WAD := TWADEditor_1.Create();
+    g_ProcessResourceStr(Res, FileName, SectionName, ResName);
+    if not WAD.ReadFile(FileName) then
+      WAD.FreeWAD();
+
+    WAD.CreateImage();
+  end;
+
   MapWriter := TMapWriter_1.Create();
 
 // Сохраняем заголовок:
@@ -1337,17 +1350,19 @@ begin
 
 // Записываем в 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);
@@ -1368,6 +1383,7 @@ end;
 
 function LoadMap(Res: String): Boolean;
 var
+  WAD: TWADEditor_1;
   MapReader: TMapReader_1;
   Header: TMapHeaderRec_1;
   textures: TTexturesRec1Array;
@@ -1404,17 +1420,31 @@ begin
   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);
@@ -1426,7 +1456,7 @@ begin
   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
@@ -1445,7 +1475,7 @@ begin
       if _fn = '' then
         TextureRes := FileName + ustr
       else
-        TextureRes := EditorDir+'wads/'+ustr;
+        TextureRes := WadsDir + DirectorySeparator + ustr;
 
       Error := False;
 
@@ -1488,7 +1518,7 @@ begin
   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
@@ -1567,7 +1597,7 @@ 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
@@ -1591,7 +1621,7 @@ 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
@@ -1614,7 +1644,7 @@ 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
@@ -1637,7 +1667,7 @@ 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
@@ -1713,7 +1743,7 @@ begin
 
 // Открытие карты:
   MainForm.pbLoad.Position := 0;
-  MainForm.lLoad.Caption := _lc[I_LOAD_MAP];;
+  MainForm.lLoad.Caption := MsgLoadMap;;
   Application.ProcessMessages();
 
   map := TConfig.CreateFile(_FileName);
@@ -1723,7 +1753,7 @@ begin
 
   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
@@ -1735,13 +1765,13 @@ 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;
 
@@ -1753,7 +1783,7 @@ begin
 
   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
@@ -1764,6 +1794,7 @@ begin
     if not map.SectionExists(section) then
       Continue;
 
+    panel := Default(TPanel);
     panel.X := map.ReadInt(section, 'X1', 0);
     panel.Y := map.ReadInt(section, 'Y1', 0);
     panel.Height := map.ReadInt(section, 'Height', 16);
@@ -1780,6 +1811,7 @@ begin
     end;
 
     panel.Alpha := map.ReadInt(section, 'Alpha', 0);
+    panel.Blending := false;
 
   // Текстура панели:
     if panel.PanelType in [PANEL_WALL, PANEL_BACK, PANEL_FORE, PANEL_STEP] then
@@ -1842,7 +1874,7 @@ 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
@@ -1853,6 +1885,7 @@ begin
     if not map.SectionExists(section) then
       Continue;
 
+    item := Default(TItem);
     item.X := map.ReadInt(section, 'X', 0);
     item.Y := map.ReadInt(section, 'Y', 0);
     item.ItemType := ITEMSCONVERT[map.ReadInt(section, 'Type', 0)];
@@ -1871,7 +1904,7 @@ 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
@@ -1882,6 +1915,7 @@ begin
     if not map.SectionExists(section) then
       Continue;
 
+    area := Default(TArea);
     area.X := map.ReadInt(section, 'X', 0);
     area.Y := map.ReadInt(section, 'Y', 0);
     area.AreaType := map.ReadInt(section, 'Type', 0);
@@ -1895,6 +1929,7 @@ begin
   end;
 
 // Чтение параметров карты:
+  gMapInfo := Default(TMapInfo);
   with gMapInfo do
   begin
     Name := win2utf(map.ReadStr('MapOptions', 'MapName', ''));
@@ -1940,17 +1975,9 @@ begin
   SetLength(gTriggers, 0);
   gTriggers := nil;
 
-  with gMapInfo do
-  begin
-    Name := '';
-    Description := '';
-    Author := '';
-    MusicName := '';
-    SkyName := '';
-    FileName := '';
-    Height := 1600;
-    Width := 1600;
-  end;
+  gMapInfo := Default(TMapInfo);
+  gMapInfo.Width := 1600;
+  gMapInfo.Height := 1600;
 
   with MainForm.lbTextureList do
   begin