最近在做wc4编辑器中想到一个问题,为什么不根据规则,自动生成类,然后再使用这个类呢...

然后我感觉emmm,项目又要大改了.....

然后花了一天时间磨了出来.

规则文件:

<Files  game="wc4" fileType="btl" ifET="true">
<bm0 id="bm0" name="masterData" ifCycle="false"  Count="one" remark="主数据 128" >
    <bm id="bm0_1" size="8" name="biBtlVersion"  remark="btl版本" type="Integer" function="no" defaul="1" />
    <bm id="bm0_2" size="8" name="biMapSource" remark="地图序号" type="Integer" function="no" defaul="0" />
    <bm id="bm0_3" size="8" name="biMapCutx" remark="x" type="Integer" function="no" defaul="0" />
    <bm id="bm0_4" size="8" name="biMapCuty" remark="y" type="Integer" function="no" defaul="0" />
    <bm id="bm0_5" size="8" name="biMapx" remark="w" type="Integer" function="mapW" defaul="0" />
    <bm id="bm0_6" size="8" name="biMapy" remark="h" type="Integer" function="mapH" defaul="0" />
    <bm id="bm0_7" size="8" name="biLegionNum" remark="军团总数" type="Integer" function="no" defaul="0" />
    <bm id="bm0_8" size="8" name="biBuildingNum" remark="建筑总数" type="Integer" function="no" defaul="0" />
    <bm id="bm0_9" size="8" name="biUnitsNum" remark="单位总数" type="Integer" function="no" defaul="0" />
    <bm id="bm0_10" size="8" name="biMovingNum" remark="方案总数" type="Integer" function="no" defaul="0" />
    <bm id="bm0_11" size="8" name="biEventsNum" remark="事件总数" type="Integer" function="no" defaul="0" />
    <bm id="bm0_12" size="8" name="biWeatherNum" remark="天气总数" type="Integer" function="no" defaul="0" />
    <bm id="bm0_13" size="8" name="biTask" remark="胜利条件" type="Integer" function="no" defaul="0" />00进攻 01全灭 02防守 03积攒物资
    <bm id="bm0_14" size="8" name="biVictoryRound" remark="胜利回合" type="Integer" function="no" defaul="40" />
    <bm id="bm0_15" size="8" name="biGreatVictoryRound" remark="重大胜利回合" type="Integer" function="no" defaul="30" /> 三星回合 02防守中指红圈个数(?)
    <bm id="bm0_16" size="8" name="biSummonSoldiersNum" remark="援军总数" type="Integer" function="no" defaul="0" />
    <bm id="bm0_17" size="8" name="biAirportAirstrikesNum" remark="空袭总数" type="Integer" function="no" defaul="0" />
    <bm id="bm0_18" size="8" name="biEntranceA" remark="放置位甲" type="Integer" function="no" defaul="0" />
    <bm id="bm0_19" size="8" name="biEntranceB" remark="放置位乙" type="Integer" function="no" defaul="0" />
    <bm id="bm0_20" size="8" name="biFlagNum" remark="国家首都" type="Integer" function="no" defaul="0" />
    <bm id="bm0_21" size="8" name="biUnknown20" remark="?" type="Integer" function="no" defaul="0" />
    <bm id="bm0_22" size="8" name="biUnknown21" remark="?" type="Integer" function="no" defaul="0" />
    <bm id="bm0_23" size="8" name="biTerrainsNum" remark="地块总数" type="Integer" function="no" defaul="0" />
    <bm id="bm0_24" size="8" name="biMoneyNeeded" remark="积攒金钱" type="Integer" function="no" defaul="0" />
    <bm id="bm0_25" size="8" name="biIndustryNeeded" remark="积攒工业" type="Integer" function="no" defaul="0" />
    <bm id="bm0_26" size="8" name="biTechNeeded" remark="积攒科技" type="Integer" function="no" defaul="0" />
    <bm id="bm0_27" size="8" name="biLandminesNum" remark="地雷数" type="Integer" function="no" defaul="0" />
    <bm id="bm0_28" size="8" name="biUnknown27" remark="?" type="Integer" function="no" defaul="0" />
    <bm id="bm0_29" size="8" name="biStreatgyNum" remark="战略总数" type="Integer" function="no" defaul="0" />
    <bm id="bm0_30" size="8" name="biUnknown29" remark="?" type="Integer" function="no" defaul="0" />
    <bm id="bm0_31" size="8" name="biUnknown30" remark="?" type="Integer" function="no" defaul="0" />
    <bm id="bm0_32" size="8" name="biNationalAirstrikesNum" remark="空中支援" type="Integer" function="no" defaul="0" />
    
    </bm0>
    <bm1 id="bm1" name="legionData" ifCycle="true"  Count="bm0_7" remark="军团 300" >
    <bm id="bm1_1" size="8" name="blId"  remark="军团id" type="Integer" function="no" defaul="0" />
    <bm id="bm1_2" size="8" name="blCountry" remark="国家id" type="Integer" function="no" defaul="0" />
    <bm id="bm1_3" size="8" name="blMoney" remark="金钱" type="Integer" function="no" defaul="0" />
    <bm id="bm1_4" size="8" name="blIndustry" remark="工业" type="Integer" function="no" defaul="0" />
    <bm id="bm1_5" size="8" name="blTech" remark="科技" type="Integer" function="no" defaul="0" />
    <bm id="bm1_6" size="8" name="blControl" remark="控制" type="Integer" function="no" defaul="0" /> 玩家是0
    <bm id="bm1_7" size="8" name="blCamp" remark="阵营" type="Integer" function="no" defaul="0" />
    <bm id="bm1_8" size="8" name="blDefeat" remark="胜利条件" type="Integer" function="no" defaul="0" />
    <bm id="bm1_9" size="8" name="blMoneyRate" remark="税率加成" type="Single" function="no" defaul="0" />
    <bm id="bm1_10" size="8" name="blHpRate" remark="兵种加成" type="Single" function="no" defaul="0" />
    <bm id="bm1_11" size="2" name="r" remark="颜色r" type="Byte" function="no" defaul="0" />
    <bm id="bm1_12" size="2" name="g" remark="颜色g" type="Byte" function="no" defaul="0" />
    <bm id="bm1_13" size="2" name="b" remark="颜色b" type="Byte" function="no" defaul="0" />
    <bm id="bm1_14" size="2" name="a" remark="颜色a" type="Byte" function="no" defaul="255" />
    <bm id="bm1_15" size="8" name="blNuclearNum1" remark="原子弹" type="Integer" function="no" defaul="0" />
    <bm id="bm1_16" size="8" name="blNuclearNum2" remark="氢弹" type="Integer" function="no" defaul="0" />
    <bm id="bm1_17" size="8" name="blNuclearNum3" remark="三相弹" type="Integer" function="no" defaul="0" />
    <bm id="bm1_18" size="8" name="blNuclearNum4" remark="反物质弹" type="Integer" function="no" defaul="0" />
    <bm id="bm1_19" size="8" name="blUnknown71" remark="机动" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_20" size="8" name="blUnknown72" remark="步枪" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_21" size="8" name="blUnknown73" remark="迷彩" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_22" size="8" name="blUnknown74" remark="工兵" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_23" size="8" name="blUnknown75" remark="手雷" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_24" size="8" name="blUnknown76" remark="迫击炮" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_25" size="8" name="blUnknown77" remark="行军" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_26" size="8" name="blUnknown78" remark="防弹衣" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_27" size="8" name="blUnknown79" remark="装甲" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_28" size="8" name="blUnknown80" remark="主炮" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_29" size="8" name="blUnknown81" remark="车体" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_30" size="8" name="blUnknown82" remark="引擎" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_31" size="8" name="blUnknown83" remark="机枪" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_32" size="8" name="blUnknown84" remark="突袭" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_33" size="8" name="blUnknown85" remark="防空" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_34" size="8" name="blUnknown86" remark="强化车体" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_35" size="8" name="blUnknown87" remark="炮击" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_36" size="8" name="blUnknown88" remark="火箭弹" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_37" size="8" name="blUnknown89" remark="牵引" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_38" size="8" name="blUnknown90" remark="装甲" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_39" size="8" name="blUnknown91" remark="火力" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_40" size="8" name="blUnknown92" remark="火箭" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_41" size="8" name="blUnknown93" remark="伪装" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_42" size="8" name="blUnknown94" remark="船体" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_43" size="8" name="blUnknown95" remark="推进" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_44" size="8" name="blUnknown96" remark="装甲" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_45" size="8" name="blUnknown97" remark="武器" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_46" size="8" name="blUnknown98" remark="舰炮" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_47" size="8" name="blUnknown99" remark="鱼雷" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_48" size="8" name="blUnknown100" remark="扫雷" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_49" size="8" name="blUnknown101" remark="防空" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_50" size="8" name="blUnknown102" remark="现代舰艇" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_51" size="8" name="blUnknown103" remark="航空燃油" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_52" size="8" name="blUnknown104" remark="航空发动机" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_53" size="8" name="blUnknown105" remark="航空炸弹" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_54" size="8" name="blUnknown106" remark="空袭" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_55" size="8" name="blUnknown107" remark="轰炸" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_56" size="8" name="blUnknown108" remark="战略轰炸" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_57" size="8" name="blUnknown109" remark="空降兵" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_58" size="8" name="blUnknown110" remark="喷气发动机" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_59" size="8" name="blUnknown111" remark="机枪堡" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_60" size="8" name="blUnknown112" remark="要塞炮" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_61" size="8" name="blUnknown113" remark="海岸炮" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_62" size="8" name="blUnknown114" remark="火箭发射器" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_63" size="8" name="blUnknown115" remark="工事" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_64" size="8" name="blUnknown116" remark="高射机枪" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_65" size="8" name="blUnknown117" remark="防空炮" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_66" size="8" name="blUnknown118" remark="防空导弹" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_67" size="8" name="blUnknown119" remark="雷达" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_68" size="8" name="blUnknown120" remark="弹头" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_69" size="8" name="blUnknown121" remark="火箭发动机" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_70" size="8" name="blUnknown122" remark="破防" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_71" size="8" name="blUnknown123" remark="核聚变" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_72" size="8" name="blUnknown124" remark="?" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_73" size="8" name="blUnknown125" remark="?" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_74" size="8" name="blUnknown126" remark="?" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_75" size="8" name="blUnknown127" remark="战略" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_76" size="8" name="blUnknown128" remark="科技等级" type="Integer" function="no" defaul="0"/>
    <bm id="bm1_77" size="8" name="blUnknown129" remark="?" type="?" function="no" defaul="00000000"/>
    <bm id="bm1_78" size="8" name="blUnknown130" remark="?" type="Integer" function="no" defaul="0"/>
    </bm1>
    <bm2 id="bm2" name="terrainData" ifCycle="bm0_2==0"  Count="sumGride" remark="地形 16" >
    <bm id="bm2_1" size="2" name="bmTerrain1Group"  remark="地块组1" type="Byte" function="no" defaul="0" />
    <bm id="bm2_2" size="2" name="bmTerrain1Id" remark="地块号1" type="Byte" function="no" defaul="0" />
    <bm id="bm2_3" size="2" name="bmTerrain1X" remark="x" type="Byte" function="no" defaul="0" />
    <bm id="bm2_4" size="2" name="bmTerrain1Y" remark="y" type="Byte" function="no" defaul="0" />
    <bm id="bm2_5" size="2" name="bmDoodad1Group" remark="装饰组1" type="Byte" function="no" defaul="0" />
    <bm id="bm2_6" size="2" name="bmDoodad1Id" remark="装饰号1" type="Byte" function="no" defaul="255" />
    <bm id="bm2_7" size="2" name="bmDoodad1X" remark="x" type="Byte" function="no" defaul="0" />
    <bm id="bm2_8" size="2" name="bmDoodad1Y" remark="y" type="Byte" function="no" defaul="0" />
    <bm id="bm2_9" size="2" name="bmDoodad2Group" remark="装饰组2" type="Byte" function="no" defaul="0" />
    <bm id="bm2_10" size="2" name="bmDoodad2Id" remark="装饰号2" type="Byte" function="no" defaul="255" />
    <bm id="bm2_11" size="2" name="bmDoodad2X" remark="x" type="Byte" function="no" defaul="0" />
    <bm id="bm2_12" size="2" name="bmDoodad2Y" remark="y" type="Byte" function="no" defaul="0" />
    <bm id="bm2_13" size="2" name="waterPass" remark="?" type="Byte" function="no" defaul="0" />
    <bm id="bm2_14" size="2" name="landPass" remark="?" type="Byte" function="no" defaul="0" />
    <bm id="bm2_15" size="2" name="bmUnknown14" remark="?" type="Byte" function="no" defaul="0" />
    <bm id="bm2_16" size="2" name="bmUnknown15" remark="?" type="Byte" function="no" defaul="0" />
    </bm2>
    <bm3 id="bm3" name="regionData" ifCycle="true"  Count="bm0_23" remark="省规划 2" >
    <bm id="bm3_1" size="4" name="bpProvince"  remark="省区" type="Short" function="no" defaul="0" />
    </bm3>
    <bm4 id="bm4" name="belongData" ifCycle="true"  Count="bm0_23" remark="军团归属 1" >
    <bm id="bm4_1" size="2" name="bbBelong"  remark="id" type="Byte" function="id"/>
    </bm4>
    <bm5 id="bm5" name="buildData" ifCycle="true"  Count="bm0_8" remark="地块 32" >
    <bm id="bm5_1" size="4" name="buPosition"  remark="坐标" type="Short" function="no" defaul="0" />
    <bm id="bm5_2" size="4" name="buAreaid" remark="名称" type="Short" function="no" defaul="0" />
    <bm id="bm5_3" size="2" name="buType" remark="类型" type="Byte" function="no" defaul="0" />
    <bm id="bm5_4" size="2" name="buStyle" remark="外观 1↙2↘3↗4↖" type="Byte" function="no" defaul="0" />
    <bm id="bm5_5" size="2" name="buCityFeature" remark="?" type="Byte" function="no" defaul="0" />
    <bm id="bm5_6" size="2" name="capital" remark="首都外观" type="Byte" function="no" defaul="0" />
    <bm id="bm5_7" size="4" name="buRewardType" remark="奖励类型(宝物或装备id)" type="Short" function="no" defaul="0" />
    <bm id="bm5_8" size="4" name="buRewardNum" remark="奖励数量" type="Short" function="no" defaul="0" />
    <bm id="bm5_9" size="2" name="buUnknown09" remark="轻视度" type="Byte" function="no" defaul="0" />
    <bm id="bm5_10" size="2" name="buVictoryPoint" remark="据点(0-2)" type="Byte" function="no" defaul="0" />
    <bm id="bm5_11" size="2" name="buEvent" remark="事件" type="Byte" function="no" defaul="0" />
    <bm id="bm5_12" size="2" name="buUnknown12" remark="?" type="Byte" function="no" defaul="0" />
    <bm id="bm5_13" size="2" name="buUnknown13" remark="?" type="Byte" function="no" defaul="0" />
    <bm id="bm5_14" size="2" name="buUnknown14" remark="?" type="Byte" function="no" defaul="0" />
    <bm id="bm5_15" size="2" name="buUnknown15" remark="?" type="Byte" function="no" defaul="0" />
    <bm id="bm5_16" size="2" name="buUnknown16" remark="运输船?" type="Byte" function="no" defaul="0" />
    <bm id="bm5_17" size="2" name="buFireLevel" remark="火焰等级" type="Byte" function="no" defaul="0" />
    <bm id="bm5_18" size="2" name="buFireTime" remark="火焰时间" type="Byte" function="no" defaul="0" />
    <bm id="bm5_19" size="2" name="buAirDefense" remark="防空" type="Byte" function="no" defaul="0" />
    <bm id="bm5_20" size="2" name="buRadar" remark="防空雷达" type="Byte" function="no" defaul="0" />
    <bm id="bm5_21" size="2" name="buFactoryLv" remark="工业" type="Byte" function="no" defaul="0" />
    <bm id="bm5_22" size="2" name="buResearchLv" remark="科技" type="Byte" function="no" defaul="0" />
    <bm id="bm5_23" size="2" name="buHospitalLv" remark="医院" type="Byte" function="no" defaul="0" />
    <bm id="bm5_24" size="2" name="buAirportLv" remark="机场" type="Byte" function="no" defaul="0" />
    <bm id="bm5_25" size="2" name="buMissileLv" remark="导弹" type="Byte" function="no" defaul="0" />
    <bm id="bm5_26" size="2" name="buNuclearLv" remark="核弹" type="Byte" function="no" defaul="0" />
    <bm id="bm5_27" size="2" name="buUnknown27" remark="?" type="Byte" function="no" defaul="0" />
    <bm id="bm5_28" size="2" name="buUnknown28" remark="?" type="Byte" function="no" defaul="0" />
    </bm5>
    <bm6 id="bm6" name="armyData" ifCycle="true"  Count="bm0_9" remark="兵种 48" >
    <bm id="bm6_1" size="4" name="baPosition"  remark="坐标" type="Short" function="no" defaul="0" />1
    <bm id="bm6_2" size="2" name="baType" remark="兵种" type="Byte" function="no" defaul="0" />1
    <bm id="bm6_3" size="2" name="baLevel" remark="部队等级" type="Byte" function="no" defaul="0" />1
    <bm id="bm6_4" size="2" name="baNum" remark="编队数" type="Byte" function="no" defaul="0" />1
    <bm id="bm6_5" size="2" name="baFace" remark="方向" type="Byte" function="no" defaul="0" />1
    <bm id="bm6_6" size="2" name="baMobility" remark="移动力" type="Byte" function="no" defaul="0" />
    <bm id="bm6_7" size="2" name="baUnknown07" remark="运输船?" type="Byte" function="no" defaul="0" />
    <bm id="bm6_8" size="4" name="baArmyExp" remark="兵种经验" type="Short" function="no" defaul="0" />
    <bm id="bm6_9" size="4" name="baHpPercent" remark="血量加成" type="Short" function="no" defaul="0" />1
    <bm id="bm6_10" size="4" name="baHpNow" remark="当前血量" type="Short" function="no" defaul="0" />
    <bm id="bm6_11" size="4" name="baHpMax" remark="总血量" type="Short" function="no" defaul="0" />
    <bm id="bm6_12" size="4" name="baGeneralId" remark="将领编号" type="Short" function="no" defaul="0" />1
    <bm id="bm6_13" size="2" name="baGeneralLevel" remark="将领军衔" type="Byte" function="no" defaul="0" />1
    <bm id="bm6_14" size="2" name="baGeneralColor" remark="将领品质" type="Byte" function="no" defaul="0" />1
    <bm id="bm6_15" size="2" name="baMedalId1" remark="勋章一" type="Byte" function="no" defaul="0" />
    <bm id="bm6_16" size="2" name="baMedalId2" remark="勋章二" type="Byte" function="no" defaul="0" />
    <bm id="bm6_17" size="2" name="baMedalId3" remark="勋章三" type="Byte" function="no" defaul="0" />
    <bm id="bm6_18" size="2" name="baSkillLevel1" remark="技能等级1" type="Byte" function="no" defaul="0" />
    <bm id="bm6_19" size="2" name="baSkillLevel2" remark="技能等级2" type="Byte" function="no" defaul="0" />
    <bm id="bm6_20" size="2" name="baSkillLevel3" remark="技能等级3" type="Byte" function="no" defaul="0" />
    <bm id="bm6_21" size="2" name="baSkillLevel4" remark="技能等级4" type="Byte" function="no" defaul="0" />
    <bm id="bm6_22" size="2" name="baSkillLevel5" remark="技能等级5" type="Byte" function="no" defaul="0" />
    <bm id="bm6_23" size="2" name="baVP" remark="VP" type="Byte" function="no" defaul="0" />
    <bm id="bm6_24" size="2" name="baAI" remark="AI 初始行动策略 2行动 3待机 bm6_28为待机回合" type="Byte" function="no" defaul="0" />
    <bm id="bm6_25" size="2" name="baUnknown25" remark="运输船" type="Byte" function="no" defaul="0 1? 2禁止下海" />
    <bm id="bm6_26" size="2" name="baUnknown26" remark="轻视度" type="Byte" function="no" defaul="0" />
    <bm id="bm6_27" size="4" name="baMovePoint" remark="移动目标" type="Short" function="no" defaul="0" />
    <bm id="bm6_28" size="2" name="baUnknown28" remark="行为" type="Byte" function="no" defaul="0" />
    <bm id="bm6_29" size="2" name="baUnknown29" remark="?" type="Byte" function="no" defaul="0" />
    <bm id="bm6_30" size="8" name="baZeros" remark="?" type="Integer" function="no" defaul="0" />
    <bm id="bm6_31" size="2" name="baMorale" remark="士气" type="Byte" function="no" defaul="0" />
    <bm id="bm6_32" size="2" name="baMoraleTime" remark="士气时间" type="Byte" function="no" defaul="0" />
    <bm id="bm6_33" size="2" name="baEvent" remark="事件" type="Byte" function="no" defaul="0" />
    <bm id="bm6_34" size="2" name="baUnknown34" remark="?" type="Byte" function="no" defaul="0" />
    <bm id="bm6_35" size="8" name="baTrigger" remark="二次行动策略  2行动 3待机" type="Integer" function="no" defaul="0" />
    </bm6>
    <bm7 id="bm7" name="trapData" ifCycle="true"  Count="bm0_27" remark="陷阱 12" >
    <bm id="bm7_1" size="4" name="bmiPosition"  remark="地块坐标" type="Short" function="no" defaul="0" />
    <bm id="bm7_2" size="4" name="bmiLegion" remark="所属军团" type="Short" function="no" defaul="0" />
    <bm id="bm7_3" size="4" name="bmiMinesLv" remark="陷阱等级" type="Short" function="no" defaul="0" />
    <bm id="bm7_4" size="4" name="bmiMinesHp" remark="陷阱血量" type="Short" function="no" defaul="0" />
    <bm id="bm7_5" size="8" name="bmiZeros" remark="?" type="Integer" function="no" defaul="0" />
    </bm7>
    <bm8 id="bm8" name="planData" ifCycle="true"  Count="bm0_10" remark="方案 16" >
    <bm id="bm8_1" size="8" name="bhId"  remark="id" type="Integer" function="no" defaul="0" />
    <bm id="bm8_2" size="8" name="bhType" remark="类型" type="Integer" function="no" defaul="0" />
    <bm id="bm8_3" size="8" name="bhTime" remark="时间" type="Integer" function="no" defaul="0" />
    <bm id="bm8_4" size="8" name="bhValue" remark="目标值" type="Integer" function="no" defaul="0" />
    </bm8>
    <bm9 id="bm9" name="weatherData" ifCycle="true"  Count="bm0_12" remark="天气  16" >
    <bm id="bm9_1" size="8" name="bwId"  remark="天气编号"  type="Integer" function="no" defaul="0" />
    <bm id="bm9_2" size="8" name="bwUnknown02" remark="天气类型 (01下雨  02暴雨  03下雪)" type="Integer" function="no" defaul="0" />
    <bm id="bm9_3" size="8" name="bwStartTime" remark="触发回合" type="Integer" function="no" defaul="0" />
    <bm id="bm9_4" size="8" name="bwLength" remark="持续回合" type="Integer" function="no" defaul="0" />
    </bm9>
    <bm10 id="bm10" name="eventData" ifCycle="true"  Count="bm0_11" remark="事件 44" >
    <bm id="bm10_1" size="8" name="beId"  remark="序号 1开始" type="Integer" function="no" defaul="0" />
    <bm id="bm10_2" size="8" name="beNextid" remark="伴生ID" type="Integer" function="no" defaul="0" />
    <bm id="bm10_3" size="8" name="beTrigger" remark="触发条件,00建筑触发01部队触发02回合触发04连带触发" type="Integer" function="no" defaul="0" />
    <bm id="bm10_4" size="8" name="beType" remark="类型,00士气上升01下降02大降03混乱04无效果07阵营变化" type="Integer" function="no" defaul="0" />
    <bm id="bm10_5" size="8" name="beUnknown05" remark="?" type="Integer" function="no" defaul="0" />
    <bm id="bm10_6" size="8" name="beLegion" remark="军团(顺序)" type="Integer" function="no" defaul="0" />
    <bm id="bm10_7" size="8" name="beValue" remark="若触发事件07,则这里填变换后的阵营" type="Integer" function="no" defaul="0" />
    <bm id="bm10_8" size="8" name="beZero" remark="?" type="Integer" function="no" defaul="0" />
    <bm id="bm10_9" size="8" name="beTime" remark="触发回合" type="Integer" function="no" defaul="0" />
    <bm id="bm10_10" size="8" name="beDialogue" remark="对话代码" type="Integer" function="no" defaul="0" />
    <bm id="bm10_11" size="8" name="beEnding" remark="?" type="?" function="no" defaul="00cccccc" />
    </bm10>
    <bm11 id="bm11" name="reliefData" ifCycle="true"  Count="bm0_16" remark="援军 80" >
    <bm id="bm11_1" size="8" name="bsaPosition"  remark="坐标" type="Integer" function="no" defaul="0" />
    <bm id="bm11_2" size="8" name="bsaType" remark="兵种" type="Integer" function="no" defaul="0" />
    <bm id="bm11_3" size="8" name="bsaLevel" remark="等级" type="Integer" function="no" defaul="0" />
    <bm id="bm11_4" size="8" name="bsanum" remark="编制" type="Integer" function="no" defaul="0" />
    <bm id="bm11_5" size="8" name="bsaShip" remark="运输船" type="Integer" function="no" defaul="0" />
    <bm id="bm11_6" size="8" name="bsaFace" remark="朝向" type="Integer" function="no" defaul="0" />
    <bm id="bm11_7" size="8" name="bsaUnknown07" remark="?" type="Integer" function="no" defaul="0" />
    <bm id="bm11_8" size="8" name="bsaGeneralId" remark="将领" type="Integer" function="no" defaul="0" />
    <bm id="bm11_9" size="8" name="bsaGeneralLevel" remark="军衔" type="Integer" function="no" defaul="0" />
    <bm id="bm11_10" size="8" name="bsaGeneralColor" remark="爵位" type="Integer" function="no" defaul="0" />
    <bm id="bm11_11" size="8" name="bsaSkillLevel1" remark="技能等级1" type="Integer" function="no" defaul="0" />
    <bm id="bm11_12" size="8" name="bsaSkillLevel2" remark="技能等级2" type="Integer" function="no" defaul="0" />
    <bm id="bm11_13" size="8" name="bsaSkillLevel3" remark="技能等级3" type="Integer" function="no" defaul="0" />
    <bm id="bm11_14" size="8" name="bsaSkillLevel4" remark="技能等级4" type="Integer" function="no" defaul="0" />
    <bm id="bm11_15" size="8" name="bsaSkillLevel5" remark="技能等级5" type="Integer" function="no" defaul="0" />
    <bm id="bm11_16" size="8" name="bsaMedalId1" remark="勋章一" type="Integer" function="no" defaul="0" />
    <bm id="bm11_17" size="8" name="bsaMedalId2" remark="勋章二" type="Integer" function="no" defaul="0" />
    <bm id="bm11_18" size="8" name="bsaMedalId3" remark="勋章三" type="Integer" function="no" defaul="0" />
    <bm id="bm11_19" size="8" name="bsaLegion" remark="军团" type="Integer" function="no" defaul="0" />
    <bm id="bm11_20" size="8" name="bsaTime" remark="回合" type="Integer" function="no" defaul="0" />
    </bm11>
    <bm12 id="bm12" name="airData" ifCycle="true"  Count="bm0_17" remark="空袭 20" >
    <bm id="bm12_1" size="8" name="baaPosition"  remark="坐标" type="Integer" function="no" defaul="0" />
    <bm id="bm12_2" size="8" name="baaType" remark="兵种" type="Integer" function="no" defaul="0" />
    <bm id="bm12_3" size="8" name="baaNuclear" remark="核弹" type="Integer" function="no" defaul="0" />
    <bm id="bm12_4" size="8" name="baaLegion" remark="军团" type="Integer" function="no" defaul="0" />
    <bm id="bm12_5" size="8" name="baaTime" remark="回合" type="Integer" function="no" defaul="0" />
    </bm12>
    <bm13 id="bm13" name="placeAData" ifCycle="true"  Count="bm0_18" remark="兵种放置A 8" >
    <bm id="bm13_1" size="4" name="bsPosition"  remark="坐标" type="Short" function="no" defaul="65535" />
    <bm id="bm13_2" size="4" name="bsUnknown02" remark="?" type="Short" function="no" defaul="0" />
    <bm id="bm13_3" size="2" name="bsFace" remark="方向" type="Byte" function="no" defaul="0" />
    <bm id="bm13_4" size="2" name="bsId" remark="序号" type="Byte" function="no" defaul="0" />
    <bm id="bm13_5" size="2" name="bsShip" remark="运输船" type="Byte" function="no" defaul="0" />
    <bm id="bm13_6" size="2" name="bsUnknown06" remark="?" type="Byte" function="no" defaul="0" />
    </bm13>
    <bm14 id="bm14" name="placeBData" ifCycle="true"  Count="bm0_19" remark="兵种放置B 8" >
    <bm id="bm14_1" size="4" name="bsPosition"  remark="坐标" type="Short" function="no" defaul="0" />
    <bm id="bm14_2" size="4" name="bsUnknown02" remark="?" type="Short" function="no" defaul="0" />
    <bm id="bm14_3" size="2" name="bsFace" remark="方向" type="Byte" function="no" defaul="0" />
    <bm id="bm14_4" size="2" name="bsId" remark="序号" type="Byte" function="no" defaul="0" />
    <bm id="bm14_5" size="2" name="bsShip" remark="运输船" type="Byte" function="no" defaul="0" />
    <bm id="bm14_6" size="2" name="bsUnknown06" remark="?" type="Byte" function="no" defaul="0" />
    </bm14>
     <bm15 id="bm15" name="capitalData" ifCycle="true"  Count="bm0_20" remark="首都 4" >
    <bm id="bm15_1" size="4" name="bfPosition"  remark="地块坐标" type="Short" function="no" defaul="0" />
    <bm id="bm15_2" size="4" name="bfUnknown02" remark="?" type="Short" function="no" defaul="0" />
    </bm15>
    <bm16 id="bm16" name="strategicData" ifCycle="true"  Count="bm0_29" remark="战略建设 16" >
    <bm id="bm16_1" size="8" name="bstLegion"  remark="军团序号" type="Integer" function="no" defaul="0" />
    <bm id="bm16_2" size="8" name="bstUnknown02" remark="未知" type="Integer" function="no" defaul="0" />
    <bm id="bm16_3" size="8" name="bstTime" remark="回合" type="Integer" function="no" defaul="0" />
    <bm id="bm16_4" size="8" name="bstValue" remark="目标值" type="Integer" function="no" defaul="0" />
    </bm16>
    <bm17 id="bm17" name="airSData" ifCycle="true"  Count="bm0_32" remark="空中支援 16" >
    <bm id="bm17_1" size="8" name="bnaType"  remark="空军序号" type="Integer" function="no" defaul="21" />
    <bm id="bm17_2" size="8" name="bnaNuclear" remark="弹药类型" type="Integer" function="no" defaul="0" />
    <bm id="bm17_3" size="8" name="bnaLegion" remark="所属军团" type="Integer" function="no" defaul="1" />
    <bm id="bm17_4" size="8" name="bnaTime" remark="触发回合" type="Integer" function="no" defaul="599" />
    </bm17><!-- -->
</Files>
rule_wc4_btl.xml

代码:

  1     public static void copyClassInfoByRule(String rule, String name, boolean ifET) {
  2         StringBuffer sb=new StringBuffer();
  3         
  4         String btlSetTrans="";
  5         if(ifET) {
  6             btlSetTrans="+\"\"";
  7         }
  8         name = ComUtil.UpperInitial(name);
  9         byte[] rsbt = null;
 10         BTLDAO btl = new BTLDAO();
 11         BtlModule0 bi;
 12         StringBuilder buf = new StringBuilder();
 13         String cutStr = "";
 14         int bufTag = 0;
 15         int cutSumCt = 1;//总循环次数
 16         int mapW = 0, mapH = 0, i, j, k;
 17         JSONObject row = null;
 18         List<DefRule> rs;
 19         String trans;
 20         { //重复读取所有基本信息
 21             String[] cutStrs = new String[] { "bm0", "bm1", "bm2", "bm3", "bm4", "bm5", "bm6", "bm7", "bm8", "bm9", "bm10", "bm11", "bm12", "bm13", "bm14", "bm15", "bm16", "bm17", "bm18", "bm19", "bm20" };
 22             String[] cutStrs2 = new String[] { "BtlModule0", "BtlModule1", "BtlModule2", "BtlModule3", "BtlModule4", "BtlModule5", "BtlModule6", "BtlModule7", "BtlModule8", "BtlModule9", "BtlModule10", "BtlModule11", "BtlModule12", "BtlModule13", "BtlModule14", "BtlModule15", "BtlModule16", "BtlModule17", "BtlModule18", "BtlModule19", "BtlModule20" };
 23             String uName, lName;
 24             
 25             sb.append("public class " + name + " {");
 26             for (i = 0; i < cutStrs.length; i++) {
 27                 try {
 28                     row = getInfoByRootName(rule, cutStrs[i]);
 29                     if (row != null) {
 30                         rs = getDefRuleInfosByRow(row);
 31                         if (i == 0) {
 32                             sb.append("\r\npublic " + ComUtil.UpperInitial(row.getString("name")) + " " + ComUtil.LowerInitial(row.getString("name")) + ";");
 33                         } else {
 34                             sb.append("\r\npublic List<" + ComUtil.UpperInitial(row.getString("name")) + "> " + ComUtil.LowerInitial(row.getString("name")) + "s;");
 35                         }
 36                     }
 37                     
 38                 } catch (DocumentException e) {
 39                     e.printStackTrace();
 40                 }
 41             }
 42             sb.append("\r\npublic void init" + name + "() {");
 43             
 44             
 45             for (i = 0; i < cutStrs.length; i++) {
 46                 try {
 47                     row = getInfoByRootName(rule, cutStrs[i]);
 48                     if (row != null) {
 49                         rs = getDefRuleInfosByRow(row);
 50                         if (i == 0) {
 51                             sb.append("\r\n "+ComUtil.LowerInitial(row.getString("name"))+" = new " + ComUtil.UpperInitial(row.getString("name")) +  "() ;");
 52                         } else {
 53                             sb.append("\r\n "+ComUtil.LowerInitial(row.getString("name"))+"s = new ArrayList<" + ComUtil.UpperInitial(row.getString("name")) + ">() " +  ";");
 54                         }
 55                     }
 56                     
 57                 } catch (DocumentException e) {
 58                     e.printStackTrace();
 59                 }
 60             }
 61             sb.append("\r\n }");
 62             
 63             
 64             /*
 65              * public Test(BTLDAO btl) { setMasterData(btl.getBm0()); }
 66              */
 67             sb.append("\r\npublic " + name + "( BTLDAO btl) {");
 68             
 69             for (i = 0; i < cutStrs.length; i++) {
 70                 try {
 71                     row = getInfoByRootName(rule, cutStrs[i]);
 72                     if (row != null) {
 73                         rs = getDefRuleInfosByRow(row);
 74                         sb.append("\r\n"+ComUtil.getSetMethodName(row.getString("name")) + "(btl." + ComUtil.getGetMethodName(cutStrs[i]) + "());");
 75                     }
 76                     
 77                 } catch (DocumentException e) {
 78                     e.printStackTrace();
 79                 }
 80             }
 81             
 82             sb.append("\r\n }");
 83             
 84             for (i = 0; i < cutStrs.length; i++) {
 85                 try {
 86                     row = getInfoByRootName(rule, cutStrs[i]);
 87                     
 88                     if (row != null) {
 89                         uName = ComUtil.UpperInitial(row.getString("name"));
 90                         lName = ComUtil.LowerInitial(row.getString("name"));
 91                         rs = getDefRuleInfosByRow(row);
 92                         
 93                         //生成变量
 94                         /* */ 
 95 
 96                         sb.append("\r\n//" +(row.getString("remark")) );
 97                         sb.append("\r\npublic class " + ComUtil.UpperInitial(row.getString("name")) + " {");
 98                         for (j = 0; j < rs.size(); j++) {
 99                             String type = rs.get(j).getType().equals("?") ? "String" : rs.get(j).getType();
100                             
101                             if(ifET) {
102                                 if (type.equals("String") || type.equals("?")) {
103                                     type = "String";
104                                 } else if (type.equals("Single")) {
105                                     type = "float";
106                                 } else {
107                                     type = "int";
108                                 } 
109                             }else {
110                                 type = "int";
111                             }
112                             
113                             sb.append("\r\nprivate " + type + " " + rs.get(j).getName() + ";//"+rs.get(j).getRemark());
114                             
115                             sb.append("\r\npublic " + type + " " + ComUtil.getGetMethodName(rs.get(j).getName()) + "(){ return " + rs.get(j).getName() + ";}");
116                             sb.append("\r\npublic void " + ComUtil.getSetMethodName(rs.get(j).getName()) + "(" + type + " " + rs.get(j).getName() + "){ this." + rs.get(j).getName() + "=" + rs.get(j).getName() + ";}");
117                         }
118                         sb.append("\r\n }");
119                         
120                         /*
121                          * private void setMasterData(BtlModule0 bm0) {
122                          * this.masterData.biAirportAirstrikesNum=0; }
123                          */
124                         if (i == 0) {
125                             
126                             sb.append("\r\npublic void set" + uName + "(" + cutStrs2[i] + " " + cutStrs[i] + "){");
127                             
128                             sb.append("\r\nif (" + lName + "==null){" + lName + "=new " + uName + "();}");
129                             
130                             for (j = 0; j < rs.size(); j++) {
131                                 String type = rs.get(j).getType().equals("?") ? "String" : rs.get(j).getType();
132                                 // type = type.equals("Single") ? "float" : type;
133                                 if(ifET) {
134                                     if (type.equals("String") || type.equals("?")) {
135                                         type = "String";
136                                     } else if (type.equals("Single")) {
137                                         type = "float";
138                                     } else {
139                                         type = "int";
140                                     } 
141                                 }else {
142                                     type = "int";
143                                 }
144                                 
145                                 if(ifET) {
146                                     sb.append("\r\n"+lName + "." + ComUtil.getSetMethodName(rs.get(j).getName()) + "(" + transValue(type, cutStrs[i] + "." + ComUtil.getGetMethodName(rs.get(j).getId()) + "()") + ");");
147                                       
148                                 }else {
149                                     sb.append("\r\n"+lName + "." + ComUtil.getSetMethodName(rs.get(j).getName()) + "(" +  cutStrs[i] + "." + ComUtil.getGetMethodName(rs.get(j).getId()) + "()" + ");");
150                                      
151                                 }
152                                 
153                                 
154                                 // sb.append("\r\n");
155                             }
156                             sb.append("\r\n }");
157                             
158                         } else {
159                             sb.append("\r\npublic void set" + uName + "(List<" + cutStrs2[i] + "> " + cutStrs[i] + "s){");
160                             
161                             sb.append("\r\nif (" + lName + "s==null){" + lName + "s=new ArrayList<" + uName + ">();}else{this." + lName + "s.clear();" + "}");
162                             sb.append("\r\n if("+ cutStrs[i]+"s ==null){return ;}");
163                             
164                             
165                             sb.append("\r\nfor(" + cutStrs2[i] + " " + cutStrs[i] + ":" + cutStrs[i] + "s) {");
166                             sb.append("\r\n"+uName + " " + lName + "=new " + uName + "();");
167                             for (j = 0; j < rs.size(); j++) {
168                                 String type = rs.get(j).getType().equals("?") ? "String" : rs.get(j).getType();
169                                 // type = type.equals("Single") ? "float" : type;
170                                 
171                                 if(ifET) {
172                                     sb.append("\r\n"+lName + "." + ComUtil.getSetMethodName(rs.get(j).getName()) + "(" + transValue(type, cutStrs[i] + "." + ComUtil.getGetMethodName(rs.get(j).getId()) + "()") + ");");
173                                         
174                                 }else {
175                                     sb.append("\r\n"+lName + "." + ComUtil.getSetMethodName(rs.get(j).getName()) + "(" +  cutStrs[i] + "." + ComUtil.getGetMethodName(rs.get(j).getId()) + "()" + ");");
176                                     
177                                 }
178                                 
179                                 // sb.append("\r\n");
180                             }
181                             sb.append("\r\nthis." + lName + "s.add(" + lName + ");");
182                             sb.append("\r\n }");
183                             
184                             sb.append("\r\n }");
185                         }
186                         
187                         //bm转变量 TODO
188                         /* public get */
189                         
190                         //变量转bm TODO
191                         
192                     }
193                     
194                 } catch (DocumentException e) {
195                     // TODO Auto-generated catch block
196                     e.printStackTrace();
197                 }
198                 
199             }
200             
201             /*
202              * public BTLDAO getBTL() { BTLDAO btl=new BTLDAO(); initBm1(btl);
203              * 
204              * return btl; }
205              */
206             
207             sb.append("\r\n public BTLDAO getBTL() { BTLDAO btl=new BTLDAO();btl.init();");
208             for (i = 0; i < cutStrs.length; i++) {
209                 try {
210                     row = getInfoByRootName(rule, cutStrs[i]);
211                 } catch (DocumentException e) {
212                     // TODO Auto-generated catch block
213                     e.printStackTrace();
214                 }
215                 if (row != null) {
216                 sb.append("\r\ninit" + ComUtil.UpperInitial(cutStrs[i]) + "(btl);");
217                 }
218             }
219             sb.append("\r\n  return btl;}");
220             
221             /*private void initBm1(BTLDAO btl){
222                 
223             }*/
224             for (i = 0; i < cutStrs.length; i++) {
225                 try {
226                     row = getInfoByRootName(rule, cutStrs[i]);
227                     if (row != null) {
228                         uName = ComUtil.UpperInitial(row.getString("name"));
229                         lName = ComUtil.LowerInitial(row.getString("name"));
230                         rs = getDefRuleInfosByRow(row);
231                 if(i==0) {
232                     sb.append("\r\nprivate void init" + ComUtil.UpperInitial(cutStrs[i]) + "(BTLDAO btl){");
233                     /*private void initBm0(BTLDAO btl){
234                         btl.getBm0().setBm0_1("");
235                      }*/
236                     
237                     for (j = 0; j < rs.size(); j++) {
238                         sb.append("\r\n btl.get"+ComUtil.UpperInitial(cutStrs[i])+"().set"+ComUtil.UpperInitial(rs.get(j).getId())
239                         +"("+lName+"."+rs.get(j).getName()+btlSetTrans+");");
240                      }
241                     sb.append("\r\n }");
242                 }else {
243                     sb.append("\r\nprivate void init" + ComUtil.UpperInitial(cutStrs[i]) + "(BTLDAO btl){");
244                     /*private void initBm1(BTLDAO btl){
245                         for(LegionData legionData: legionDatas) {
246                             BtlModule1 bm1=new BtlModule1();
247                             bm1.setBm1_1(legionData.blUnknown129);
248                             btl.getBm1().add(bm1);
249                         }
250                      }*/
251                     sb.append("\r\n if("+lName+"s ==null){return ;}");
252                     sb.append("\r\n for("+uName+" "+lName+":"+lName+"s){");
253                     sb.append("\r\n"+cutStrs2[i]+" "+cutStrs[i]+"=new "+cutStrs2[i]+"();" );
254                     for (j = 0; j < rs.size(); j++) {
255                         sb.append("\r\n"+cutStrs[i]+".set"+ComUtil.UpperInitial(rs.get(j).getId())
256                         +"("+lName+"."+rs.get(j).getName()+btlSetTrans+");");
257                      }
258                     
259                     
260                     
261                     sb.append("\r\nbtl.get"+ComUtil.UpperInitial(cutStrs[i])+"().add("+cutStrs[i]+");");
262   
263                     sb.append("\r\n }");
264                     
265                     sb.append("\r\n }");
266                     
267                   //  sb.append("\r\ninit" + ComUtil.UpperInitial(cutStrs[i]) + "(btl)");
268                 }
269                     }
270                 } catch (DocumentException e) {
271                     // TODO Auto-generated catch block
272                     e.printStackTrace();
273                 }
274             }
275             
276             
277             sb.append("\r\n }");
278             
279             ComUtil.setSysClipboardText(sb.toString());
280             JOptionPane.showMessageDialog(null,"内容已复制,请右键粘贴","提示",  JOptionPane.INFORMATION_MESSAGE);
281         }
282     }
283     
根据规则生成相关类

效果:

 1 public class Wc4Btl {
 2 public MasterData masterData;
 3 public List<TerrainData> terrainDatas;
 4 public void initWc4Btl() {
 5  masterData = new MasterData() ;
 6  terrainDatas = new ArrayList<TerrainData>() ;
 7  }
 8 public Wc4Btl( BTLDAO btl) {
 9 setMasterData(btl.getBm0());
10 setTerrainData(btl.getBm1());
11  }
12 //2
13 public class MasterData {
14 private int mapW;//3
15 public int getMapW(){ return mapW;}
16 public void setMapW(int mapW){ this.mapW=mapW;}
17 private int mapH;//4
18 public int getMapH(){ return mapH;}
19 public void setMapH(int mapH){ this.mapH=mapH;}
20  }
21 public void setMasterData(BtlModule0 bm0){
22 if (masterData==null){masterData=new MasterData();}
23 masterData.setMapW(Integer.parseInt(bm0.getBm0_1()));
24 masterData.setMapH(Integer.parseInt(bm0.getBm0_2()));
25  }
26 //1
27 public class TerrainData {
28 private int bmTerrain1Group;//
29 public int getBmTerrain1Group(){ return bmTerrain1Group;}
30 public void setBmTerrain1Group(int bmTerrain1Group){ this.bmTerrain1Group=bmTerrain1Group;}
31 private int bmTerrain1Id;//
32 public int getBmTerrain1Id(){ return bmTerrain1Id;}
33 public void setBmTerrain1Id(int bmTerrain1Id){ this.bmTerrain1Id=bmTerrain1Id;}
34  }
35 public void setTerrainData(List<BtlModule1> bm1s){
36 if (terrainDatas==null){terrainDatas=new ArrayList<TerrainData>();}else{this.terrainDatas.clear();}
37  if(bm1s ==null){return ;}
38 for(BtlModule1 bm1:bm1s) {
39 TerrainData terrainData=new TerrainData();
40 terrainData.setBmTerrain1Group(Integer.parseInt(bm1.getBm1_1()));
41 terrainData.setBmTerrain1Id(Integer.parseInt(bm1.getBm1_2()));
42 this.terrainDatas.add(terrainData);
43  }
44  }
45  public BTLDAO getBTL() { BTLDAO btl=new BTLDAO();btl.init();
46 initBm0(btl);
47 initBm1(btl);
48   return btl;}
49 private void initBm0(BTLDAO btl){
50  btl.getBm0().setBm0_1(masterData.mapW+"");
51  btl.getBm0().setBm0_2(masterData.mapH+"");
52  }
53 private void initBm1(BTLDAO btl){
54  if(terrainDatas ==null){return ;}
55  for(TerrainData terrainData:terrainDatas){
56 BtlModule1 bm1=new BtlModule1();
57 bm1.setBm1_1(terrainData.bmTerrain1Group+"");
58 bm1.setBm1_2(terrainData.bmTerrain1Id+"");
59 btl.getBm1().add(bm1);
60  }
61  }
62  }
根据规则生成的文本

把原来的规则映射类转换为 正式类...可惜我想到的太迟了....mmp.....然后我应用到第二个项目上了,因为第一个项目没有用这种方法

每次测试都得对着规则看内容.然而因为8月因为某个事故我停工了一段时间,然后我忘了具体代码的含义,每一次做都得翻规则..导致第一个项目断断续续

mmp,希望第二个项目能弄好

 

 

--------------------------------更新---------------------------------------------------

更新下规则生成类,增加直接生成libgx使用的读取和保存而不再通过转换层,以提高效率

public static void copyClassInfoByRule(String rule, String name, boolean ifET) {
        StringBuffer sb=new StringBuffer();
        
        String btlSetTrans="";
        if(ifET) {
            btlSetTrans="+\"\"";
        }
        name = ComUtil.UpperInitial(name);
        byte[] rsbt = null;
        BTLDAO btl = new BTLDAO();
        BtlModule0 bi;
        StringBuilder buf = new StringBuilder();
        String cutStr = "";
        int bufTag = 0;
        int cutSumCt = 1;//总循环次数
        int mapW = 0, mapH = 0, i, j, k;
        JSONObject row = null;
        List<DefRule> rs;
        String trans;
        { //重复读取所有基本信息
            String[] cutStrs = new String[] { "bm0", "bm1", "bm2", "bm3", "bm4", "bm5", "bm6", "bm7", "bm8", "bm9", "bm10", "bm11", "bm12", "bm13", "bm14", "bm15", "bm16", "bm17", "bm18", "bm19", "bm20" };
            String[] cutStrs2 = new String[] { "BtlModule0", "BtlModule1", "BtlModule2", "BtlModule3", "BtlModule4", "BtlModule5", "BtlModule6", "BtlModule7", "BtlModule8", "BtlModule9", "BtlModule10", "BtlModule11", "BtlModule12", "BtlModule13", "BtlModule14", "BtlModule15", "BtlModule16", "BtlModule17", "BtlModule18", "BtlModule19", "BtlModule20" };
            String uName, lName;
            
            sb.append("public class " + name + " {");
            for (i = 0; i < cutStrs.length; i++) {
                try {
                    row = getInfoByRootName(rule, cutStrs[i]);
                    if (row != null) {
                        rs = getDefRuleInfosByRow(row);
                        if (i == 0) {
                            sb.append("\r\npublic " + ComUtil.UpperInitial(row.getString("name")) + " " + ComUtil.LowerInitial(row.getString("name")) + ";");
                        } else {
                            sb.append("\r\npublic Array<" + ComUtil.UpperInitial(row.getString("name")) + "> " + ComUtil.LowerInitial(row.getString("name")) + "s;");
                        }
                    }
                    
                } catch (DocumentException e) {
                    e.printStackTrace();
                }
            }
            sb.append("\r\npublic void init" + name + "() {");
            
            
            for (i = 0; i < cutStrs.length; i++) {
                try {
                    row = getInfoByRootName(rule, cutStrs[i]);
                    if (row != null) {
                        rs = getDefRuleInfosByRow(row);
                        if (i == 0) {
                            sb.append("\r\n "+ComUtil.LowerInitial(row.getString("name"))+" = new " + ComUtil.UpperInitial(row.getString("name")) +  "() ;");
                        } else {
                            sb.append("\r\n "+ComUtil.LowerInitial(row.getString("name"))+"s = new Array<" + ComUtil.UpperInitial(row.getString("name")) + ">() " +  ";");
                        }
                    }
                    
                } catch (DocumentException e) {
                    e.printStackTrace();
                }
            }
            sb.append("\r\n }");
            
            
            /*
             * public Test(BTLDAO btl) { setMasterData(btl.getBm0()); }
             */
            sb.append("\r\npublic " + name + "( BTLDAO btl) {");
            
            for (i = 0; i < cutStrs.length; i++) {
                try {
                    row = getInfoByRootName(rule, cutStrs[i]);
                    if (row != null) {
                        rs = getDefRuleInfosByRow(row);
                        sb.append("\r\n"+ComUtil.getSetMethodName(row.getString("name")) + "(btl." + ComUtil.getGetMethodName(cutStrs[i]) + "());");
                    }
                    
                } catch (DocumentException e) {
                    e.printStackTrace();
                }
            }
            
            sb.append("\r\n }");
            
            for (i = 0; i < cutStrs.length; i++) {
                try {
                    row = getInfoByRootName(rule, cutStrs[i]);
                    
                    if (row != null) {
                        uName = ComUtil.UpperInitial(row.getString("name"));
                        lName = ComUtil.LowerInitial(row.getString("name"));
                        rs = getDefRuleInfosByRow(row);
                        
                        //生成变量
                        /* */ 

                        sb.append("\r\n//" +(row.getString("remark")) );
                        sb.append("\r\npublic class " + ComUtil.UpperInitial(row.getString("name")) + " {");
                        for (j = 0; j < rs.size(); j++) {
                            String type = rs.get(j).getType().equals("?") ? "String" : rs.get(j).getType();
                            
                            if(ifET) {
                                if (type.equals("String") || type.equals("?")) {
                                    type = "String";
                                } else if (type.equals("Single")) {
                                    type = "float";
                                } else {
                                    type = "int";
                                } 
                            }else {
                                type = "int";
                            }
                            
                            sb.append("\r\nprivate " + type + " " + rs.get(j).getName() + ";//"+rs.get(j).getRemark());
                            
                            sb.append("\r\npublic " + type + " " + ComUtil.getGetMethodName(rs.get(j).getName()) + "(){ return " + rs.get(j).getName() + ";}");
                            
                            
                            int size=rs.get(j).getSize();
                            int max=65525;
                            if(size==2) {
                                max=255;
                            }else{
                                max=65525;
                            }
                            
                            sb.append("\r\npublic void " + ComUtil.getSetMethodName(rs.get(j).getName()) + "(" + type + " " + rs.get(j).getName() + "){ this." + rs.get(j).getName() + "=ComUtil.limitValue(" + rs.get(j).getName() + ",0,"+max+");}");
                        }
                        sb.append("\r\n }");
                        
                        /*
                         * private void setMasterData(BtlModule0 bm0) {
                         * this.masterData.biAirportAirstrikesNum=0; }
                         */
                        if (i == 0) {
                            
                            sb.append("\r\npublic void set" + uName + "(" + cutStrs2[i] + " " + cutStrs[i] + "){");
                            
                            sb.append("\r\nif (" + lName + "==null){" + lName + "=new " + uName + "();}");
                            
                            for (j = 0; j < rs.size(); j++) {
                                String type = rs.get(j).getType().equals("?") ? "String" : rs.get(j).getType();
                                // type = type.equals("Single") ? "float" : type;
                                if(ifET) {
                                    if (type.equals("String") || type.equals("?")) {
                                        type = "String";
                                    } else if (type.equals("Single")) {
                                        type = "float";
                                    } else {
                                        type = "int";
                                    } 
                                }else {
                                    type = "int";
                                }
                                
                                if(ifET) {
                                    sb.append("\r\n"+lName + "." + ComUtil.getSetMethodName(rs.get(j).getName()) + "(" + transValue(type, cutStrs[i] + "." + ComUtil.getGetMethodName(rs.get(j).getId()) + "()") + ");");
                                      
                                }else {
                                    sb.append("\r\n"+lName + "." + ComUtil.getSetMethodName(rs.get(j).getName()) + "(" +  cutStrs[i] + "." + ComUtil.getGetMethodName(rs.get(j).getId()) + "()" + ");");
                                     
                                }
                                
                                
                                // sb.append("\r\n");
                            }
                            sb.append("\r\n }");
                            
                        } else {
                            sb.append("\r\npublic void set" + uName + "(Array<" + cutStrs2[i] + "> " + cutStrs[i] + "s){");
                            
                            sb.append("\r\nif (" + lName + "s==null){" + lName + "s=new Array<" + uName + ">();}else{this." + lName + "s.clear();" + "}");
                            sb.append("\r\n if("+ cutStrs[i]+"s ==null){return ;}");
                            
                            
                            sb.append("\r\nfor(" + cutStrs2[i] + " " + cutStrs[i] + ":" + cutStrs[i] + "s) {");
                            sb.append("\r\n"+uName + " " + lName + "=new " + uName + "();");
                            for (j = 0; j < rs.size(); j++) {
                                String type = rs.get(j).getType().equals("?") ? "String" : rs.get(j).getType();
                                // type = type.equals("Single") ? "float" : type;
                                
                                if(ifET) {
                                    sb.append("\r\n"+lName + "." + ComUtil.getSetMethodName(rs.get(j).getName()) + "(" + transValue(type, cutStrs[i] + "." + ComUtil.getGetMethodName(rs.get(j).getId()) + "()") + ");");
                                        
                                }else {
                                    sb.append("\r\n"+lName + "." + ComUtil.getSetMethodName(rs.get(j).getName()) + "(" +  cutStrs[i] + "." + ComUtil.getGetMethodName(rs.get(j).getId()) + "()" + ");");
                                    
                                }
                                
                                // sb.append("\r\n");
                            }
                            sb.append("\r\nthis." + lName + "s.add(" + lName + ");");
                            sb.append("\r\n }");
                            
                           
                            
                            sb.append("\r\n }");
                        }
                        
                        //bm转变量 TODO
                        /* public get */
                        
                        //变量转bm TODO
                        
                    }
                    
                } catch (DocumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                
            }
            
            /*
             * public BTLDAO getBTL() { BTLDAO btl=new BTLDAO(); initBm1(btl);
             * 
             * return btl; }
             */
            
            sb.append("\r\n public BTLDAO getBTL() { BTLDAO btl=new BTLDAO();btl.init();");
            for (i = 0; i < cutStrs.length; i++) {
                try {
                    row = getInfoByRootName(rule, cutStrs[i]);
                } catch (DocumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                if (row != null) {
                sb.append("\r\ninit" + ComUtil.UpperInitial(cutStrs[i]) + "(btl);");
                }
            }
            sb.append("\r\n  return btl;}");
            
            /*private void initBm1(BTLDAO btl){
                
            }*/
            for (i = 0; i < cutStrs.length; i++) {
                try {
                    row = getInfoByRootName(rule, cutStrs[i]);
                    if (row != null) {
                        uName = ComUtil.UpperInitial(row.getString("name"));
                        lName = ComUtil.LowerInitial(row.getString("name"));
                        rs = getDefRuleInfosByRow(row);
                if(i==0) {
                    sb.append("\r\nprivate void init" + ComUtil.UpperInitial(cutStrs[i]) + "(BTLDAO btl){");
                    /*private void initBm0(BTLDAO btl){
                        btl.getBm0().setBm0_1("");
                     }*/
                    
                    for (j = 0; j < rs.size(); j++) {
                        sb.append("\r\n btl.get"+ComUtil.UpperInitial(cutStrs[i])+"().set"+ComUtil.UpperInitial(rs.get(j).getId())
                        +"("+lName+"."+rs.get(j).getName()+btlSetTrans+");");
                     }
                    sb.append("\r\n }");
                }else {
                    sb.append("\r\nprivate void init" + ComUtil.UpperInitial(cutStrs[i]) + "(BTLDAO btl){");
                    /*private void initBm1(BTLDAO btl){
                        for(LegionData legionData: legionDatas) {
                            BtlModule1 bm1=new BtlModule1();
                            bm1.setBm1_1(legionData.blUnknown129);
                            btl.getBm1().add(bm1);
                        }
                     }*/
                    sb.append("\r\n if("+lName+"s ==null){return ;}");
                    sb.append("\r\n for("+uName+" "+lName+":"+lName+"s){");
                    sb.append("\r\n"+cutStrs2[i]+" "+cutStrs[i]+"=new "+cutStrs2[i]+"();" );
                    for (j = 0; j < rs.size(); j++) {
                        sb.append("\r\n"+cutStrs[i]+".set"+ComUtil.UpperInitial(rs.get(j).getId())
                        +"("+lName+"."+rs.get(j).getName()+btlSetTrans+");");
                     }
                    sb.append("\r\nbtl.get"+ComUtil.UpperInitial(cutStrs[i])+"().add("+cutStrs[i]+");");
  
                    sb.append("\r\n }");
                    
                    sb.append("\r\n }");
                    
                  //  sb.append("\r\ninit" + ComUtil.UpperInitial(cutStrs[i]) + "(btl)");
                }
                    }
                } catch (DocumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            
            Map<String,String> bm0NameMap=new HashMap();
            Map<String,String> countSizeMap=new HashMap();//legionsCount:legionData
            //load
            sb.append("\r\n public "+ name+"(byte[] bt){");
            sb.append("\r\n init"+name+"();");
            sb.append("\r\n int line = 0;StringBuilder buf = new StringBuilder();");
            sb.append("\r\n for (byte d : bt) {if (line % 1 == 0) {buf.append(String.format(\"%02x\", d));line++; } }");
            //sb.append("\r\n String[] rId = new String[] { \"bm1\", \"bm2\", \"bm3\", \"bm4\", \"bm5\", \"bm6\", \"bm7\", \"bm8\", \"bm9\", \"bm10\", \"bm11\", \"bm12\", \"bm13\", \"bm14\", \"bm15\", \"bm16\", \"bm17\", \"bm18\", \"bm19\", \"bm20\" };");
            sb.append("\r\n  int sum=0;int h=0;int w=0;int tag=0;  int c=0;");
          
            for (i = 0; i < cutStrs.length; i++) {
                try {
                    row = getInfoByRootName(rule, cutStrs[i]);
                    
                    if (row != null) {
                        uName = ComUtil.UpperInitial(row.getString("name"));
                        lName = ComUtil.LowerInitial(row.getString("name"));
                        rs = getDefRuleInfosByRow(row);
                       
                        if (i == 0) {
                            
                            
                            for (j = 0; j < rs.size(); j++) {
                                bm0NameMap.put(rs.get(j).getId(), rs.get(j).getName());
                                // this.mapVersion= GameUtil.getCoverStr(buf,tag,re.get(0).getInt("size")  ); tag+=re.get(0).getInt("size");
                                sb.append("\r\n this.masterData."+rs.get(j).getName()+"= GameUtil.getCoverStr(buf,tag,"+rs.get(j).getSize()+"); tag+="+rs.get(j).getSize()+";");
                                if(rs.get(j).getFunction().equals("mapW")) {
                                    sb.append("\r\n w=masterData."+rs.get(j).getName()+";");
                                }
                                if(rs.get(j).getFunction().equals("mapH")) {
                                    sb.append("\r\n h=masterData."+rs.get(j).getName()+";");
                                }
                            }
                            sb.append("\r\n sum=w*h;");
                        } else {
                            //判断循环次数
                            if(row.get("Count").equals("one")) {
                                sb.append("\r\n c=1;");
                            }else if(row.get("Count").equals("sum")) {
                                sb.append("\r\n c=sum;");
                            }else {
                                sb.append("\r\n c=masterData."+bm0NameMap.get(row.get("Count"))+";");
                                countSizeMap.put(bm0NameMap.get(row.get("Count")), (String) row.get("name"));
                            }
                            sb.append("for(int i=0;i<c;i++){");
                            sb.append("\r\n"+uName+" "+lName+"=new "+uName+"();" );
                                for (j = 0; j < rs.size(); j++) {
                                    sb.append("\r\n"+lName+".set"+ ComUtil.UpperInitial(rs.get(j).getName())+"(GameUtil.getCoverStr(buf,tag,"+rs.get(j).getSize()+")); tag+="+rs.get(j).getSize()+";");
                                }
                                sb.append("\r\n this."+lName+"s.add("+lName+");");
                                sb.append("\r\n }");
                        }
                        //bm转变量 TODO
                        /* public get */
                        //变量转bm TODO
                    }
                } catch (DocumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                
            }
            
            sb.append("\r\n bt=null;buf=null; init();");
            
            
            
            sb.append("\r\n }");
            
            //save
            sb.append("\r\n public void  save(String path){");
            
            //更新size个数
            for (String key : countSizeMap.keySet()) {
                sb.append("\r\n this.masterData."+key+"="+countSizeMap.get(key)+"s.size;");
              }
            
            
            sb.append("\r\n  try {  FileByte out = new FileByte();");
            
            
            for (i = 0; i < cutStrs.length; i++) {
                try {
                    row = getInfoByRootName(rule, cutStrs[i]);
                    
                    if (row != null) {
                        uName = ComUtil.UpperInitial(row.getString("name"));
                        lName = ComUtil.LowerInitial(row.getString("name"));
                        rs = getDefRuleInfosByRow(row);
                       
                        if (i == 0) {
                            for (j = 0; j < rs.size(); j++) {
                                bm0NameMap.put(rs.get(j).getId(), rs.get(j).getName());
                                // this.mapVersion= GameUtil.getCoverStr(buf,tag,re.get(0).getInt("size")  ); tag+=re.get(0).getInt("size");
                                sb.append("\r\n out.write(masterData."+rs.get(j).getName()+","+rs.get(j).getSize()+"); ");
                                
                            }
                        } else {
                            //判断循环次数
                            
                            
                            sb.append("for(int i=0,iMax="+lName+"s.size;i<iMax;i++){");
                          
                                for (j = 0; j < rs.size(); j++) {
                                    
                                    sb.append("\r\n out.write("+lName+"s.get(i).get"+ComUtil.UpperInitial(rs.get(j).getName())+"(),"+rs.get(j).getSize()+");");
                                }
                               
                                sb.append("\r\n }");
                                
                        }
                       
                       // sb.append("\r\n }");   
                    }
                    
                } catch (DocumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                
            }
            
            sb.append("\r\n  FileHandle file = Gdx.files.local(path); file.writeBytes(out.getByte(), false);");
            sb.append("\r\n  } catch (Exception e) { System.err.println(e); } System.out.println(\"Ok\");");
           
            sb.append("\r\n }");
            
            
            
            sb.append("\r\n//-------------------------------自定义新增变量-----------------------------------");
            sb.append("\r\n//-------------------------------自定义新增方法-----------------------------------");
            
            
            sb.append("\r\n }");
            String st=sb.toString();
            System.out.print(st);
            ComUtil.setSysClipboardText(st);
            JOptionPane.showMessageDialog(null,"内容已复制,请右键粘贴","提示",  JOptionPane.INFORMATION_MESSAGE);
        }
    }
   
View Code

 

posted on 2019-12-30 00:07  黑狱  阅读(173)  评论(0编辑  收藏  举报