Example #1
0
        public AILoader ()
        {
            Directory.SetCurrentDirectory( System.Environment.CurrentDirectory );
            if (!Directory.Exists( AIDirectory ))
            {
                Directory.CreateDirectory( AIDirectory );
            }
            if (File.Exists( AIListPath ))
            {
                list = AssetList.Load( File.Open( AIListPath, FileMode.OpenOrCreate ) );
            }
            interList = new List<Type>();
            compatibleAIs = new List<Type>();
            compatibleAINames = new List<string>();

        }
Example #2
0
        static public void Save ( Stream stream, AssetList data )
        {
            if (serializer == null)
                serializer = new XmlSerializer( typeof( AssetList ) );

            try
            {
                serializer.Serialize( stream, data );
            }
            catch (Exception)
            {
                Log.Write( "Save AssetList error!" );
            }
            finally
            {
                stream.Close();
            }
        }
Example #3
0
        private void InitialAIList ()
        {
            Directory.SetCurrentDirectory( Application.StartupPath );
            if (!Directory.Exists( AIPath ))
            {
                Directory.CreateDirectory( AIPath );
            }
            AIlist = AssetList.Load( File.Open( AIListPath, FileMode.OpenOrCreate ) );
            if (AIlist == null) AIlist = new AssetList();

            ListViewItem myItem = new ListViewItem();
            listViewAI.Items.Clear();
            foreach (AssetItem item in AIlist.list)
            {
                foreach (NameAndTypeName item1 in item.names)
                {
                    myItem = listViewAI.Items.Add( item.DLLName );
                    myItem.SubItems.Add( item1.name );
                    myItem.SubItems.Add( item1.typeNames );
                }
            }
        }
Example #4
0
        private void OpenRuleDLLFileDialog_FileOk ( object sender, CancelEventArgs e )
        {
            List<AssetItem> rulesList = new List<AssetItem>();

            List<string> vaildDLL = new List<string>();

            int countVaildClass = 0;

            foreach (string fileName in OpenRuleDLLFileDialog.FileNames)
            {
                Assembly assembly = DIHelper.GetAssembly( fileName );

                AssetItem curItem;
                bool findGameRule = false;
                curItem = new AssetItem();
                curItem.DLLName = assembly.FullName;// Path.GetFileName( fileName );
                List<NameAndTypeName> names = new List<NameAndTypeName>();
                try
                {
                    foreach (Type type in assembly.GetTypes())
                    {
                        foreach (Type infer in type.GetInterfaces())
                        {
                            if (infer.Name == "IGameRule")
                            {
                                object[] attributes = type.GetCustomAttributes( typeof( RuleAttribute ), false );
                                foreach (object attri in attributes)
                                {
                                    if (attri is RuleAttribute)
                                    {
                                        findGameRule = true;
                                        string ruleName = ((RuleAttribute)attri).Name;
                                        names.Add( new NameAndTypeName( ruleName, type.FullName ) );
                                        countVaildClass++;
                                        break;
                                    }
                                }
                                if (findGameRule)
                                    break;
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    findGameRule = false;
                }
                if (findGameRule)
                {
                    curItem.names = names.ToArray();
                    rulesList.Add( curItem );
                    vaildDLL.Add( fileName );
                }
            }

            if (rulesList.Count != 0)
            {
                Directory.SetCurrentDirectory( Application.StartupPath );
                if (!Directory.Exists( rulesPath ))
                {
                    Directory.CreateDirectory( rulesPath );
                }
                AssetList list = AssetList.Load( File.Open( rulesListPath, FileMode.OpenOrCreate ) );
                if (list == null)
                    list = new AssetList();


                foreach (AssetItem item in rulesList)
                {
                    int index = list.IndexOf( item.DLLName );
                    if (index != -1)
                        list.list[index] = item;
                    else
                        list.list.Add( item );
                }
                AssetList.Save( File.Open( rulesListPath, FileMode.OpenOrCreate ), list );

                foreach (string DLLPath in vaildDLL)
                {
                    string copyPath = Path.Combine( rulesPath, Path.GetFileName( DLLPath ) );
                    if (!Path.GetFullPath( copyPath ).Equals( DLLPath ))
                    {
                        if (File.Exists( copyPath ))
                        {
                            DialogResult result = MessageBox.Show( Path.GetFileName( DLLPath ) + "已存在于" + rulesPath + "中。是否覆盖?", "文件已存在", MessageBoxButtons.YesNo );
                            if (result == DialogResult.Yes)
                            {
                                File.Copy( DLLPath, copyPath, true );
                            }
                        }
                        else
                            File.Copy( DLLPath, copyPath );
                    }
                }
                MessageBox.Show( "添加规则程序集成功!共添加" + vaildDLL.Count + "个有效程序集," + countVaildClass + "个有效规则类", "成功" );
            }
            else
                MessageBox.Show( "未找到有效规则程序集!", "失败" );

            InitialRuleList();
        }
Example #5
0
 static public void Initial()
 {
     list = AssetList.Load( File.OpenRead( Path.Combine( Directories.GameBaseDirectory, ruleListPath ) ) );
 }
Example #6
0
 static public void Initial()
 {
     list = AssetList.Load(File.OpenRead(Path.Combine(Directories.GameBaseDirectory, ruleListPath)));
 }