Exemplo n.º 1
0
        private List<CarResource> CollectCarResources(List<CyPhy.CarModel> carcomps)
        {
            List<CarResource> result = new List<CarResource>();
            foreach (var comp in carcomps)
            {
                foreach (var res in comp.Children.CarResourceCollection)
                {
                    // Is the resource already listed?
                    CarResource currres = null;
                    var existingres = result.Where(r => r.FileName == res.Attributes.ResourcePath);
                    if (existingres.Any())
                    {
                        if (existingres.Count() > 1)
                        {
                            throw new Exception("Internal error: car resource found more than once.");
                        }
                        currres = existingres.First();

                    }
                    else
                    {
                        currres = new CarResource() { FileName = res.Attributes.ResourcePath };
                        result.Add(currres);
                    }
                    foreach (var param in res.SrcConnections.CarResourceParameterCollection)
                    {
                        if (param.SrcEnds.CarParameter != null)
                        {
                            if (param.SrcEnds.CarParameter.Attributes.Value.Length == 0)
                            {
                                GMEConsole.Warning.WriteLine("Empty parameter value for '" + param.SrcEnds.CarParameter.Name + "', ignoring.");
                            }
                            else
                            {
                                var existingparam = currres.Parameters.Where(p => p.Name == param.SrcEnds.CarParameter.Name);
                                if (existingparam.Any())
                                {
                                    GMEConsole.Warning.WriteLine("Parameter '" + existingparam.First().Name + "' set twice on resource '" + currres.FileName + "'. Ignoring second setting.");
                                }
                                else
                                {
                                    var newparam = new CarFileParam() { Name = param.SrcEnds.CarParameter.Name, Value = param.SrcEnds.CarParameter.Attributes.Value, Replacement = ((param.Attributes.ParameterKey.Length > 0) ? AdamsCarFileReplacement.FromString(param.Attributes.ParameterKey) : null) };
                                    currres.Parameters.Add(newparam);
                                }
                            }
                        }
                    }
                }
            }
            // Do a 2nd round to discover resource replacements
            foreach (var comp in carcomps)
            {
                foreach (var res in comp.Children.CarResourceCollection)
                {
                    foreach (var conn in res.SrcConnections.ReferenceSwapCollection)
                    {
                        if (conn.SrcEnds.CarResource != null)
                        {
                            var referenced = result.Where(r => r.FileName == res.Attributes.ResourcePath);
                            var referer = result.Where(r => r.FileName == conn.SrcEnds.CarResource.Attributes.ResourcePath);
                            if (referer.Any() && referenced.Any())
                            {
                                referenced.First().References.Add(conn.Attributes.ReferenceName, referer.First());
                            }
                            else
                            {
                                GMEConsole.Error.WriteLine("Internal error, resource was not found: " + conn.DstEnds.CarResource.Attributes.ResourcePath);
                            }
                        }
                    }
                }
            }

            return result;
        }
Exemplo n.º 2
0
        private List <CarResource> CollectCarResources(List <CyPhy.CarModel> carcomps)
        {
            List <CarResource> result = new List <CarResource>();

            foreach (var comp in carcomps)
            {
                foreach (var res in comp.Children.CarResourceCollection)
                {
                    // Is the resource already listed?
                    CarResource currres     = null;
                    var         existingres = result.Where(r => r.FileName == res.Attributes.ResourcePath);
                    if (existingres.Any())
                    {
                        if (existingres.Count() > 1)
                        {
                            throw new Exception("Internal error: car resource found more than once.");
                        }
                        currres = existingres.First();
                    }
                    else
                    {
                        currres = new CarResource()
                        {
                            FileName = res.Attributes.ResourcePath
                        };
                        result.Add(currres);
                    }
                    foreach (var param in res.SrcConnections.CarResourceParameterCollection)
                    {
                        if (param.SrcEnds.CarParameter != null)
                        {
                            if (param.SrcEnds.CarParameter.Attributes.Value.Length == 0)
                            {
                                GMEConsole.Warning.WriteLine("Empty parameter value for '" + param.SrcEnds.CarParameter.Name + "', ignoring.");
                            }
                            else
                            {
                                var existingparam = currres.Parameters.Where(p => p.Name == param.SrcEnds.CarParameter.Name);
                                if (existingparam.Any())
                                {
                                    GMEConsole.Warning.WriteLine("Parameter '" + existingparam.First().Name + "' set twice on resource '" + currres.FileName + "'. Ignoring second setting.");
                                }
                                else
                                {
                                    var newparam = new CarFileParam()
                                    {
                                        Name = param.SrcEnds.CarParameter.Name, Value = param.SrcEnds.CarParameter.Attributes.Value, Replacement = ((param.Attributes.ParameterKey.Length > 0) ? AdamsCarFileReplacement.FromString(param.Attributes.ParameterKey) : null)
                                    };
                                    currres.Parameters.Add(newparam);
                                }
                            }
                        }
                    }
                }
            }
            // Do a 2nd round to discover resource replacements
            foreach (var comp in carcomps)
            {
                foreach (var res in comp.Children.CarResourceCollection)
                {
                    foreach (var conn in res.SrcConnections.ReferenceSwapCollection)
                    {
                        if (conn.SrcEnds.CarResource != null)
                        {
                            var referenced = result.Where(r => r.FileName == res.Attributes.ResourcePath);
                            var referer    = result.Where(r => r.FileName == conn.SrcEnds.CarResource.Attributes.ResourcePath);
                            if (referer.Any() && referenced.Any())
                            {
                                referenced.First().References.Add(conn.Attributes.ReferenceName, referer.First());
                            }
                            else
                            {
                                GMEConsole.Error.WriteLine("Internal error, resource was not found: " + conn.DstEnds.CarResource.Attributes.ResourcePath);
                            }
                        }
                    }
                }
            }

            return(result);
        }