예제 #1
0
        public TOCLoadResult LoadTOC(string folder)
        {
            TOCLoadResult result = new TOCLoadResult();

            if (!Directory.Exists(folder))
            {
                result.error = TOCLoadError.MissingFolder;
                return(result);
            }
            string finalFolder = Path.GetFileName(folder);
            string filename    = Path.Combine(folder, finalFolder) + ".toc";

            if (!File.Exists(filename))
            {
                result.error = TOCLoadError.MissingTOCFile;
                return(result);
            }
            try {
                XmlSerializer xml = new XmlSerializer(typeof(TableOfContents));
                using (BufferedStream s = new BufferedStream(new FileStream(filename, FileMode.Open, FileAccess.Read))) {
                    result.toc = (TableOfContents)xml.Deserialize(s);
                }
            } catch (XmlException) {
                result.error = TOCLoadError.XMLException;
                return(result);
            } catch (IOException) {
                result.error = TOCLoadError.IOException;
                return(result);
            }

            if (string.IsNullOrEmpty(result.toc.displayName))
            {
                result.toc.displayName = result.toc.name;
            }
            if (string.IsNullOrEmpty(result.toc.displayVersion))
            {
                result.toc.displayVersion = result.toc.version.ToString();
            }
            if (string.IsNullOrEmpty(result.toc.author))
            {
                result.toc.author = "Anonymous";
            }

            if (string.IsNullOrEmpty(result.toc.name))
            {
                result.error = TOCLoadError.NoName;
            }

            return(result);
        }
예제 #2
0
        public List <LocalModInfo> SearchForMods(string parentFolder)
        {
            if (tocLoader == null)
            {
                tocLoader = scene.Game.Components.Get <Query <TOCLoadResult, string> >((int)ComponentKeys.TableOfContentsLoadRequest);
            }

            List <LocalModInfo> mods = new List <LocalModInfo>();

            if (Directory.Exists(parentFolder))
            {
                foreach (var folder in Directory.GetDirectories(parentFolder))
                {
                    string        filePath  = Path.Combine(parentFolder, folder);
                    TOCLoadResult tocResult = tocLoader.Send(filePath);
                    if (tocResult.error == TOCLoadError.None)
                    {
                        TableOfContents toc  = tocResult.toc;
                        LocalModInfo    info = new LocalModInfo()
                        {
                            filePath       = filePath,
                            modName        = toc.name,
                            displayName    = toc.displayName,
                            displayVersion = toc.displayVersion,
                            numericVersion = toc.version,
                            author         = toc.author,
                        };
                        mods.Add(info);
                    }
                    else
                    {
                        UnityEngine.Debug.Log(string.Format("Unable to load mod TOC at {0}: {1}", folder, tocResult.error));
                    }
                }
            }
            else
            {
                UnityEngine.Debug.Log("Mod folder does not exist");
            }

            return(mods);
        }
예제 #3
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);
            }
        }