Last active
December 22, 2015 04:19
-
-
Save rc1/6416696 to your computer and use it in GitHub Desktop.
Example/draft API for Your Tour c++
This file contains hidden or 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
| // # ContentList | |
| // Can be created | |
| ContentList allcontent; | |
| // Can load it from the cms, and write it to disk | |
| allcontent.fetch(); | |
| // Load it from disk and parse it | |
| allcontent.load(); | |
| // Can be filtered by nearest | |
| ofVec2f userPosition( 0.5, 0.5 ); | |
| ContentList contentNearUser = allcontent.near( userPosition ); | |
| // Can be filtered for only content facing the user (takes into account spread and direction of the content) | |
| float userDirection( 0.5 ); | |
| ContentList contentFacingUser = allcontent.facing( userDirection ); | |
| // Can be filtered for only matching certain tags | |
| ContentList contentWithFish = allcontent.withTag( "fish" ); | |
| // Can be filtered for only not matching certain tags | |
| ContentList contentWithOutChips = allcontent.withoutTag( "chips" ); | |
| // Can be chained together | |
| ContentList selection = allcontent.withoutTag( "special" ).facing( userDirection ).near( userPosition ); | |
| // ^^^ the above should return all the items which don't have the tag special, are facing the user, and are near the users position | |
| // Can be sorted by distance | |
| ContentList nearestSelection = selection.sortedByNearest(); | |
| // # ContentItems | |
| // The ContentList will contain content items, which can be looped through | |
| for (int i = 0; i < nearestSelection.size(); ++i) { | |
| ContentItems item = nearestSelection.at(i); | |
| ofLogVerbose() << "Content item: " << item.title << " has the id of " << item.id; | |
| } | |
| // # Example usages | |
| // An exmaple of what you may do when you want to send new content | |
| void getNewContent() { | |
| // Filter and sort | |
| ContentList selection = allcontent.withoutTag( "special" ).facing( userDirection ).near( userPosition ).sortedByNearest(); | |
| // Check there is one! | |
| if ( selection.size() > 0 ) { | |
| // send it to the web app, if we have a function `sendToWebapp` that takes an id. | |
| sendToWebapp( selection.at(0).id ); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment