Esempio n. 1
0
        //============================================================
        // <T>创建资源对象。</T>
        //
        // @param typeCd 资源类型
        // @param code 代码
        //============================================================
        public FRsResource CreateResource(int typeCd, int code)
        {
            // 创建资源
            FRsResource resource = null;

            switch (typeCd)
            {
            case ERsResource.Picture:
                resource = new FRsResourcePicture();
                break;

            case ERsResource.Animation:
                resource = new FRsResourceAnimation();
                break;

            case ERsResource.Sound:
                resource = new FRsResourceSound();
                break;

            case ERsResource.Music:
                resource = new FRsResourceMusic();
                break;
            }
            // 检查存在性
            if (_resources.Contains(code))
            {
                RMoCore.TrackConsole.Write(this, "CreateResource", "Duplicate resource code. (code={0})", code);
            }
            // 设置对照表
            _resources.Set(code, resource);
            return(resource);
        }
Esempio n. 2
0
        //============================================================
        // <T>扫描文件夹。</T>
        //============================================================
        public void Scan()
        {
            // 处理所有子文件
            FStrings fileNames = RDirectory.ListFiles(_directory);

            foreach (string fileName in fileNames)
            {
                if (-1 != fileName.IndexOf(".svn"))
                {
                    continue;
                }
                // 解析资源
                string shortName = fileName.Substring(fileName.LastIndexOf("\\") + 1);
                string name      = shortName.Substring(3);
                // 解析图片资源
                if (shortName.StartsWith("RP-"))
                {
                    string fullName   = name;
                    string label      = name;
                    int    codeIndex  = name.IndexOf("-");
                    int    labelIndex = name.IndexOf(".png");
                    if (-1 != codeIndex)
                    {
                        label    = name.Substring(0, labelIndex);
                        fullName = name.Substring(codeIndex + 1, labelIndex - codeIndex);
                        name     = name.Substring(0, codeIndex);
                    }
                    if (11 == name.Length)
                    {
                        name = name.Replace(".", "");
                        // 创建图片资源
                        int code = RInt.Parse(name);
                        FRsResourcePicture picture = RContent2dManager.ResourceConsole.CreateResource(ERsResource.Picture, code) as FRsResourcePicture;
                        picture.Folder    = this;
                        picture.Code      = code;
                        picture.Name      = name;
                        picture.Label     = label;
                        picture.FullLabel = FullLabel + "\\" + label;
                        picture.Keyword   = label.Replace(".", "");
                        picture.FileName  = fileName;
                        picture.Directory = _directory;
                        picture.Scan();
                        _resources.Push(picture);
                    }
                }
                // 解析音乐资源
                if (shortName.StartsWith("RM-"))
                {
                    string fullName   = name;
                    string label      = name;
                    int    codeIndex  = name.IndexOf("-");
                    int    labelIndex = name.IndexOf(".mp3");
                    if (-1 != codeIndex)
                    {
                        label    = name.Substring(0, labelIndex);
                        fullName = name.Substring(codeIndex + 1, labelIndex - codeIndex);
                        name     = name.Substring(0, codeIndex);
                    }
                    if (11 == name.Length)
                    {
                        name = name.Replace(".", "");
                        // 创建音乐资源
                        int code = RInt.Parse(name);
                        FRsResourceMusic music = RContent2dManager.ResourceConsole.CreateResource(ERsResource.Music, code) as FRsResourceMusic;
                        music.Folder    = this;
                        music.Code      = code;
                        music.Name      = name;
                        music.Label     = label;
                        music.FullLabel = FullLabel + "\\" + label;
                        music.Keyword   = label.Replace(".", "");
                        music.FileName  = fileName;
                        music.Directory = _directory;
                        music.Scan();
                        _resources.Push(music);
                    }
                }
                // 解析声音资源
                if (shortName.StartsWith("RS-"))
                {
                    string fullName   = name;
                    string label      = name;
                    int    codeIndex  = name.IndexOf("-");
                    int    labelIndex = name.IndexOf(".mp3");
                    if (-1 != codeIndex)
                    {
                        label    = name.Substring(0, labelIndex);
                        fullName = name.Substring(codeIndex + 1, labelIndex - codeIndex);
                        name     = name.Substring(0, codeIndex);
                    }
                    if (11 == name.Length)
                    {
                        name = name.Replace(".", "");
                        // 创建声音资源
                        int code = RInt.Parse(name);
                        FRsResourceSound sound = RContent2dManager.ResourceConsole.CreateResource(ERsResource.Sound, code) as FRsResourceSound;
                        sound.Folder    = this;
                        sound.Code      = code;
                        sound.Name      = name;
                        sound.Label     = label;
                        sound.FullLabel = FullLabel + "\\" + label;
                        sound.Keyword   = label.Replace(".", "");
                        sound.FileName  = fileName;
                        sound.Directory = _directory;
                        sound.Scan();
                        _resources.Push(sound);
                    }
                }
            }
            // 加载设置信息
            //_configName = _directory + "\\config.xml";
            //if (RFile.Exists(_configName)) {
            //   FXmlDocument xdoc = new FXmlDocument();
            //   xdoc.LoadFile(_configName);
            //   foreach (FXmlNode xnode in xdoc.Root.Nodes) {
            //      if (xnode.IsName("Object")) {
            //         string code = null;
            //         if (xnode.Contains("code")) {
            //            code = xnode.Get("code");
            //         } else {
            //            code = xnode.Get("id", String.Empty);
            //         }
            //         if ("" == code) {
            //         }
            //         //FDsResource resource = FindResourceById(code);
            //         //if(null != resource) {
            //         //   resource.LoadConfig(xnode);
            //         //}
            //      }
            //   }
            //}
        }