-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create FunctionalHoroscope class #31
- Loading branch information
Showing
6 changed files
with
231 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { Horoscope, Scope } from '../data/types'; | ||
import { PalaceName, StarKey, StarName, kot } from '../i18n'; | ||
import { IFunctionalAstrolabe } from './FunctionalAstrolabe'; | ||
import { FunctionalSurpalaces } from './FunctionalSurpalaces'; | ||
import FunctionalPalace from './FunctionalPalace'; | ||
import { mergeStars } from '../utils'; | ||
|
||
export interface IFunctionalHoroscope extends Horoscope { | ||
/** | ||
* 获取小限宫位 | ||
* | ||
* @version v1.3.0 | ||
* | ||
* @returns {FunctionalPalace | undefined} 小限宫位 | ||
*/ | ||
agePalace: () => FunctionalPalace | undefined; | ||
|
||
/** | ||
* 获取运限宫位 | ||
* | ||
* @version v1.3.0 | ||
* | ||
* @param palaceName 宫位名称 | ||
* @param scope 指定获取哪个运限的宫位 | ||
* @returns {FunctionalPalace | undefined} 指定宫位 | ||
*/ | ||
palace: (palaceName: PalaceName, scope: Scope) => FunctionalPalace | undefined; | ||
|
||
/** | ||
* 获取运限指定宫位的三方四正宫位 | ||
* | ||
* @version v1.3.0 | ||
* | ||
* @param palaceName 宫位名称 | ||
* @param scope 指定获取哪个运限的宫位 | ||
* @returns {FunctionalSurpalaces | undefined} 指定宫位的三方四正 | ||
*/ | ||
surroundPalaces: (palaceName: PalaceName, scope: Scope) => FunctionalSurpalaces | undefined; | ||
|
||
/** | ||
* 判断在指定运限的宫位内是否包含流耀,需要全部包含才返回true | ||
* | ||
* @version v1.3.0 | ||
* | ||
* @param palaceName 宫位名称 | ||
* @param scope 指定获取哪个运限的宫位 | ||
* @param horoscopeStar | ||
* @returns {boolean} 是否包含指定流耀 | ||
*/ | ||
hasHoroscopeStars: (palaceName: PalaceName, scope: Scope, horoscopeStar: StarName[]) => boolean; | ||
} | ||
|
||
export default class FunctionalHoroscope implements IFunctionalHoroscope { | ||
lunarDate; | ||
solarDate; | ||
decadal; | ||
age; | ||
yearly; | ||
monthly; | ||
daily; | ||
hourly; | ||
astrolabe; | ||
|
||
constructor(data: Horoscope, astrolabe: IFunctionalAstrolabe) { | ||
this.lunarDate = data.lunarDate; | ||
this.solarDate = data.solarDate; | ||
this.decadal = data.decadal; | ||
this.age = data.age; | ||
this.yearly = data.yearly; | ||
this.monthly = data.monthly; | ||
this.daily = data.daily; | ||
this.hourly = data.hourly; | ||
this.astrolabe = astrolabe; | ||
|
||
return this; | ||
} | ||
|
||
agePalace = () => { | ||
return this.astrolabe.palace(this.age.index); | ||
}; | ||
|
||
palace = (palaceName: PalaceName, scope: Scope) => { | ||
if (scope === 'origin') { | ||
return this.astrolabe.palace(palaceName); | ||
} | ||
|
||
const targetPalaceindex = this[scope].palaceNames.indexOf(palaceName); | ||
|
||
return this.astrolabe.palace(targetPalaceindex); | ||
}; | ||
|
||
surroundPalaces = (palaceName: PalaceName, scope: Scope) => { | ||
if (scope === 'origin') { | ||
return this.astrolabe.surroundedPalaces(palaceName); | ||
} | ||
|
||
const targetPalaceindex = this[scope].palaceNames.indexOf(palaceName); | ||
|
||
return this.astrolabe.surroundedPalaces(targetPalaceindex); | ||
}; | ||
|
||
hasHoroscopeStars = (palaceName: PalaceName, scope: Scope, horoscopeStar: StarName[]) => { | ||
let palaceIndex = -1; | ||
|
||
if (!this.decadal.stars || !this.yearly.stars) { | ||
return false; | ||
} | ||
|
||
if (scope === 'origin') { | ||
this.astrolabe.palaces.some((p, idx) => { | ||
if (p.name === palaceName) { | ||
palaceIndex = idx; | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
}); | ||
} else { | ||
palaceIndex = this[scope].palaceNames.indexOf(palaceName); | ||
} | ||
|
||
const stars = mergeStars(this.decadal.stars, this.yearly.stars)[palaceIndex]; | ||
const starKeys = stars.map((item) => kot<StarKey>(item.name)); | ||
const horoscopeStarKeys = horoscopeStar.map((item) => kot<StarKey>(item)); | ||
|
||
return horoscopeStarKeys.every((star) => starKeys.includes(star)); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters