FLoad.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { FFAttr } from "../data/FFCalAttr";
  2. import FF from "./FF";
  3. import FMap from "./map/FMap";
  4. import FSprite from "./object/FSprite";
  5. import MSprite from "./object/MSprite";
  6. import PSprite from "./object/PSprite";
  7. /**
  8. * 载入战斗数据
  9. */
  10. export default class FLoad{
  11. /**
  12. *
  13. * @param mapId 载入地图数据
  14. * @param callback
  15. */
  16. public static loadMap(ff:FF,stageData,callback:(fmap:FMap)=>void){
  17. // cc.log('loadMap stageData = ',stageData);
  18. cc.resources.load('prefab/map/'+stageData.mapId, cc.Prefab, (err, prefab:cc.Prefab) =>{
  19. if(err){
  20. cc.error(err);
  21. }else{
  22. //加载结束
  23. let node:cc.Node = cc.instantiate(prefab);
  24. let fmap:FMap = node.getComponent(FMap);
  25. ff.mLietMap.loadMap(stageData.mapId)
  26. callback(fmap);
  27. }
  28. } );
  29. }
  30. /**
  31. * 载入角色列表
  32. * @param fDatas
  33. * @param callback
  34. */
  35. public static loadRole(ff:FF,fDatas:Array<FFAttr>,callback:(sprites:Array<FSprite>)=>void){
  36. if(fDatas.length <= 0){
  37. callback([]);
  38. return;
  39. }
  40. let paths = [];
  41. for (let i = 0; i < fDatas.length; i++) {
  42. const element = fDatas[i];
  43. paths.push(element.path);
  44. }
  45. cc.resources.load(paths, cc.Prefab, (err, prefas:any) =>{
  46. if(err){
  47. cc.error(err);
  48. }else{
  49. let player = ff.main.player
  50. let ss = [];
  51. for (let i = 0; i < fDatas.length; i++) {
  52. // for (let i = 0; i < 1; i++) {
  53. const prefab = prefas[i];
  54. let node:cc.Node = cc.instantiate(prefab);
  55. let sp = null;
  56. let data = fDatas[i]
  57. if(data.id != 2){
  58. continue
  59. }
  60. player.role.leader = 2
  61. if(data.id == player.role.leader){//此处需要根据用户设置
  62. sp = node.addComponent(MSprite);
  63. }else{
  64. sp = node.addComponent(PSprite);
  65. }
  66. sp.ff = ff
  67. sp.setAttrData(fDatas[i]);
  68. sp.hp = sp.attrData.hp
  69. ss.push(sp);
  70. }
  71. callback(ss);
  72. } });
  73. }
  74. }