public BaseResult(string self, int totalPages) { Links = new LinksResult { Self = self }; Meta = new MetaResult { TotalPages = totalPages }; }
/// <summary> /// The dissect meta. /// </summary> /// <param name="m">The m.</param> /// <remarks></remarks> public static void DissectMeta(ref Meta m) { object tempobject = Results[m.type]; if (tempobject == null) { MetaResult mr = new MetaResult(); IFPIO io = IFPHashMap.GetIfp(m.type, m.Map.HaloVersion); mr.IFP = io; Results.Add(m.type, mr); tempobject = Results[m.type]; } MetaResult CurrentResult = tempobject as MetaResult; // figure out headersize for current meta int headersize = m.size; for (int x = 0; x < m.items.Count; x++) { if (m.items[x].type == Meta.ItemType.Reflexive) { Meta.Reflexive tempr = m.items[x] as Meta.Reflexive; if (tempr.translation < headersize && tempr.intag == m.TagIndex) { headersize = tempr.translation; } } } if (CurrentResult.HeaderSizes.IndexOf(headersize) == -1) { CurrentResult.HeaderSizes.Add(headersize); } // AnalyzeReferences(ref m); }
public static Mapper <MetaValue> .ToRule ObjectsAreDecomposed(Mapper <MetaValue> binder) { object FromMeta(MetaValue target) { return(target.Value.Match <object>( metaObject => throw new NotImplementedException(), metaValue => metaValue.Value.Value, metaArray => throw new NotImplementedException() )); } MetaObject ToMetaObject(object target) { MetaType ToMetaType(Type type) { if (type == typeof(object)) { throw new Exception(); } return(new MetaType { Name = type.GetTypeInfo().IsGenericType&& !type.IsConstructedGenericType ? null : MetaName.From(type.FullName), GenericType = type.GetTypeInfo().IsGenericType&& !type.IsConstructedGenericType ? ToMetaType(type.GetGenericTypeDefinition()) : null, GenericArguments = type.GetTypeInfo().IsGenericType&& !type.IsConstructedGenericType ? type.GetTypeInfo().GenericTypeArguments.Select(ToMetaType).ToArray() : null }); } MetaParameter ToParam(ParameterInfo arg) => new MetaParameter() { Name = MetaName.From(arg.Name), Type = ToMetaType(arg.ParameterType) }; MetaResult ToResult(Func <object> execute) { try { var result = execute(); return(MetaResult.From(binder.Map(result).AsT0)); } catch (Exception ex) { return(MetaResult.From(MetaError.From(ex.Message))); } } MetaAction ToAction(MethodInfo method) => new MetaAction() { Name = MetaName.From(method.Name), Call = args => ToResult(() => method.Invoke(target, args.Select(arg => FromMeta(arg.Value)).ToArray())), Parameters = method.GetParameters().Select(ToParam) }; MetaProperty ToProperty(PropertyInfo propertyInfo) => new MetaProperty() { Name = MetaName.From(propertyInfo.Name), Type = ToMetaType(propertyInfo.PropertyType), GetValue = !propertyInfo.CanRead ? null as Func <MetaValue> : () => { var value = propertyInfo.GetValue(target); return(value == null?MetaScalar.From(new MetaNull()) : binder.Map(value).AsT0); }, SetValue = !propertyInfo.CanWrite ? null as Action <MetaValue> : (arg) => { propertyInfo.SetValue(target, FromMeta(arg.Value)); }, }; return(new MetaObject() { Type = ToMetaType(target.GetType()), Properties = target.GetType().GetTypeInfo().DeclaredProperties.Where(t => !t.IsSpecialName && t.DeclaringType == target.GetType()).Select(ToProperty).ToArray(), Actions = target.GetType().GetTypeInfo().DeclaredMethods.Where(t => !t.Name.StartsWith("<") && !t.Name.StartsWith("get_") && !t.Name.StartsWith("set_") && t.DeclaringType == target.GetType()).Select(ToAction).ToArray() }); } return(target => (Mapper <MetaValue> .RuleOutput)(MetaValue) ToMetaObject(target)); }
internal static void SetResult(MetaResult result) { globals->mres = result; }
public static IEnumerator FetchMeta(string levelId) { Debug.Log("Fetching " + levelId + " meta"); var request = UnityWebRequest.Get( string.Format(CytoidApplication.Host + "/meta?level={0}", levelId) ); request.downloadHandler = new DownloadHandlerBuffer(); request.SetRequestHeader("Content-Type", "application/json"); yield return(request.Send()); if (request.isNetworkError) { LastMetaResult = new MetaResult { status = -1 }; } else { if (request.responseCode == 200) { try { LastMetaResult = JsonConvert.DeserializeObject <MetaResult>(request.downloadHandler.text); #if UNITY_EDITOR Debug.Log(JsonConvert.SerializeObject(LastMetaResult)); #endif var level = CytoidApplication.Levels.Find(it => it.id == levelId); if (level == null) { yield break; } var willInvalidate = false; if (level.version > LastMetaResult.version) { // Intended; version info would not be persisted yield break; } if (level.schema_version != LastMetaResult.schema_version) { level.schema_version = LastMetaResult.schema_version; willInvalidate = true; } if (!string.IsNullOrEmpty(LastMetaResult.title) && level.title != LastMetaResult.title) { level.title = LastMetaResult.title; willInvalidate = true; } if (!string.IsNullOrEmpty(LastMetaResult.title_localized) && level.title_localized != LastMetaResult.title_localized) { level.title_localized = LastMetaResult.title_localized; willInvalidate = true; } if (!string.IsNullOrEmpty(LastMetaResult.artist) && level.artist != LastMetaResult.artist) { level.artist = LastMetaResult.artist; willInvalidate = true; } if (!string.IsNullOrEmpty(LastMetaResult.artist_localized) && level.artist_localized != LastMetaResult.artist_localized) { level.artist_localized = LastMetaResult.artist_localized; willInvalidate = true; } if (!string.IsNullOrEmpty(LastMetaResult.artist_source) && level.artist_source != LastMetaResult.artist_source) { level.artist_source = LastMetaResult.artist_source; willInvalidate = true; } if (!string.IsNullOrEmpty(LastMetaResult.illustrator) && level.illustrator != LastMetaResult.illustrator) { level.illustrator = LastMetaResult.illustrator; willInvalidate = true; } if (!string.IsNullOrEmpty(LastMetaResult.illustrator_source) && level.illustrator_source != LastMetaResult.illustrator_source) { level.illustrator_source = LastMetaResult.illustrator_source; willInvalidate = true; } if (LastMetaResult.easy_difficulty != -1 && level.GetChartSection("easy") != null && level.GetChartSection("easy").difficulty != LastMetaResult.easy_difficulty) { level.GetChartSection("easy").difficulty = LastMetaResult.easy_difficulty; willInvalidate = true; } if (LastMetaResult.hard_difficulty != -1 && level.GetChartSection("hard") != null && level.GetChartSection("hard").difficulty != LastMetaResult.hard_difficulty) { level.GetChartSection("hard").difficulty = LastMetaResult.hard_difficulty; willInvalidate = true; } if (LastMetaResult.extreme_difficulty != -1 && level.GetChartSection("extreme") != null && level.GetChartSection("extreme").difficulty != LastMetaResult.extreme_difficulty) { level.GetChartSection("extreme").difficulty = LastMetaResult.extreme_difficulty; willInvalidate = true; } if (willInvalidate) { File.WriteAllText(level.BasePath + "level.json", JsonConvert.SerializeObject(level)); if (CytoidApplication.CurrentLevel.id == levelId) { EventKit.Broadcast("meta reloaded", levelId); } } } catch (Exception e) { LastMetaResult = new MetaResult { status = -1 }; yield break; } } else { LastMetaResult = new MetaResult { status = (int)request.responseCode, message = request.downloadHandler.text }; } } request.Dispose(); }