Member Controls

Developers > referencing the correct tile in multi-tiled objects
lfolcoLink to postposted: Sun Mar 26, 2006 8:09 pm
Avator for lfolco

Member since:
 2005-05-23
Posts:
 5
ok, so i have my scanner plugin correctly pulling the function sort for single-tiled objects and have even updated the operations form to allow reassiging the function sort from within the scan tool. :D

there are two problems that i'm running into, though:
    - getting a reference to the correct tile of multi-tiled objects through the scanner. these show up as 0 (zero) in the list view results.
    - sometimes the object type and/or the object category show up as integers (i.e., 16, 32, etc.) on the list view results. clearing the cache and rescanning seems to fix this.

my question is, how can i make sure that i'm in the correct tile (the one that has the function sort and subsort set)?

to get the object function to show up, i made the following modifications to SimPe.Cache.PackageCacheItem:

public PackageCacheItem()
{         
   version = VERSION;
   name = "";
   guids = new uint[0];
   type = PackageType.Undefined;
   subcategory = new ObjFunctionSubSort();  <=== NEW
   states = new PackageStates();
}


(also added the proper getter/setter methods).

added following line to the Load method:
subcategory = (ObjFunctionSubSort) reader.ReadUInt32();


added the following line to the Save method:
writer.Write((uint) subcategory);


then, i created the ScannerCategories.cs file (i didn't include all the methods to keep it readable) :


using System;
using System.Windows.Forms;
using SimPe.Cache;
using SimPe.Data;
using SimPe.Interfaces.Files;
using SimPe.Interfaces.Plugin.Scanner;
using SimPe.PackedFiles.Wrapper;

namespace SimPe.Plugin.Scanner
{
   /// <summary>
   /// This class gets an object's function sort.
   /// </summary>
   internal class CategoryScanner : AbstractScanner, IScanner
   {
      public CategoryScanner (ListView lv) : base(lv) { }

      #region IScannerBase Member
      ... SNIP ...


      public void ScanPackage(ScannerItem si, PackageState ps, ListViewItem lvi) 
      {
         if (si.PackageCacheItem.Type == PackageType.Object ||
            si.PackageCacheItem.Type == PackageType.MaxisObject)
         {
            IPackedFileDescriptor[] pfds = si.Package.FindFiles(MetaData.OBJD_FILE);

            foreach (IPackedFileDescriptor pfd in pfds)
            {
               ExtObjd objd = new ExtObjd();
               objd.ProcessData(pfd, si.Package, false);
               si.PackageCacheItem.Subcategory = objd.FunctionSubSort;
            }
            ps.State = TriState.True;
            
         }
         else 
         {
            ps.State = TriState.Null;
         }
         UpdateState(si, ps, lvi);
      }
      

      public void UpdateState(ScannerItem si, PackageState ps, ListViewItem lvi)
      {
         AbstractScanner.SetSubItem(lvi, this.StartColum, "");
         if (ps.State == SimPe.Cache.TriState.True)
         {
            ObjFunctionSubSort subSort = si.PackageCacheItem.Subcategory;
            AbstractScanner.SetSubItem(lvi, this.StartColum, subSort.ToString());
         }
      }
      
      ... SNIP ...
      
      #endregion
   }
}


now, since i've been doing C# for about a week and, therefore, don't really know what i'm doing, my new class isn't really mine as much as a a mish-mash of other code found in the SimPe source. so there may be a lot of extraneous stuff in there that is completely unnecessary or just plain wrong! :oops:

any help would be greatly appreciated!

thanks,

laura
quaxiLink to postposted: Sun Mar 26, 2006 8:44 pm
Avator for quaxi

Member since:
 2006-04-28
Posts:
 3154
An easy way is, to look for the OBJd with Instance 0x000041A8, that is the main OBJd in most Objects.

When the Result shows up as a Number, it menas, that the Value is not known, this might indicate, that you do not store the result of your scan correct.
The ScanPackage Method is only called, when the package was changed or is new. If it is already in the cache, and unchanged, SimPe will directly load the
PackageState item from the Cache and call UpdateState with it.

The correct behaviour would be something like this:

ScanPackage(..){
    ...

    ps.Data = new uint[1];
    ps.Data[0] = (uint)objd.FunctionSubSort;
}

and

UpdateState(..){
    ...

    ObjFunctionSubSort subSort = (ObjFunctionSubSort )ps.Data[0];
    AbstractScanner.SetSubItem(lvi, this.StartColum, subSort.ToString());
    
    ...
}


Btw. You should not use si.PackageCacheItem.Subcategory.


viewthread, 0, 0, referencing-the-correct-tile-in-multi-tiled-objects