Beispiel #1
0
    // Display (known / locally present) art using the slot settings.
    public void DisplayArt(SlotSettings slot)
    {
        ArtMetaData meta = slot.MetaData;
        string      tag  = slotNrToTag(slot.SlotNumber);

        DisplayArt(meta, tag);
    }
Beispiel #2
0
    public static SlotSettings FromJSON(string json, ArtRegistry reg)
    {
        Dictionary <string, string> tmp = Serial.DictFromJSON(json);
        int         slotNumber          = Int32.Parse(tmp["SlotNumber"]);
        ArtMetaData metaData            = reg.Get(Checksum.FromString(tmp["Checksum"]));

        return(new SlotSettings(slotNumber, metaData));
    }
Beispiel #3
0
    private bool alreadyDownloaded(ArtMetaData meta)
    {
        Debug.Log("Checking if " + meta.AbsolutePath + " already exists");
        if (!Util.IsFile(meta.AbsolutePath))
        {
            return(false);
        }
        Checksum hash = Checksum.Compute(meta.AbsolutePath, meta.Type);

        return(meta.Checksum.Equals(hash));
    }
Beispiel #4
0
    // Display (known / locally present) art in the specified slot.
    public void DisplayArt(ArtMetaData meta, string slotTag)
    {
        Debug.Log("Displaying slot " + slotTag + ": " + meta.Checksum.ToString());
        string filename = meta.AbsolutePath;

        if (meta.IsPainting)
        {
            Sprite sprite = IMG2Sprite.instance.LoadNewSprite(filename);
            SetSprite(slotTag, sprite);
        }
        else if (meta.IsSculpture)
        {
            GameObject obj = new OBJLoader().Load(meta.AbsolutePath);
            SetObj(slotTag, obj);
        }
    }
Beispiel #5
0
 public static byte[] ZipAsset(ArtMetaData meta)
 {
     // Either use ZipDirectory to zip all files in the directory if 3D,
     // or ZipFile to zip a single image file if 2D.
     if (meta.IsPainting)
     {
         return(ZipFile(meta.AbsolutePath));
     }
     else if (meta.IsSculpture)
     {
         return(ZipDirectory(meta.AbsolutePath));
     }
     else
     {
         throw new ArgumentException("Invalid meta data with checksum " + meta.Checksum.ToString());
     }
 }
Beispiel #6
0
    private void ReceiveManifestRPC(byte[] manifest)
    {
        // XXX: For testing. Simulate that client has no art assets.
        //artReg = ArtRegistry.GetEmptyArtRegistry();
        ArtManifest artManifest = Serial.DeserializeByteArray <ArtManifest>(manifest);

        slotSettings = new Dictionary <Checksum, SlotSettings>();
        List <Checksum> missing = new List <Checksum>();

        foreach (SlotSettings slot in artManifest.Slots)
        {
            SlotSettings ss       = slot;
            Checksum     checksum = slot.MetaData.Checksum;
            if (artReg.HasArt(checksum))
            {
                Debug.Log("Visitor already has art " + checksum.ToString());
                // Use existing meta data from registry.
                ss = slot.WithMeta(artReg.Get(checksum));
                slotSettings.Add(checksum, ss);
                DisplayArt(ss);
            }
            else
            {
                ArtMetaData absolute = ss.MetaData.MakeAbsolutePath(root);
                ss = slot.WithMeta(absolute);
                slotSettings.Add(ss.MetaData.Checksum, ss);
                if (alreadyDownloaded(ss.MetaData))
                {
                    artReg.AddArt(absolute);
                    DisplayArt(ss);
                }
                else
                {
                    Debug.Log("Visitor does NOT have art " + checksum.ToString());
                    missing.Add(checksum);
                    // TODO:
                    // instantiate some place holder for missing?
                }
            }
        }
        if (missing.Count > 0)
        {
            RequestArtAssets(missing);
        }
    }
Beispiel #7
0
 // TODO: automatically write to file when a change is made?
 // Can also be used to update meta data of existing art.
 // As long as the asset is the same, so that the checksum matches, the new
 // metadata will replace the old.
 public ArtRegistry AddArt(ArtMetaData metaData)
 {
     Metadata.Put(metaData.Checksum, metaData);
     return(Save()); // TODO: ???
     //return this;
 }
Beispiel #8
0
 public SlotSettings WithMeta(ArtMetaData metaData) =>
 new SlotSettings(SlotNumber, metaData);
Beispiel #9
0
 public SlotSettings(int slot, ArtMetaData metaData)
 {
     SlotNumber = slot;
     MetaData   = metaData;
 }
Beispiel #10
0
 public static void UnzipAsset(byte[] zip, ArtMetaData meta)
 => Unzip(zip, GetDirectory(meta.AbsolutePath));
Beispiel #11
0
 // Store asset data and register in Art Registry.
 public void ImportAsset(byte[] asset, ArtMetaData meta)
 {
     Debug.Log("Importing received asset.");
     Util.UnzipAsset(asset, meta);
     artReg.AddArt(meta);
 }