public object Load(string path, Type type)
        {
            string json   = File.ReadAllText(path);
            var    jtoken = JToken.Parse(json);

            return(ObjectPipeline.BuildObject(jtoken, type));
        }
        public IContentPack Load(string path)
        {
            ContentPackInfo info    = new ContentPackInfo();
            Texture2D       texture = new Texture2D(2, 2);

            try
            {
                JToken data = DataSerialization.FromFile(Path.Combine(path, ABOUT_FILE));
                info = ObjectPipeline.BuildObject <ContentPackInfo>(data);

                if (File.Exists(Path.Combine(path, IMAGE_FILE)))
                {
                    texture.LoadImage(File.ReadAllBytes(Path.Combine(path, IMAGE_FILE)));
                    texture.filterMode = FilterMode.Point; // TODO: Allow content packs to decide this individually.
                }
                else
                {
                    texture = null;
                }
            }
            catch (FileNotFoundException)
            {
                info.Name        = Path.GetFileName(path);
                info.Author      = "Unknown Author";
                info.Version     = "Unknown Version";
                info.Description = "Unknown Description";

                File.WriteAllText(Path.Combine(path, ABOUT_FILE), ObjectPipeline.UnbuildObject(info, true).ToString());
            }

            return(new ContentPack(path + "/", info.Name, info.Author, info.Description, info.Version, texture));
        }
        private void LoadFile(string file)
        {
            JObject obj = JObject.Parse(File.ReadAllText(file));

            MapData = ObjectPipeline.BuildObject <MapData>(obj);

            _mapController.IfExists(x => x.ApplyMapData(MapData));

            NameInput.text        = MapData.Name;
            DescriptionInput.text = MapData.Description;
        }
 public static PlayerProfile Load(string profileName)
 {
     try
     {
         JToken json = JToken.Parse(File.ReadAllText(GetPath(profileName)));
         return(ObjectPipeline.BuildObject <PlayerProfile>(json));
     }
     catch
     {
         return(null);
     }
 }
        public IEnumerable <KeyValuePair <string, string> > GetTranslations(string cultureName)
        {
            string file = Path.Combine(_path, cultureName) + ".json";

            if (File.Exists(file))
            {
                JToken           token = JToken.Parse(File.ReadAllText(file));
                LocalizationData data  = ObjectPipeline.BuildObject <LocalizationData>(token);

                foreach (var pair in data)
                {
                    yield return(pair);
                }
            }
        }
Example #6
0
        public PlayerProfile[] LoadProfiles()
        {
            if (!Directory.Exists(ProfileManager.ProfileFolder))
            {
                Directory.CreateDirectory(ProfileManager.ProfileFolder);
            }

            string[]        files    = Directory.GetFiles(ProfileManager.ProfileFolder);
            PlayerProfile[] profiles = new PlayerProfile[files.Length];

            for (int i = 0; i < files.Length; i++)
            {
                JObject obj = JObject.Parse(File.ReadAllText(files[i]));
                profiles[i] = ObjectPipeline.BuildObject <PlayerProfile>(obj);
            }

            return(profiles);
        }