generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3be4589
commit 9d52dd9
Showing
24 changed files
with
1,395 additions
and
640 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
--- | ||
playerCount: 6 | ||
playerLevel: 6 | ||
playerLevel: 4 | ||
enemy: | ||
- name: Somthing | ||
level: 2 | ||
|
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
This file was deleted.
Oops, something went wrong.
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,103 @@ | ||
import { type IMetadataSource, MapMetadataSource, type Metadata } from './MetadataSource'; | ||
import { type GlobalMetadataCacheItem, type MapMetadataCacheItem } from './MetadataCacheItem'; | ||
import { type MetadataManager } from './MetadataManager'; | ||
import { type BindTargetDeclaration } from '../parsers/bindTargetParser/BindTargetDeclaration'; | ||
import { type PropPath } from '../utils/prop/PropPath'; | ||
import { type IMetadataSubscription } from './IMetadataSubscription'; | ||
import { PropUtils } from '../utils/prop/PropUtils'; | ||
import { ErrorLevel, MetaBindInternalError } from '../utils/errors/MetaBindErrors'; | ||
|
||
export class InternalMetadataSource extends MapMetadataSource<MapMetadataCacheItem> { | ||
public getDefaultCacheItem(storagePath: string): MapMetadataCacheItem { | ||
return { | ||
data: {}, | ||
storagePath: storagePath, | ||
...this.manager.getDefaultCacheItem(), | ||
}; | ||
} | ||
|
||
public async syncExternal(_cacheItem: MapMetadataCacheItem): Promise<void> { | ||
// Do nothing | ||
} | ||
} | ||
|
||
export class GlobalMetadataSource implements IMetadataSource<GlobalMetadataCacheItem> { | ||
public readonly id: string; | ||
public readonly manager: MetadataManager; | ||
public readonly cache: GlobalMetadataCacheItem; | ||
|
||
constructor(id: string, manager: MetadataManager) { | ||
this.id = id; | ||
this.manager = manager; | ||
|
||
this.cache = { | ||
data: {}, | ||
...this.manager.getDefaultCacheItem(), | ||
}; | ||
} | ||
|
||
public delete(_cacheItem: GlobalMetadataCacheItem): void { | ||
// noop | ||
} | ||
|
||
public getCacheItemForStoragePath(_storagePath: string): GlobalMetadataCacheItem | undefined { | ||
return this.cache; | ||
} | ||
|
||
public iterateCacheItems(): IterableIterator<GlobalMetadataCacheItem> { | ||
return [this.cache][Symbol.iterator](); | ||
} | ||
|
||
public onCycle(_cacheItem: GlobalMetadataCacheItem): void { | ||
// noop | ||
} | ||
|
||
public readCache(_bindTarget: BindTargetDeclaration): unknown { | ||
return this.readCacheItem(this.cache, _bindTarget.storageProp); | ||
} | ||
|
||
public readCacheItem(cacheItem: GlobalMetadataCacheItem, propPath: PropPath): unknown { | ||
return PropUtils.tryGet(cacheItem.data, propPath); | ||
} | ||
|
||
public shouldDelete(_cacheItem: GlobalMetadataCacheItem): boolean { | ||
return false; | ||
} | ||
|
||
public subscribe(subscription: IMetadataSubscription): GlobalMetadataCacheItem { | ||
this.cache.subscriptions.push(subscription); | ||
return this.cache; | ||
} | ||
|
||
public syncExternal(_cacheItem: GlobalMetadataCacheItem): void { | ||
// noop | ||
} | ||
|
||
public unsubscribe(subscription: IMetadataSubscription): GlobalMetadataCacheItem { | ||
this.cache.subscriptions = this.cache.subscriptions.filter(x => x.uuid !== subscription.uuid); | ||
|
||
return this.cache; | ||
} | ||
|
||
public update(value: unknown, subscription: IMetadataSubscription): GlobalMetadataCacheItem { | ||
if (subscription.bindTarget === undefined) { | ||
throw new MetaBindInternalError({ | ||
errorLevel: ErrorLevel.CRITICAL, | ||
effect: 'can not update metadata', | ||
cause: 'subscription bind target undefined', | ||
}); | ||
} | ||
|
||
PropUtils.setAndCreate(this.cache.data, subscription.bindTarget.storageProp, value); | ||
|
||
return this.cache; | ||
} | ||
|
||
public updateEntireCache(value: Metadata, cacheItem: GlobalMetadataCacheItem): void { | ||
cacheItem.data = value; | ||
} | ||
|
||
public readEntireCacheItem(cacheItem: GlobalMetadataCacheItem): Metadata { | ||
return cacheItem.data; | ||
} | ||
} |
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,33 @@ | ||
import { type IMetadataSubscription } from './IMetadataSubscription'; | ||
|
||
import { type Metadata } from './MetadataSource'; | ||
|
||
export interface IMetadataCacheItem { | ||
subscriptions: IMetadataSubscription[]; | ||
|
||
/** | ||
* The cycles since the last change to the cache by the plugin. | ||
*/ | ||
cyclesSinceInternalChange: number; | ||
/** | ||
* Whether the cache was changed by the plugin. If this is true, the frontmatter should be updated. | ||
*/ | ||
pendingInternalChange: boolean; | ||
/** | ||
* The cycles that the cache has been inactive, meaning no listener registered to it. | ||
*/ | ||
cyclesSinceInactive: number; | ||
/** | ||
* Whether the there are no subscribers to the cache. | ||
*/ | ||
inactive: boolean; | ||
} | ||
|
||
export interface MapMetadataCacheItem extends IMetadataCacheItem { | ||
storagePath: string; | ||
data: Metadata; | ||
} | ||
|
||
export interface GlobalMetadataCacheItem extends IMetadataCacheItem { | ||
data: Metadata; | ||
} |
Oops, something went wrong.