Skip to content

Commit

Permalink
Merge pull request #75 from SylarLong/feat-74
Browse files Browse the repository at this point in the history
Feat 74
  • Loading branch information
SylarLong authored Oct 22, 2023
2 parents af266ab + 1f655ea commit 8edaa4f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@

## v1.3.4

- 🪄 功能(feature)

🇨🇳

- 判断运限四化 #74

🇺🇸

- check horoscope mutagen state #74

- ✨ 改进(enhancement)

🇨🇳
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iztro",
"version": "1.3.3",
"version": "1.3.4",
"description": "轻量级紫微斗数星盘生成库。可以通过出生年月日获取到紫微斗数星盘信息、生肖、星座等信息。A lightweight kit to astrolabe generator of The Purple Star Astrology (Zi Wei Dou Shu). The Purple Star Astrology(Zi Wei Dou Shu) is a Chinese ancient astrology. You're able to get your horoscope and personality from the astrolabe",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
16 changes: 16 additions & 0 deletions src/__tests__/astro/astro.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,22 @@ describe('Astrolabe', () => {
expect(horoscope.notHaveHoroscopeStars('疾厄', 'decadal', ['流喜', '流鸾', '流魁'])).toBe(true);
expect(horoscope.hasOneOfHoroscopeStars('疾厄', 'decadal', ['流陀', '流曲', '运昌'])).toBe(true);
expect(horoscope.hasOneOfHoroscopeStars('疾厄', 'decadal', ['流喜', '流鸾', '流魁'])).toBe(false);
expect(horoscope.hasHoroscopeMutagen('兄弟', 'decadal', '禄')).toBe(true);
expect(horoscope.hasHoroscopeMutagen('夫妻', 'decadal', '权')).toBe(true);
expect(horoscope.hasHoroscopeMutagen('疾厄', 'decadal', '科')).toBe(true);
expect(horoscope.hasHoroscopeMutagen('子女', 'decadal', '忌')).toBe(true);
expect(horoscope.hasHoroscopeMutagen('仆役', 'yearly', '禄')).toBe(true);
expect(horoscope.hasHoroscopeMutagen('夫妻', 'yearly', '权')).toBe(true);
expect(horoscope.hasHoroscopeMutagen('财帛', 'yearly', '科')).toBe(true);
expect(horoscope.hasHoroscopeMutagen('子女', 'yearly', '忌')).toBe(true);
expect(horoscope.hasHoroscopeMutagen('夫妻', 'monthly', '禄')).toBe(true);
expect(horoscope.hasHoroscopeMutagen('子女', 'monthly', '权')).toBe(true);
expect(horoscope.hasHoroscopeMutagen('迁移', 'monthly', '科')).toBe(true);
expect(horoscope.hasHoroscopeMutagen('财帛', 'monthly', '忌')).toBe(true);
expect(horoscope.hasHoroscopeMutagen('迁移', 'daily', '禄')).toBe(true);
expect(horoscope.hasHoroscopeMutagen('官禄', 'daily', '权')).toBe(true);
expect(horoscope.hasHoroscopeMutagen('疾厄', 'daily', '科')).toBe(true);
expect(horoscope.hasHoroscopeMutagen('夫妻', 'daily', '忌')).toBe(true);

const agePalace = horoscope.agePalace();

Expand Down
29 changes: 28 additions & 1 deletion src/astro/FunctionalHoroscope.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Horoscope, Scope } from '../data/types';
import { PalaceName, StarKey, StarName, kot } from '../i18n';
import { Mutagen, MutagenKey, PalaceName, StarKey, StarName, kot } from '../i18n';
import { IFunctionalAstrolabe } from './FunctionalAstrolabe';
import { FunctionalSurpalaces } from './FunctionalSurpalaces';
import FunctionalPalace from './FunctionalPalace';
import { mergeStars } from '../utils';
import { MUTAGEN } from '../data';

const _getHoroscopePalaceIndex = ($: FunctionalHoroscope, scope: Scope, palaceName: PalaceName) => {
let palaceIndex = -1;
Expand Down Expand Up @@ -92,6 +93,18 @@ export interface IFunctionalHoroscope extends Horoscope {
* @returns {boolean} 是否含有(部分)指定流耀中
*/
hasOneOfHoroscopeStars: (palaceName: PalaceName, scope: Scope, horoscopeStar: StarName[]) => boolean;

/**
* 判断指定运限宫位内是否存在运限四化
*
* @version v1.3.4
*
* @param palaceName 宫位名称
* @param scope 指定获取哪个运限的宫位
* @param horoscopeMutagen 运限四化
* @returns {boolean} 是否含有运限四化
*/
hasHoroscopeMutagen: (palaceName: PalaceName, scope: Scope, horoscopeMutagen: Mutagen) => boolean;
}

export default class FunctionalHoroscope implements IFunctionalHoroscope {
Expand Down Expand Up @@ -181,4 +194,18 @@ export default class FunctionalHoroscope implements IFunctionalHoroscope {

return horoscopeStarKeys.some((star) => starKeys.includes(star));
};

hasHoroscopeMutagen = (palaceName: PalaceName, scope: Scope, horoscopeMutagen: Mutagen) => {
if (scope === 'origin') {
return false;
}

const palaceIndex = _getHoroscopePalaceIndex(this, scope, palaceName);
const majorStars = this.astrolabe.palace(palaceIndex)?.majorStars ?? [];
const minorStars = this.astrolabe.palace(palaceIndex)?.minorStars ?? [];
const stars = mergeStars([majorStars], [minorStars])[0].map((star) => kot<StarKey>(star.name));
const mutagenIndex = MUTAGEN.indexOf(kot<MutagenKey>(horoscopeMutagen));

return stars.includes(kot<StarKey>(this[scope].mutagen[mutagenIndex]));
};
}

0 comments on commit 8edaa4f

Please sign in to comment.