private void TranslateActionIndicators(Dictionary <string, int> modelNameMap, GameDatabase db, LoadedMod loaded)
        {
            IndicatorModelData d = new IndicatorModelData();

            db.Indicators = d;
            d.Full        = new int[3];
            d.Small       = new int[d.Full.Length];
            d.Mouseover   = new int[d.Full.Length];

            for (int i = 0; i < d.Full.Length; i++)
            {
                d.Full[i]      = -1;
                d.Small[i]     = -1;
                d.Mouseover[i] = -1;
            }

            for (int i = 0; i < loaded.toc.actionIndicators.Length; i++)
            {
                int             typeIndex     = -1;
                int[]           strengthArray = d.Full;
                ActionIndicator mai           = loaded.toc.actionIndicators[i];
                switch (mai.type.ToUpperInvariant())
                {
                case "MOVE":
                    typeIndex = 0;
                    break;

                case "CAPTURE":
                    typeIndex = 1;
                    break;

                case "PROMOTE":
                case "PROMOTION":
                    typeIndex = 2;
                    break;

                default:
                    throw new ModException(string.Format("Unknown indicator type \"{1}\" at position {0}", i, mai.type));
                }
                if (!string.IsNullOrEmpty(mai.strength))
                {
                    switch (mai.strength.ToUpperInvariant())
                    {
                    case "CHOSEN":
                    case "ACTIVE":
                    case "DEFAULT":
                    case "SELECTED":
                        break;

                    case "UNSELECTED":
                    case "INACTIVE":
                    case "SMALL":
                        strengthArray = d.Small;
                        break;

                    case "MOUSEOVER":
                        strengthArray = d.Mouseover;
                        break;

                    default:
                        throw new ModException(string.Format("Unknown indicator strength \"{1}\" at position {0}", i, mai.strength));
                    }
                }
                if (strengthArray[typeIndex] >= 0)
                {
                    throw new ModException(string.Format("Indicator already registered for type {0} and strength {1}, duplicate at position {2}",
                                                         mai.type, string.IsNullOrEmpty(mai.strength) ? "default" : mai.strength, i));
                }
                strengthArray[typeIndex] = SetAndMapModel(modelNameMap, db, loaded, mai.model);
            }

            for (int i = 0; i < d.Full.Length; i++)
            {
                if (d.Full[i] < 0)
                {
                    throw new ModException(string.Format("No indicator registered for type {0}", new string[] { "move", "capture", "promote" }[i]));
                }
            }

            if (loaded.toc.indicatorStackingHeight > 0)
            {
                db.Indicators.StackingHeight = loaded.toc.indicatorStackingHeight;
            }
            else
            {
                db.Indicators.StackingHeight = 1;
            }
        }
示例#2
0
        public void LoadMod(string folder)
        {
            try {
                scripts.StartScriptEnvironment();

                state = State.Loading;
                TOCLoadResult tocLoadResult = GameLink.Game.Components.Get <Query <TOCLoadResult, string> >((int)ComponentKeys.TableOfContentsLoadRequest).Send(folder);
                if (tocLoadResult.error != TOCLoadError.None)
                {
                    throw new ModLoaderException("Cannot load table of contents, error: " + tocLoadResult.error);
                }
                toc = tocLoadResult.toc;
                Debug.Log("Start loading " + toc.name);

                if (toc.extraLuaFiles != null)
                {
                    for (int i = 0; i < toc.extraLuaFiles.Length; i++)
                    {
                        StartLoadLua(folder, toc.extraLuaFiles[i], string.Format("Extra lua file {0}", i));
                    }
                }

                StartLoadAsset(folder, toc.boardModel, "boardModel");
                StartLoadLua(folder, toc.boardSetupFunction, "boardSetupFunction");
                StartLoadLua(folder, toc.winLossFunction, "winLossFunction");

                if (toc.pieces == null || toc.pieces.Length == 0)
                {
                    throw new ModLoaderException("Mod requires at least one piece.");
                }

                for (int p = 0; p < toc.pieces.Length; p++)
                {
                    Piece piece = toc.pieces[p];
                    if (piece == null)
                    {
                        throw new ModLoaderException("Null piece given at position " + p);
                    }
                    else if (string.IsNullOrEmpty(piece.name))
                    {
                        throw new ModLoaderException("Piece not given a name at position " + p);
                    }
                    string baseExcName = string.Format("piece {0} ", piece.name);
                    StartLoadAsset(folder, piece.player1Model, baseExcName + "player1Model");
                    StartLoadAsset(folder, piece.player2Model, baseExcName + "player2Model");
                    if (!string.IsNullOrEmpty(piece.promoteIndicatorModel))
                    {
                        StartLoadAsset(folder, piece.promoteIndicatorModel, baseExcName + "player2Model");
                    }
                    StartLoadLua(folder, piece.actionOptionFunction, baseExcName + "actionOptionFunction");
                }

                if (toc.actionIndicators == null || toc.actionIndicators.Length == 0)
                {
                    throw new ModLoaderException("Mod requires action indicator models.");
                }

                for (int i = 0; i < toc.actionIndicators.Length; i++)
                {
                    ActionIndicator indicator = toc.actionIndicators[i];
                    if (indicator == null)
                    {
                        throw new ModLoaderException("Null indicator given at position " + i);
                    }
                    else if (string.IsNullOrEmpty(indicator.type))
                    {
                        throw new ModLoaderException("Indicator not given a type at position " + i);
                    }
                    string testName;
                    if (string.IsNullOrEmpty(indicator.strength))
                    {
                        testName = string.Format("indicator {0}", indicator.type);
                    }
                    else
                    {
                        testName = string.Format("indicator {0}-{1}", indicator.type, indicator.strength);
                    }
                    StartLoadAsset(folder, indicator.model, testName);
                }
            } catch (ModLoaderException mlx) {
                GameLink.Game.SceneComponents.Get <Message <string> >((int)ComponentKeys.ModLoadError).Send(mlx.Message);
            }
        }