| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- import { _decorator,Constructor, Node } from 'cc';
- import { UIController } from '../easy_ui_framework/UIController';
- // 打包之后有问题不支持名称注入
- export class UIControllerAnnotation {
-
- private static initMap = new Map<any, { bundleName?: any, path?: any,layer?:number }>()
- private static initElement = new Map<any, Map<string,{type:any,prefix?:string,path?:string}>>()
- static UI(param: { bundleName?: any, path: any } | string) {
- return function (target: Constructor) {
- // 首字母小写注入
- if(typeof param == 'string'){
- UIControllerAnnotation.initMap.set(target,{path:param})
- }else{
- UIControllerAnnotation.initMap.set(target,param)
- }
-
- }
- }
- static getElement(target:Constructor){
- // 这里还要找到父类的结果
- if(!target){
- return null
- }
- if(target == UIController){
- return UIControllerAnnotation.initElement.get(target)
- }
- let res = new Map
- let parent = Object.getPrototypeOf(target)
- let parentMap = this.getElement(parent)
- let myMap = UIControllerAnnotation.initElement.get(target)
- if(parentMap){
- parentMap.forEach((vlaue,key)=>res.set(key,vlaue))
- }
- if(myMap){
- myMap.forEach((vlaue,key)=>res.set(key,vlaue))
- }
- return res
- }
- static getUI(ui:Constructor){
- return UIControllerAnnotation.initMap.get(ui)
- }
- static element(type: Constructor|{type:any,prefix?:string,path?:string} = Node) {
-
- let res: PropertyDecorator = function (target:Object, prop: string) {
- // 首字母小写注入
- let map =UIControllerAnnotation.initElement.get(target.constructor)
- if(!map){
- map= new Map
- UIControllerAnnotation.initElement.set(target.constructor,map)
- }
- if(map.get(prop)){
- console.warn("存在同名注入,请检查代码,prop==>",prop)
- }
- if(typeof type == 'object'){
- map.set(prop,type)
- }else{
- map.set(prop,{type:type,prefix:'#'})
- }
-
- }
- return res
- }
-
- }
|